|
1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 // Class TBtreeToken |
|
17 inline TBtreeToken::TBtreeToken(TEmpty) |
|
18 /** Constructor that intialises the TBtreeToken for an empty B-tree. |
|
19 |
|
20 @param Intialises for an empty B-tree */ |
|
21 {Clear();} |
|
22 inline void TBtreeToken::Touch() |
|
23 /** Marks the B-tree as broken. */ |
|
24 {iHeight=0;} |
|
25 inline TBool TBtreeToken::IsBroken() const |
|
26 /** Tests if the broken flag has been set on the B-tree. |
|
27 |
|
28 @return True if the B-tree is broken, otherwise false. */ |
|
29 {return iFirst!=KNullPageRef&&iHeight==0;} |
|
30 inline TBool TBtreeToken::IsIntact() const |
|
31 /** Tests if the broken flag has not been set on the B-tree . |
|
32 |
|
33 @return True if the B-tree is not broken, otherwise false. */ |
|
34 {return iFirst==KNullPageRef||iHeight!=0;} |
|
35 inline TBool TBtreeToken::IsEmpty() const |
|
36 /** Tests if the B-tree is empty. |
|
37 |
|
38 @return True if the B-tree is empty, otherwise false. */ |
|
39 {return iFirst==KNullPageRef;} |
|
40 |
|
41 // Class TBtreePath |
|
42 inline TBtreePath::TBtreePath() |
|
43 : iEnd(-1) |
|
44 {} |
|
45 inline TPageRef TBtreePath::Node() const |
|
46 {return iNodes[iEnd];} |
|
47 inline TInt TBtreePath::Entry() const |
|
48 {return iEntries[iEnd];} |
|
49 inline TBool TBtreePath::IsLeaf() const |
|
50 {return iEnd==0;} |
|
51 inline TBtreeHeight TBtreePath::End() const |
|
52 {return iEnd;} |
|
53 inline void TBtreePath::SetEntry(TInt aEntry) |
|
54 {iEntries[iEnd]=TUint8(aEntry);} |
|
55 inline void TBtreePath::Pop() |
|
56 {++iEnd;} |
|
57 |
|
58 // Class TBtree |
|
59 inline TBool TBtree::IsDirty() const |
|
60 /** Tests if the dirty flag has been set on the B-tree. |
|
61 |
|
62 Any updates to the B-tree will set this flag on the TBtree object. Applications |
|
63 can use this to determine if they need to flush the page pool and re-save |
|
64 the B-tree token, after which they can call MarkCurrent() to indicate that |
|
65 the persistent storage is now up-to-date with the TBtree object. |
|
66 |
|
67 @return True if the dirty flag has been set, otherwise false */ |
|
68 {return iStatus<0;} |
|
69 inline void TBtree::MarkCurrent() |
|
70 /** Clears the dirty flag. */ |
|
71 {iStatus&=~EDirty;} |
|
72 inline void TBtree::MarkDirty() |
|
73 /** Sets the dirty flag. */ |
|
74 {iStatus|=EDirty;} |
|
75 inline TBool TBtree::IsBroken() const |
|
76 /** Tests if the broken flag has been set on the B-tree. |
|
77 |
|
78 Any updates to the B-tree that fail will leave this flag set on the TBtree |
|
79 object. This indicates that the persistent tree data is broken (corrupt) and |
|
80 the tree needs to be repaired. In this state, none of the functions which |
|
81 use a TBtreePos will work, only those taking a TBtreeMark. |
|
82 |
|
83 @return True if the B-tree is broken, otherwise false. */ |
|
84 {return (iStatus&EBroken)!=0;} |
|
85 inline TBool TBtree::IsIntact() const |
|
86 /** Tests if the broken flag has not been set on the B-tree . |
|
87 |
|
88 @return True if the B-tree is not broken, otherwise false. */ |
|
89 {return (iStatus&EBroken)==0;} |
|
90 inline void TBtree::MarkBroken() |
|
91 /** Sets the broken flag. */ |
|
92 {if (iFirst!=KNullPageRef) iStatus|=EBroken;} |
|
93 inline TBool TBtree::IsEmpty() const |
|
94 /** Tests if the B-tree is empty. |
|
95 |
|
96 @return True if the B-tree is empty, otherwise false */ |
|
97 {return iFirst==KNullPageRef;} |
|
98 |
|
99 // Template class TBtreeFix |
|
100 template <class Entry,class Key> |
|
101 inline TBtreeFix<Entry,Key>::TBtreeFix(TBtreeMode aMode) |
|
102 : TBtreeFixBase(aMode,sizeof(Entry),sizeof(Key)) |
|
103 /** Constructor that sets the B-tree mode. |
|
104 |
|
105 @param aMode B-tree operating mode */ |
|
106 {} |
|
107 template <class Entry,class Key> |
|
108 inline TBtreeFix<Entry,Key>::TBtreeFix(const TBtreeToken& aToken,TBtreeMode aMode) |
|
109 : TBtreeFixBase(aToken,aMode,sizeof(Entry),sizeof(Key)) |
|
110 /** Constructor that sets the B-tree mode and initialisation parameters. |
|
111 |
|
112 @param aToken Parameters with which to initialise the B-tree |
|
113 @param aMode B-tree operating mode */ |
|
114 {} |
|
115 template <class Entry,class Key> |
|
116 inline TBool TBtreeFix<Entry,Key>::FindL(TBtreePos& aPos,const Key& aKey,TBtree::TFind aMode) const |
|
117 {return TBtreeFixBase::FindL(aPos,&aKey,aMode);} |
|
118 template <class Entry,class Key> |
|
119 inline TBool TBtreeFix<Entry,Key>::InsertL(TBtreePos& aPos,const Entry& anEntry,TAllowDuplicates aDup) |
|
120 /** Inserts an entry into the tree. |
|
121 |
|
122 @param aPos On return, the position of the entry inserted |
|
123 @param anEntry Entry to insert |
|
124 @param aDup Flag to indicate whether duplicate entries are allowed in the tree |
|
125 @return True if successful, false if the entry was a duplicate and aDup was |
|
126 set to ENoDuplicates */ |
|
127 {return TBtreeFixBase::InsertL(aPos,&anEntry,aDup);} |
|
128 template <class Entry,class Key> |
|
129 inline TBool TBtreeFix<Entry,Key>::DeleteL(const Key& aKey) |
|
130 /** Delete an entry. |
|
131 |
|
132 @param aKey Key of the entry to delete |
|
133 @return True if successful, false if the entry was not found */ |
|
134 {return TBtreeFixBase::DeleteL(&aKey);} |
|
135 template <class Entry,class Key> |
|
136 inline Entry TBtreeFix<Entry,Key>::AtL(const TBtreePos& aPos) const |
|
137 /** Gets the entry at the specified position. |
|
138 |
|
139 @param aPos Position of the entry to get |
|
140 @return Entry at position aPos */ |
|
141 {Entry e;TBtreeFixBase::ExtractAtL(aPos,&e);return e;} |
|
142 template <class Entry,class Key> |
|
143 inline Entry TBtreeFix<Entry,Key>::AtL(const TBtreeMark& aMark) const |
|
144 /** Gets the entry at the specified iterator position. |
|
145 |
|
146 @param aMark Iterator to use to get the entry |
|
147 @return Entry at current iterator position */ |
|
148 {Entry e;TBtreeFixBase::ExtractAtL(aMark,&e);return e;} |
|
149 template <class Entry,class Key> |
|
150 inline void TBtreeFix<Entry,Key>::ExtractAtL(const TBtreePos& aPos,Entry& anEntry) const |
|
151 /** Gets the entry at the specified position. |
|
152 |
|
153 @param aPos Position of the entry to get |
|
154 @param anEntry On return, the specified entry */ |
|
155 {TBtreeFixBase::ExtractAtL(aPos,&anEntry);} |
|
156 template <class Entry,class Key> |
|
157 inline void TBtreeFix<Entry,Key>::ExtractAtL(const TBtreeMark& aMark,Entry& anEntry) const |
|
158 /** Gets the entry at the specified iterator position. |
|
159 |
|
160 @param aMark Iterator to use to get the entry |
|
161 @param anEntry On return, the specified entry */ |
|
162 {TBtreeFixBase::ExtractAtL(aMark,&anEntry);} |
|
163 inline TBtreeFix<TAny,TAny>::TBtreeFix(TBtreeMode aMode,TInt anEntrySize,TInt aKeySize) |
|
164 : TBtreeFixBase(aMode,anEntrySize,aKeySize) |
|
165 /** Constructor that sets the B-tree mode. |
|
166 |
|
167 @param aMode B-tree operating mode |
|
168 @param anEntrySize Entry size |
|
169 @param aKeySize Key size for entries */ |
|
170 {} |
|
171 inline TBtreeFix<TAny,TAny>::TBtreeFix(const TBtreeToken& aToken,TBtreeMode aMode,TInt anEntrySize,TInt aKeySize) |
|
172 : TBtreeFixBase(aToken,aMode,anEntrySize,aKeySize) |
|
173 /** Constructor that sets the B-tree mode and initialisation parameters. |
|
174 |
|
175 @param aToken Parameters with which to initialise the B-tree |
|
176 @param aMode B-tree operating mode |
|
177 @param anEntrySize Entry size |
|
178 @param aKeySize Key size for entries */ |
|
179 {} |
|
180 |