sl@0: // Copyright (c) 1995-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 the License "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: // Collection of common constants, utility functions, etc. for the file server and file systems. sl@0: // Definitions here must be filesystem-agnostic, i.e. generic enougs to be used by every file system sl@0: // sl@0: // This is the internal file and must not be exported. sl@0: sl@0: /** sl@0: @file sl@0: @internalTechnology sl@0: */ sl@0: sl@0: #if !defined(__FILESYSTEM_UTILS_BIT_VECTOR__) sl@0: #define __FILESYSTEM_UTILS_BIT_VECTOR__ sl@0: sl@0: #if !defined(__FILESYSTEM_UTILS_H__) sl@0: #include "filesystem_utils.h" sl@0: #endif sl@0: sl@0: sl@0: //####################################################################################################################################### sl@0: sl@0: /** sl@0: This class represents a bit vector i.e. an array of bits. Vector size can be from 1 to 2^32 bits. sl@0: This class can be created on a stack (but needs to be placed into cleanup stack) or in a heap with the help of its factory methods Create/CreateL sl@0: */ sl@0: class RBitVector sl@0: { sl@0: public: sl@0: sl@0: RBitVector(); //-- Creates an empty vector. see Create() methods for memory allocation sl@0: ~RBitVector(); sl@0: sl@0: void Close(); sl@0: sl@0: TInt Create(TUint32 aNumBits); sl@0: void CreateL(TUint32 aNumBits); sl@0: sl@0: inline TUint32 Size() const; sl@0: sl@0: //-- single bit manipulation methods sl@0: inline TBool operator[](TUint32 aIndex) const; sl@0: inline void SetBit(TUint32 aIndex); sl@0: inline void ResetBit(TUint32 aIndex); sl@0: inline void InvertBit(TUint32 aIndex); sl@0: inline void SetBitVal(TUint32 aIndex, TBool aVal); sl@0: sl@0: void Fill(TBool aVal); sl@0: void Fill(TUint32 aIndexFrom, TUint32 aIndexTo, TBool aVal); sl@0: sl@0: void Invert(); sl@0: sl@0: TBool operator==(const RBitVector& aRhs) const; sl@0: TBool operator!=(const RBitVector& aRhs) const; sl@0: sl@0: //-- logical operations between 2 vectors. sl@0: void And(const RBitVector& aRhs); sl@0: void Or (const RBitVector& aRhs); sl@0: void Xor(const RBitVector& aRhs); sl@0: sl@0: TBool Diff(const RBitVector& aRhs, TUint32& aDiffIndex) const; sl@0: sl@0: TUint32 Num1Bits() const; sl@0: TUint32 Num1Bits(TUint32 aIndexFrom, TUint32 aIndexTo) const; sl@0: sl@0: TUint32 Num0Bits() const; sl@0: sl@0: sl@0: /** Bit search specifiers */ sl@0: enum TFindDirection sl@0: { sl@0: ELeft, ///< Search from the given position to the left (towards lower index) sl@0: ERight, ///< Search from the given position to the right (towards higher index) sl@0: ENearestL, ///< Search in both directions starting from the given position; in the case of the equal distances return the position to the left sl@0: ENearestR ///< Search in both directions starting from the given position; in the case of the equal distances return the position to the right sl@0: sl@0: //-- N.B the current position the search starts with isn't included to the search. sl@0: }; sl@0: sl@0: TBool Find(TUint32& aStartPos, TBool aBitVal, TFindDirection aDir) const; sl@0: sl@0: /** panic codes */ sl@0: enum TPanicCode sl@0: { sl@0: EIndexOutOfRange, ///< index out of range sl@0: EWrondFindDirection, ///< a value doesn't belong to TFindDirection sl@0: ESizeMismatch, ///< Size mismatch for binary operators sl@0: ENotInitialised, ///< No memory allocated for the array sl@0: ENotImplemented, ///< functionality isn't implemented sl@0: sl@0: EDataAlignment, ///< wrong data alignment when importing / exporting raw data sl@0: }; sl@0: sl@0: protected: sl@0: sl@0: //-- these are outlawed. Can't use them because memory allocator can leave and we don't have conthrol on it in these methods. sl@0: RBitVector(const RBitVector& aRhs); sl@0: RBitVector& operator=(const RBitVector& aRhs); sl@0: sl@0: void* operator new(TUint); //-- disable creating objects on heap. sl@0: void* operator new(TUint, void*); sl@0: //------------------------------------- sl@0: sl@0: sl@0: void Panic(TPanicCode aPanicCode) const; sl@0: sl@0: inline TUint32 WordNum(TUint32 aBitPos) const; sl@0: inline TUint32 BitInWord(TUint32 aBitPos) const; sl@0: sl@0: protected: sl@0: //-- special interface to acecess raw internal data. It's protected. Derive appropriate class from this one if you wan to use it sl@0: void DoImportData(TUint32 aStartBit, TUint32 aNumBits, const TAny* apData); sl@0: void DoExportData(TUint32 aStartBit, TUint32 aNumBits, TDes8& aData) const; sl@0: sl@0: sl@0: private: sl@0: TBool FindToRight(TUint32& aStartPos, TBool aBitVal) const; sl@0: TBool FindToLeft (TUint32& aStartPos, TBool aBitVal) const; sl@0: TBool FindNearest(TUint32& aStartPos, TBool aBitVal, TBool aToLeft) const; sl@0: sl@0: inline TUint32 MaskLastWord(TUint32 aVal) const; sl@0: inline TBool ItrLeft(TUint32& aIdx) const; sl@0: inline TBool ItrRight(TUint32& aIdx) const; sl@0: sl@0: sl@0: protected: sl@0: sl@0: TUint32 iNumBits; ///< number of bits in the vector sl@0: TUint32* ipData; ///< pointer to the data sl@0: TUint32 iNumWords;///< number of 32-bit words that store bits sl@0: }; sl@0: sl@0: sl@0: //####################################################################################################################################### sl@0: //# inline functions area sl@0: //####################################################################################################################################### sl@0: sl@0: sl@0: //--------------------------------------------------------------------------------------------------------------------------------- sl@0: //-- class RBitVector sl@0: sl@0: /** @return size of the vector (number of bits) */ sl@0: inline TUint32 RBitVector::Size() const sl@0: { sl@0: return iNumBits; sl@0: } sl@0: sl@0: /** sl@0: Get a bit by index sl@0: sl@0: @param aIndex index in a bit vector sl@0: @return 0 if the bit at pos aIndex is 0, not zero otherwise sl@0: @panic EIndexOutOfRange if aIndex is out of range sl@0: */ sl@0: inline TBool RBitVector::operator[](TUint32 aIndex) const sl@0: { sl@0: __ASSERT_ALWAYS(aIndex < iNumBits, Panic(EIndexOutOfRange)); sl@0: return (ipData[WordNum(aIndex)] & (1<> shift; //-- mask unused high bits sl@0: } sl@0: sl@0: inline TUint32 RBitVector::WordNum(TUint32 aBitPos) const sl@0: { sl@0: return aBitPos >> 5; sl@0: } sl@0: sl@0: inline TUint32 RBitVector::BitInWord(TUint32 aBitPos) const sl@0: { sl@0: return aBitPos & 0x1F; sl@0: } sl@0: sl@0: sl@0: sl@0: #endif //__FILESYSTEM_UTILS_BIT_VECTOR__ sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: