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