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.
33 #include <caf/caftypes.h>
38 namespace ContentAccess
47 _LIT(KCafUtilsPanic, "CafUtils");
50 * A container of bits.
52 * The bits may be retrieved, set, and unset.
57 class CBitset : public CBase
61 * Constructs a new bitset object with a maximum number of bits.
63 * @param aMaxBits The maximum number of bits this object may contain.
65 IMPORT_C static CBitset* NewL(TInt aMaxBits);
67 /** @see CBitset::NewL(TInt aMaxBits) */
68 IMPORT_C static CBitset* NewLC(TInt aMaxBits);
73 * @param aSource The object to be copied from.
75 IMPORT_C static CBitset* NewL(const CBitset& aSource);
77 /** @see CBitset::NewL(const CBitset& aSource) */
78 IMPORT_C static CBitset* NewLC(const CBitset& aSource);
83 /** Resets the entire bitset to zero. */
84 IMPORT_C void Reset();
86 /** Gets the maximum number of settable/gettable bits. */
87 IMPORT_C TInt MaxBits() const;
89 /** Sets all bits in the set to one. */
90 IMPORT_C void SetAll();
92 /** Inverts all bits in the set. */
93 IMPORT_C void Invert();
95 /** Sets the 'aBit'th bit of the set.
96 * @param aBit the bit to set
97 * @panic CafUtils 0 if aBit is out of range
99 IMPORT_C void Set(TInt aBit);
101 /** Clears the 'aBit'th bit of the set.
102 * @param aBit the bit to clear
103 * @panic CafUtils 0 if aBit is out of range
105 IMPORT_C void Unset(TInt aBit);
108 * Queries the single bit of the set.
110 * @param aBit The bit that requires testing.
111 * @return ETrue if the bit was set, EFalse otherwise.
112 * @panic CafUtils 0 if aBit is out of range
115 IMPORT_C TBool IsSet(TInt aBit) const;
118 * Assignment of a bitset.
120 * Note that an assignment of a longer bitset to a
121 * shorter bitset will result in the shorter bitset
122 * being expanded. This function may leave.
124 * @param aSource The bitset ......
127 IMPORT_C CBitset& operator=(const CBitset& aSource);
130 * Allows comparisons of CBitsets.
132 * Note that it is possible to compare a longer
133 * bitset with a shorter one. However, only the
134 * relevant (low-order) bits are compared.
136 * @param aSource The bitset .....
137 * @return ETrue if the ....., EFalse otherwise.
139 IMPORT_C TBool operator==(const CBitset& aSource) const;
140 inline TBool operator!=(const CBitset& aSource) const;
143 * Externalisation function that allows this object to be
144 * marshalled prior to being shipped over a client-server
145 * interface by related glue-code.
147 * @param aStream On return, the .....
149 IMPORT_C void ExternalizeL(RWriteStream& aStream) const;
152 * Internalisation function that allows this object to to be
153 * unmarshalled after transfer across a client-server
156 * @param aStream On return, the .....
158 IMPORT_C void InternalizeL(RReadStream& aStream);
161 * Allows a caller to set multiple bits in the bitset
162 * by allowing a variable-length parameter list.
164 * @param aItems The number of items following in the
167 IMPORT_C void SetListL(TInt aItems, ...);
170 * Allows a caller to query multiple bits in the bitset.
172 * @param aItems The number of items following in the
174 * @return ETrue if all of the bits specified were set. EFalse if
175 * one or more were unset.
177 IMPORT_C TBool IsSetList(TInt aItems, ...) const;
180 void ConstructL(TInt aMaxId);
181 void ConstructL(const CBitset& aSource);
183 CBitset(const CBitset& aSource);
186 * Converts from a bit ID to a byte and
187 * bit within one of the bit-field sets.
189 * @param aBitId The bit ID being mapped.
190 * @param aByte Modified to contain the resultant byte number.
191 * @param aBitInByte Modified to contain the resultant bit number
194 void IdentifyBit(TInt aBitId, TInt& aByte, TInt& aBitInByte) const;
197 * Tests whether the bit value is valid for this bitset.
199 * @param aAttributeId The .....
200 * @return ETrue if the bit value is valid for this bitset, EFalse otherwise.
202 inline TBool ValidBit(TInt aAttributeId) const;
205 /** The number of bytes required to allow for maxbits */
208 /** The maximum number of bits in this bitset */
211 /** The actual set of bits */
217 inline TBool ContentAccess::CBitset::operator!=(const CBitset& aSource) const
219 return !operator==(aSource);
222 inline TBool ContentAccess::CBitset::ValidBit(TInt aBit) const
224 return (aBit >= 0) && (aBit < iMaxBits);
227 #endif // REMOVE_CAF1
229 #endif // __BITSET_H__