1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/caf/bitset.h Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -0,0 +1,229 @@
1.4 +/*
1.5 +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +
1.23 +
1.24 +/**
1.25 + @file
1.26 + @publishedPartner
1.27 + @deprecated
1.28 +*/
1.29 +
1.30 +#ifndef __BITSET_H__
1.31 +#define __BITSET_H__
1.32 +
1.33 +#ifndef REMOVE_CAF1
1.34 +
1.35 +#include <e32base.h>
1.36 +#include <caf/caftypes.h>
1.37 +
1.38 +class RWriteStream;
1.39 +class RReadStream;
1.40 +
1.41 +namespace ContentAccess
1.42 +{
1.43 +
1.44 + /** @deprecated */
1.45 + enum TCafUtilsPanics
1.46 + {
1.47 + EInvalidBit
1.48 + };
1.49 +
1.50 + _LIT(KCafUtilsPanic, "CafUtils");
1.51 +
1.52 + /**
1.53 + * A container of bits.
1.54 + *
1.55 + * The bits may be retrieved, set, and unset.
1.56 + *
1.57 + * @publishedPartner
1.58 + * @deprecated
1.59 + */
1.60 + class CBitset : public CBase
1.61 + {
1.62 + public:
1.63 + /**
1.64 + * Constructs a new bitset object with a maximum number of bits.
1.65 + *
1.66 + * @param aMaxBits The maximum number of bits this object may contain.
1.67 + */
1.68 + IMPORT_C static CBitset* NewL(TInt aMaxBits);
1.69 +
1.70 + /** @see CBitset::NewL(TInt aMaxBits) */
1.71 + IMPORT_C static CBitset* NewLC(TInt aMaxBits);
1.72 +
1.73 + /**
1.74 + * Copy constructor
1.75 + *
1.76 + * @param aSource The object to be copied from.
1.77 + */
1.78 + IMPORT_C static CBitset* NewL(const CBitset& aSource);
1.79 +
1.80 + /** @see CBitset::NewL(const CBitset& aSource) */
1.81 + IMPORT_C static CBitset* NewLC(const CBitset& aSource);
1.82 +
1.83 + virtual ~CBitset();
1.84 +
1.85 + public:
1.86 + /** Resets the entire bitset to zero. */
1.87 + IMPORT_C void Reset();
1.88 +
1.89 + /** Gets the maximum number of settable/gettable bits. */
1.90 + IMPORT_C TInt MaxBits() const;
1.91 +
1.92 + /** Sets all bits in the set to one. */
1.93 + IMPORT_C void SetAll();
1.94 +
1.95 + /** Inverts all bits in the set. */
1.96 + IMPORT_C void Invert();
1.97 +
1.98 + /** Sets the 'aBit'th bit of the set.
1.99 + * @param aBit the bit to set
1.100 + * @panic CafUtils 0 if aBit is out of range
1.101 + */
1.102 + IMPORT_C void Set(TInt aBit);
1.103 +
1.104 + /** Clears the 'aBit'th bit of the set.
1.105 + * @param aBit the bit to clear
1.106 + * @panic CafUtils 0 if aBit is out of range
1.107 + */
1.108 + IMPORT_C void Unset(TInt aBit);
1.109 +
1.110 + /**
1.111 + * Queries the single bit of the set.
1.112 + *
1.113 + * @param aBit The bit that requires testing.
1.114 + * @return ETrue if the bit was set, EFalse otherwise.
1.115 + * @panic CafUtils 0 if aBit is out of range
1.116 + *
1.117 + */
1.118 + IMPORT_C TBool IsSet(TInt aBit) const;
1.119 +
1.120 + /**
1.121 + * Assignment of a bitset.
1.122 + *
1.123 + * Note that an assignment of a longer bitset to a
1.124 + * shorter bitset will result in the shorter bitset
1.125 + * being expanded. This function may leave.
1.126 + *
1.127 + * @param aSource The bitset ......
1.128 + * @return A bitset.
1.129 + */
1.130 + IMPORT_C CBitset& operator=(const CBitset& aSource);
1.131 +
1.132 + /**
1.133 + * Allows comparisons of CBitsets.
1.134 + *
1.135 + * Note that it is possible to compare a longer
1.136 + * bitset with a shorter one. However, only the
1.137 + * relevant (low-order) bits are compared.
1.138 + *
1.139 + * @param aSource The bitset .....
1.140 + * @return ETrue if the ....., EFalse otherwise.
1.141 + */
1.142 + IMPORT_C TBool operator==(const CBitset& aSource) const;
1.143 + inline TBool operator!=(const CBitset& aSource) const;
1.144 +
1.145 + /**
1.146 + * Externalisation function that allows this object to be
1.147 + * marshalled prior to being shipped over a client-server
1.148 + * interface by related glue-code.
1.149 + *
1.150 + * @param aStream On return, the .....
1.151 + */
1.152 + IMPORT_C void ExternalizeL(RWriteStream& aStream) const;
1.153 +
1.154 + /**
1.155 + * Internalisation function that allows this object to to be
1.156 + * unmarshalled after transfer across a client-server
1.157 + * interface.
1.158 + *
1.159 + * @param aStream On return, the .....
1.160 + */
1.161 + IMPORT_C void InternalizeL(RReadStream& aStream);
1.162 +
1.163 + /**
1.164 + * Allows a caller to set multiple bits in the bitset
1.165 + * by allowing a variable-length parameter list.
1.166 + *
1.167 + * @param aItems The number of items following in the
1.168 + * parameter list.
1.169 + */
1.170 + IMPORT_C void SetListL(TInt aItems, ...);
1.171 +
1.172 + /**
1.173 + * Allows a caller to query multiple bits in the bitset.
1.174 + *
1.175 + * @param aItems The number of items following in the
1.176 + * parameter list.
1.177 + * @return ETrue if all of the bits specified were set. EFalse if
1.178 + * one or more were unset.
1.179 + */
1.180 + IMPORT_C TBool IsSetList(TInt aItems, ...) const;
1.181 +
1.182 + private:
1.183 + void ConstructL(TInt aMaxId);
1.184 + void ConstructL(const CBitset& aSource);
1.185 + CBitset();
1.186 + CBitset(const CBitset& aSource);
1.187 +
1.188 + /**
1.189 + * Converts from a bit ID to a byte and
1.190 + * bit within one of the bit-field sets.
1.191 + *
1.192 + * @param aBitId The bit ID being mapped.
1.193 + * @param aByte Modified to contain the resultant byte number.
1.194 + * @param aBitInByte Modified to contain the resultant bit number
1.195 + * within the byte.
1.196 + */
1.197 + void IdentifyBit(TInt aBitId, TInt& aByte, TInt& aBitInByte) const;
1.198 +
1.199 + /**
1.200 + * Tests whether the bit value is valid for this bitset.
1.201 + *
1.202 + * @param aAttributeId The .....
1.203 + * @return ETrue if the bit value is valid for this bitset, EFalse otherwise.
1.204 + */
1.205 + inline TBool ValidBit(TInt aAttributeId) const;
1.206 +
1.207 + private:
1.208 + /** The number of bytes required to allow for maxbits */
1.209 + TInt iWidth;
1.210 +
1.211 + /** The maximum number of bits in this bitset */
1.212 + TInt iMaxBits;
1.213 +
1.214 + /** The actual set of bits */
1.215 + TUint8* iBitSet;
1.216 + };
1.217 +
1.218 +}
1.219 +
1.220 +inline TBool ContentAccess::CBitset::operator!=(const CBitset& aSource) const
1.221 + {
1.222 + return !operator==(aSource);
1.223 + }
1.224 +
1.225 +inline TBool ContentAccess::CBitset::ValidBit(TInt aBit) const
1.226 + {
1.227 + return (aBit >= 0) && (aBit < iMaxBits);
1.228 + }
1.229 +
1.230 +#endif // REMOVE_CAF1
1.231 +
1.232 +#endif // __BITSET_H__