williamr@2: /* williamr@2: * Copyright (c) 2003-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 "Eclipse Public License v1.0" williamr@2: * which accompanies this distribution, and is available williamr@2: * at the URL "http://www.eclipse.org/legal/epl-v10.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: williamr@2: williamr@2: williamr@2: williamr@2: /** williamr@2: @file williamr@2: @publishedPartner williamr@2: @deprecated williamr@2: */ williamr@2: williamr@2: #ifndef __BITSET_H__ williamr@2: #define __BITSET_H__ williamr@2: williamr@2: #ifndef REMOVE_CAF1 williamr@2: williamr@2: #include williamr@2: #include williamr@2: williamr@2: class RWriteStream; williamr@2: class RReadStream; williamr@2: williamr@2: namespace ContentAccess williamr@2: { williamr@2: williamr@2: /** @deprecated */ williamr@2: enum TCafUtilsPanics williamr@2: { williamr@2: EInvalidBit williamr@2: }; williamr@2: williamr@2: _LIT(KCafUtilsPanic, "CafUtils"); williamr@2: williamr@2: /** williamr@2: * A container of bits. williamr@2: * williamr@2: * The bits may be retrieved, set, and unset. williamr@2: * williamr@2: * @publishedPartner williamr@2: * @deprecated williamr@2: */ williamr@2: class CBitset : public CBase williamr@2: { williamr@2: public: williamr@2: /** williamr@2: * Constructs a new bitset object with a maximum number of bits. williamr@2: * williamr@2: * @param aMaxBits The maximum number of bits this object may contain. williamr@2: */ williamr@2: IMPORT_C static CBitset* NewL(TInt aMaxBits); williamr@2: williamr@2: /** @see CBitset::NewL(TInt aMaxBits) */ williamr@2: IMPORT_C static CBitset* NewLC(TInt aMaxBits); williamr@2: williamr@2: /** williamr@2: * Copy constructor williamr@2: * williamr@2: * @param aSource The object to be copied from. williamr@2: */ williamr@2: IMPORT_C static CBitset* NewL(const CBitset& aSource); williamr@2: williamr@2: /** @see CBitset::NewL(const CBitset& aSource) */ williamr@2: IMPORT_C static CBitset* NewLC(const CBitset& aSource); williamr@2: williamr@2: virtual ~CBitset(); williamr@2: williamr@2: public: williamr@2: /** Resets the entire bitset to zero. */ williamr@2: IMPORT_C void Reset(); williamr@2: williamr@2: /** Gets the maximum number of settable/gettable bits. */ williamr@2: IMPORT_C TInt MaxBits() const; williamr@2: williamr@2: /** Sets all bits in the set to one. */ williamr@2: IMPORT_C void SetAll(); williamr@2: williamr@2: /** Inverts all bits in the set. */ williamr@2: IMPORT_C void Invert(); williamr@2: williamr@2: /** Sets the 'aBit'th bit of the set. williamr@2: * @param aBit the bit to set williamr@2: * @panic CafUtils 0 if aBit is out of range williamr@2: */ williamr@2: IMPORT_C void Set(TInt aBit); williamr@2: williamr@2: /** Clears the 'aBit'th bit of the set. williamr@2: * @param aBit the bit to clear williamr@2: * @panic CafUtils 0 if aBit is out of range williamr@2: */ williamr@2: IMPORT_C void Unset(TInt aBit); williamr@2: williamr@2: /** williamr@2: * Queries the single bit of the set. williamr@2: * williamr@2: * @param aBit The bit that requires testing. williamr@2: * @return ETrue if the bit was set, EFalse otherwise. williamr@2: * @panic CafUtils 0 if aBit is out of range williamr@2: * williamr@2: */ williamr@2: IMPORT_C TBool IsSet(TInt aBit) const; williamr@2: williamr@2: /** williamr@2: * Assignment of a bitset. williamr@2: * williamr@2: * Note that an assignment of a longer bitset to a williamr@2: * shorter bitset will result in the shorter bitset williamr@2: * being expanded. This function may leave. williamr@2: * williamr@2: * @param aSource The bitset ...... williamr@2: * @return A bitset. williamr@2: */ williamr@2: IMPORT_C CBitset& operator=(const CBitset& aSource); williamr@2: williamr@2: /** williamr@2: * Allows comparisons of CBitsets. williamr@2: * williamr@2: * Note that it is possible to compare a longer williamr@2: * bitset with a shorter one. However, only the williamr@2: * relevant (low-order) bits are compared. williamr@2: * williamr@2: * @param aSource The bitset ..... williamr@2: * @return ETrue if the ....., EFalse otherwise. williamr@2: */ williamr@2: IMPORT_C TBool operator==(const CBitset& aSource) const; williamr@2: inline TBool operator!=(const CBitset& aSource) const; williamr@2: williamr@2: /** williamr@2: * Externalisation function that allows this object to be williamr@2: * marshalled prior to being shipped over a client-server williamr@2: * interface by related glue-code. williamr@2: * williamr@2: * @param aStream On return, the ..... williamr@2: */ williamr@2: IMPORT_C void ExternalizeL(RWriteStream& aStream) const; williamr@2: williamr@2: /** williamr@2: * Internalisation function that allows this object to to be williamr@2: * unmarshalled after transfer across a client-server williamr@2: * interface. williamr@2: * williamr@2: * @param aStream On return, the ..... williamr@2: */ williamr@2: IMPORT_C void InternalizeL(RReadStream& aStream); williamr@2: williamr@2: /** williamr@2: * Allows a caller to set multiple bits in the bitset williamr@2: * by allowing a variable-length parameter list. williamr@2: * williamr@2: * @param aItems The number of items following in the williamr@2: * parameter list. williamr@2: */ williamr@2: IMPORT_C void SetListL(TInt aItems, ...); williamr@2: williamr@2: /** williamr@2: * Allows a caller to query multiple bits in the bitset. williamr@2: * williamr@2: * @param aItems The number of items following in the williamr@2: * parameter list. williamr@2: * @return ETrue if all of the bits specified were set. EFalse if williamr@2: * one or more were unset. williamr@2: */ williamr@2: IMPORT_C TBool IsSetList(TInt aItems, ...) const; williamr@2: williamr@2: private: williamr@2: void ConstructL(TInt aMaxId); williamr@2: void ConstructL(const CBitset& aSource); williamr@2: CBitset(); williamr@2: CBitset(const CBitset& aSource); williamr@2: williamr@2: /** williamr@2: * Converts from a bit ID to a byte and williamr@2: * bit within one of the bit-field sets. williamr@2: * williamr@2: * @param aBitId The bit ID being mapped. williamr@2: * @param aByte Modified to contain the resultant byte number. williamr@2: * @param aBitInByte Modified to contain the resultant bit number williamr@2: * within the byte. williamr@2: */ williamr@2: void IdentifyBit(TInt aBitId, TInt& aByte, TInt& aBitInByte) const; williamr@2: williamr@2: /** williamr@2: * Tests whether the bit value is valid for this bitset. williamr@2: * williamr@2: * @param aAttributeId The ..... williamr@2: * @return ETrue if the bit value is valid for this bitset, EFalse otherwise. williamr@2: */ williamr@2: inline TBool ValidBit(TInt aAttributeId) const; williamr@2: williamr@2: private: williamr@2: /** The number of bytes required to allow for maxbits */ williamr@2: TInt iWidth; williamr@2: williamr@2: /** The maximum number of bits in this bitset */ williamr@2: TInt iMaxBits; williamr@2: williamr@2: /** The actual set of bits */ williamr@2: TUint8* iBitSet; williamr@2: }; williamr@2: williamr@2: } williamr@2: williamr@2: inline TBool ContentAccess::CBitset::operator!=(const CBitset& aSource) const williamr@2: { williamr@2: return !operator==(aSource); williamr@2: } williamr@2: williamr@2: inline TBool ContentAccess::CBitset::ValidBit(TInt aBit) const williamr@2: { williamr@2: return (aBit >= 0) && (aBit < iMaxBits); williamr@2: } williamr@2: williamr@2: #endif // REMOVE_CAF1 williamr@2: williamr@2: #endif // __BITSET_H__