diff -r 000000000000 -r 08ec8eefde2f persistentstorage/dbms/Inc2/D32Map.inl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/persistentstorage/dbms/Inc2/D32Map.inl Fri Jan 22 11:06:30 2010 +0200 @@ -0,0 +1,196 @@ +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// RMap template class implementation. +// +// + +/** + + Template function that compares two objects of type TPair and + returns {negative, 0, positive} depending on the comparison result. + In order the comparison to work, the KEY template parameter has to have + "-" operation defined - either native or overloaded "-" operator. + Used by RMap template class. + Note: This template function works only on objects, which have defined a "-" operation. + @param aLeft The first TPair to be compared + @param aRight The second TPair to be compared + @return An integer value, which is: + 0, if the objects are equal; + negative number, the first object is bigger than the second object + positive number, the first object is smaller than the second object + @internalComponent +*/ +template +TInt Compare(const TPair& aLeft, const TPair& aRight) + { + return aRight.iKey - aLeft.iKey; + } + +/** +@param aKey Key part of TPair object +@param aData Data part of TPair object +*/ +template +TPair::TPair(const KEY& aKey, const DATA& aData) : + iKey(aKey), + iData(aData) + { + } + +/** +@param aKey Key part of TPair object +*/ +template +TPair::TPair(const KEY& aKey) : + iKey(aKey) + { + } + +/** +*/ +template +TPair::TPair() + { + } + +/** +@param aOrder An object of TLinearOrder< TPair type, which will be used when +new elements are inserted into the collection. +*/ +template +RMap::RMap(const TLinearOrder< TPair >& aOrder) : + iOrder(aOrder) + { + } + +/** +Closes RMap instance and destroy all RMap data. +*/ +template +void RMap::Close() + { + iCol.Close(); + } + +/** +This method will create and insert new (KEY, DATA) pair in the map. +If the operation fails, the method will return some of system wide error codes. +RMap instance does not allow duplicated TPair objects in the collection. +Actually it dependes on the supplied in the constructor aOrder instance. +@param aKey The key part of TPair object, which will be inserted +@param aData The data part of TPair object, which will be inserted +@return KErrNone if successful, otherwise one of the system-wide error codes +*/ +template +TInt RMap::Insert(const KEY& aKey, const DATA& aData) + { + return iCol.InsertInOrder(TPair(aKey, aData), iOrder); + } + +/** +This method removes an element with aKey key from the map. +If there is no such element in the map, the debug verison of the method will panic. +The destructor of the object, which is about to be removed, is not called. +@param aKey The key of TPair object, which has to be removed from the collection. +*/ +template +void RMap::Remove(const KEY& aKey) + { + TInt index = iCol.FindInOrder(TPair(aKey), iOrder); + index != KErrNotFound ? iCol.Remove(index) : __ASSERT(0); + } + +/** +This method performs a search for an element with aKey key in the map. +If such element exists, the method will return a const reference to the element's data. +If not, then the method will panic. +@param aKey The key of TPair object, a reference to which DATA will be returned +@return A const reference to the matching DATA object. +*/ +template +const DATA& RMap::operator[](const KEY& aKey) const + { + TInt index = iCol.FindInOrder(TPair(aKey), iOrder); + __ASSERT_ALWAYS(index != KErrNotFound, User::Invariant()); + return iCol[index].iData; + } + +/** +This method performs a search for an element with aKey key in the map. +If such element exists, the method will set the element's data in aData parameter and +return KErrNone. +If not, then the method will return KErrNotFound. +@param aKey The key of TPair object, a reference to which DATA will be returned in aData + parameter, if found +@param aData An output parameter, it references the location, where the found data will be stored. +@return KErrNone An element with aKey key exists in the map, the data part is stored in aData. +@return KErrNotFound No map element with aKey key found. +*/ +template +TInt RMap::Find(const KEY& aKey, DATA& aData) const + { + TInt index = iCol.FindInOrder(TPair(aKey), iOrder); + if(index != KErrNotFound) + { + aData = iCol[index].iData; + } + return index; + } + +/** +This method returns the number of elements in the map. +@return Map elements count. +*/ +template +TInt RMap::Count() const + { + return iCol.Count(); + } + +/** +Initializes TMapIterator instance. +@param aMap A const reference to the RMap object, which will be iterated. +*/ +template +TMapIterator::TMapIterator(const RMap& aMap) : + iMap(aMap), + iIndex(0) + { + } + +/** +Resets TMapIterator iterator for a new scan from the beginning of the controlled map sequence. +*/ +template +void TMapIterator::Reset() + { + iIndex = 0; + } + +/** +If iterator's current position is not beyond the end of the map, +the iterator will retrieve current map entry into aPair argument, advance iterator position +by 1 and return ETrue. +Otherwise the iterator will return EFalse. +@param aPair An output parameter, which references the location, where the next RMap element will be stored. +@return ETrue The next RMap element successfully loaded into aPair parameter. This is not the + end of RMap collection. +@return EFalse The next RMap element successfully loaded into aPair parameter. This is the + end of RMap collection. Do not call Next() anymore. +*/ +template +TBool TMapIterator::Next(TPair& aPair) const + { + return (iIndex < iMap.iCol.Count()) ? aPair = iMap.iCol[iIndex++], ETrue : EFalse; + }