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