sl@0: // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: // Class TBtreeToken sl@0: inline TBtreeToken::TBtreeToken(TEmpty) sl@0: /** Constructor that intialises the TBtreeToken for an empty B-tree. sl@0: sl@0: @param Intialises for an empty B-tree */ sl@0: {Clear();} sl@0: inline void TBtreeToken::Touch() sl@0: /** Marks the B-tree as broken. */ sl@0: {iHeight=0;} sl@0: inline TBool TBtreeToken::IsBroken() const sl@0: /** Tests if the broken flag has been set on the B-tree. sl@0: sl@0: @return True if the B-tree is broken, otherwise false. */ sl@0: {return iFirst!=KNullPageRef&&iHeight==0;} sl@0: inline TBool TBtreeToken::IsIntact() const sl@0: /** Tests if the broken flag has not been set on the B-tree . sl@0: sl@0: @return True if the B-tree is not broken, otherwise false. */ sl@0: {return iFirst==KNullPageRef||iHeight!=0;} sl@0: inline TBool TBtreeToken::IsEmpty() const sl@0: /** Tests if the B-tree is empty. sl@0: sl@0: @return True if the B-tree is empty, otherwise false. */ sl@0: {return iFirst==KNullPageRef;} sl@0: sl@0: // Class TBtreePath sl@0: inline TBtreePath::TBtreePath() sl@0: : iEnd(-1) sl@0: {} sl@0: inline TPageRef TBtreePath::Node() const sl@0: {return iNodes[iEnd];} sl@0: inline TInt TBtreePath::Entry() const sl@0: {return iEntries[iEnd];} sl@0: inline TBool TBtreePath::IsLeaf() const sl@0: {return iEnd==0;} sl@0: inline TBtreeHeight TBtreePath::End() const sl@0: {return iEnd;} sl@0: inline void TBtreePath::SetEntry(TInt aEntry) sl@0: {iEntries[iEnd]=TUint8(aEntry);} sl@0: inline void TBtreePath::Pop() sl@0: {++iEnd;} sl@0: sl@0: // Class TBtree sl@0: inline TBool TBtree::IsDirty() const sl@0: /** Tests if the dirty flag has been set on the B-tree. sl@0: sl@0: Any updates to the B-tree will set this flag on the TBtree object. Applications sl@0: can use this to determine if they need to flush the page pool and re-save sl@0: the B-tree token, after which they can call MarkCurrent() to indicate that sl@0: the persistent storage is now up-to-date with the TBtree object. sl@0: sl@0: @return True if the dirty flag has been set, otherwise false */ sl@0: {return iStatus<0;} sl@0: inline void TBtree::MarkCurrent() sl@0: /** Clears the dirty flag. */ sl@0: {iStatus&=~EDirty;} sl@0: inline void TBtree::MarkDirty() sl@0: /** Sets the dirty flag. */ sl@0: {iStatus|=EDirty;} sl@0: inline TBool TBtree::IsBroken() const sl@0: /** Tests if the broken flag has been set on the B-tree. sl@0: sl@0: Any updates to the B-tree that fail will leave this flag set on the TBtree sl@0: object. This indicates that the persistent tree data is broken (corrupt) and sl@0: the tree needs to be repaired. In this state, none of the functions which sl@0: use a TBtreePos will work, only those taking a TBtreeMark. sl@0: sl@0: @return True if the B-tree is broken, otherwise false. */ sl@0: {return (iStatus&EBroken)!=0;} sl@0: inline TBool TBtree::IsIntact() const sl@0: /** Tests if the broken flag has not been set on the B-tree . sl@0: sl@0: @return True if the B-tree is not broken, otherwise false. */ sl@0: {return (iStatus&EBroken)==0;} sl@0: inline void TBtree::MarkBroken() sl@0: /** Sets the broken flag. */ sl@0: {if (iFirst!=KNullPageRef) iStatus|=EBroken;} sl@0: inline TBool TBtree::IsEmpty() const sl@0: /** Tests if the B-tree is empty. sl@0: sl@0: @return True if the B-tree is empty, otherwise false */ sl@0: {return iFirst==KNullPageRef;} sl@0: sl@0: // Template class TBtreeFix sl@0: template sl@0: inline TBtreeFix::TBtreeFix(TBtreeMode aMode) sl@0: : TBtreeFixBase(aMode,sizeof(Entry),sizeof(Key)) sl@0: /** Constructor that sets the B-tree mode. sl@0: sl@0: @param aMode B-tree operating mode */ sl@0: {} sl@0: template sl@0: inline TBtreeFix::TBtreeFix(const TBtreeToken& aToken,TBtreeMode aMode) sl@0: : TBtreeFixBase(aToken,aMode,sizeof(Entry),sizeof(Key)) sl@0: /** Constructor that sets the B-tree mode and initialisation parameters. sl@0: sl@0: @param aToken Parameters with which to initialise the B-tree sl@0: @param aMode B-tree operating mode */ sl@0: {} sl@0: template sl@0: inline TBool TBtreeFix::FindL(TBtreePos& aPos,const Key& aKey,TBtree::TFind aMode) const sl@0: {return TBtreeFixBase::FindL(aPos,&aKey,aMode);} sl@0: template sl@0: inline TBool TBtreeFix::InsertL(TBtreePos& aPos,const Entry& anEntry,TAllowDuplicates aDup) sl@0: /** Inserts an entry into the tree. sl@0: sl@0: @param aPos On return, the position of the entry inserted sl@0: @param anEntry Entry to insert sl@0: @param aDup Flag to indicate whether duplicate entries are allowed in the tree sl@0: @return True if successful, false if the entry was a duplicate and aDup was sl@0: set to ENoDuplicates */ sl@0: {return TBtreeFixBase::InsertL(aPos,&anEntry,aDup);} sl@0: template sl@0: inline TBool TBtreeFix::DeleteL(const Key& aKey) sl@0: /** Delete an entry. sl@0: sl@0: @param aKey Key of the entry to delete sl@0: @return True if successful, false if the entry was not found */ sl@0: {return TBtreeFixBase::DeleteL(&aKey);} sl@0: template sl@0: inline Entry TBtreeFix::AtL(const TBtreePos& aPos) const sl@0: /** Gets the entry at the specified position. sl@0: sl@0: @param aPos Position of the entry to get sl@0: @return Entry at position aPos */ sl@0: {Entry e;TBtreeFixBase::ExtractAtL(aPos,&e);return e;} sl@0: template sl@0: inline Entry TBtreeFix::AtL(const TBtreeMark& aMark) const sl@0: /** Gets the entry at the specified iterator position. sl@0: sl@0: @param aMark Iterator to use to get the entry sl@0: @return Entry at current iterator position */ sl@0: {Entry e;TBtreeFixBase::ExtractAtL(aMark,&e);return e;} sl@0: template sl@0: inline void TBtreeFix::ExtractAtL(const TBtreePos& aPos,Entry& anEntry) const sl@0: /** Gets the entry at the specified position. sl@0: sl@0: @param aPos Position of the entry to get sl@0: @param anEntry On return, the specified entry */ sl@0: {TBtreeFixBase::ExtractAtL(aPos,&anEntry);} sl@0: template sl@0: inline void TBtreeFix::ExtractAtL(const TBtreeMark& aMark,Entry& anEntry) const sl@0: /** Gets the entry at the specified iterator position. sl@0: sl@0: @param aMark Iterator to use to get the entry sl@0: @param anEntry On return, the specified entry */ sl@0: {TBtreeFixBase::ExtractAtL(aMark,&anEntry);} sl@0: inline TBtreeFix::TBtreeFix(TBtreeMode aMode,TInt anEntrySize,TInt aKeySize) sl@0: : TBtreeFixBase(aMode,anEntrySize,aKeySize) sl@0: /** Constructor that sets the B-tree mode. sl@0: sl@0: @param aMode B-tree operating mode sl@0: @param anEntrySize Entry size sl@0: @param aKeySize Key size for entries */ sl@0: {} sl@0: inline TBtreeFix::TBtreeFix(const TBtreeToken& aToken,TBtreeMode aMode,TInt anEntrySize,TInt aKeySize) sl@0: : TBtreeFixBase(aToken,aMode,anEntrySize,aKeySize) sl@0: /** Constructor that sets the B-tree mode and initialisation parameters. sl@0: sl@0: @param aToken Parameters with which to initialise the B-tree sl@0: @param aMode B-tree operating mode sl@0: @param anEntrySize Entry size sl@0: @param aKeySize Key size for entries */ sl@0: {} sl@0: