First public contribution.
2 * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
31 #include <caf/caftypes.h>
36 namespace ContentAccess
45 _LIT(KCafUtilsPanic, "CafUtils");
48 * A container of bits.
50 * The bits may be retrieved, set, and unset.
55 class CBitset : public CBase
59 * Constructs a new bitset object with a maximum number of bits.
61 * @param aMaxBits The maximum number of bits this object may contain.
63 IMPORT_C static CBitset* NewL(TInt aMaxBits);
65 /** @see CBitset::NewL(TInt aMaxBits) */
66 IMPORT_C static CBitset* NewLC(TInt aMaxBits);
71 * @param aSource The object to be copied from.
73 IMPORT_C static CBitset* NewL(const CBitset& aSource);
75 /** @see CBitset::NewL(const CBitset& aSource) */
76 IMPORT_C static CBitset* NewLC(const CBitset& aSource);
81 /** Resets the entire bitset to zero. */
82 IMPORT_C void Reset();
84 /** Gets the maximum number of settable/gettable bits. */
85 IMPORT_C TInt MaxBits() const;
87 /** Sets all bits in the set to one. */
88 IMPORT_C void SetAll();
90 /** Inverts all bits in the set. */
91 IMPORT_C void Invert();
93 /** Sets the 'aBit'th bit of the set.
94 * @param aBit the bit to set
95 * @panic CafUtils 0 if aBit is out of range
97 IMPORT_C void Set(TInt aBit);
99 /** Clears the 'aBit'th bit of the set.
100 * @param aBit the bit to clear
101 * @panic CafUtils 0 if aBit is out of range
103 IMPORT_C void Unset(TInt aBit);
106 * Queries the single bit of the set.
108 * @param aBit The bit that requires testing.
109 * @return ETrue if the bit was set, EFalse otherwise.
110 * @panic CafUtils 0 if aBit is out of range
113 IMPORT_C TBool IsSet(TInt aBit) const;
116 * Assignment of a bitset.
118 * Note that an assignment of a longer bitset to a
119 * shorter bitset will result in the shorter bitset
120 * being expanded. This function may leave.
122 * @param aSource The bitset ......
125 IMPORT_C CBitset& operator=(const CBitset& aSource);
128 * Allows comparisons of CBitsets.
130 * Note that it is possible to compare a longer
131 * bitset with a shorter one. However, only the
132 * relevant (low-order) bits are compared.
134 * @param aSource The bitset .....
135 * @return ETrue if the ....., EFalse otherwise.
137 IMPORT_C TBool operator==(const CBitset& aSource) const;
138 inline TBool operator!=(const CBitset& aSource) const;
141 * Externalisation function that allows this object to be
142 * marshalled prior to being shipped over a client-server
143 * interface by related glue-code.
145 * @param aStream On return, the .....
147 IMPORT_C void ExternalizeL(RWriteStream& aStream) const;
150 * Internalisation function that allows this object to to be
151 * unmarshalled after transfer across a client-server
154 * @param aStream On return, the .....
156 IMPORT_C void InternalizeL(RReadStream& aStream);
159 * Allows a caller to set multiple bits in the bitset
160 * by allowing a variable-length parameter list.
162 * @param aItems The number of items following in the
165 IMPORT_C void SetListL(TInt aItems, ...);
168 * Allows a caller to query multiple bits in the bitset.
170 * @param aItems The number of items following in the
172 * @return ETrue if all of the bits specified were set. EFalse if
173 * one or more were unset.
175 IMPORT_C TBool IsSetList(TInt aItems, ...) const;
178 void ConstructL(TInt aMaxId);
179 void ConstructL(const CBitset& aSource);
181 CBitset(const CBitset& aSource);
184 * Converts from a bit ID to a byte and
185 * bit within one of the bit-field sets.
187 * @param aBitId The bit ID being mapped.
188 * @param aByte Modified to contain the resultant byte number.
189 * @param aBitInByte Modified to contain the resultant bit number
192 void IdentifyBit(TInt aBitId, TInt& aByte, TInt& aBitInByte) const;
195 * Tests whether the bit value is valid for this bitset.
197 * @param aAttributeId The .....
198 * @return ETrue if the bit value is valid for this bitset, EFalse otherwise.
200 inline TBool ValidBit(TInt aAttributeId) const;
203 /** The number of bytes required to allow for maxbits */
206 /** The maximum number of bits in this bitset */
209 /** The actual set of bits */
215 inline TBool ContentAccess::CBitset::operator!=(const CBitset& aSource) const
217 return !operator==(aSource);
220 inline TBool ContentAccess::CBitset::ValidBit(TInt aBit) const
222 return (aBit >= 0) && (aBit < iMaxBits);
225 #endif // REMOVE_CAF1
227 #endif // __BITSET_H__