epoc32/include/caf/bitset.h
author William Roberts <williamr@symbian.org>
Tue, 16 Mar 2010 16:12:26 +0000
branchSymbian2
changeset 2 2fe1408b6811
permissions -rw-r--r--
Final list of Symbian^2 public API header files
     1 /*
     2 * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     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".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 
    20 
    21 /**
    22  @file
    23  @publishedPartner
    24  @deprecated
    25 */
    26 
    27 #ifndef __BITSET_H__
    28 #define __BITSET_H__
    29 
    30 #ifndef REMOVE_CAF1
    31 
    32 #include <e32base.h>
    33 #include <caf/caftypes.h>
    34 
    35 class RWriteStream;
    36 class RReadStream;
    37 
    38 namespace ContentAccess
    39 {
    40 	
    41 	/** @deprecated */
    42 	enum TCafUtilsPanics
    43 		{
    44 		EInvalidBit
    45 		};
    46 
    47 	_LIT(KCafUtilsPanic, "CafUtils");
    48 
    49 	/**
    50 	 * A container of bits. 
    51 	 * 
    52 	 * The bits may be retrieved, set, and unset.
    53 	 *
    54 	 * @publishedPartner
    55 	 * @deprecated 
    56 	 */
    57 	class CBitset : public CBase
    58 		{
    59 	public:
    60 		/**
    61 		 * Constructs a new bitset object with a maximum number of bits.
    62 		 * 
    63 		 * @param aMaxBits	The maximum number of bits this object may contain.
    64 		 */
    65 		IMPORT_C static CBitset* NewL(TInt aMaxBits);
    66 
    67 		/** @see CBitset::NewL(TInt aMaxBits) */
    68 		IMPORT_C static CBitset* NewLC(TInt aMaxBits);
    69 		
    70 		/** 
    71 		 * Copy constructor
    72 		 *
    73 		 * @param aSource	The object to be copied from.
    74 		 */
    75 		IMPORT_C static CBitset* NewL(const CBitset& aSource);
    76 
    77 		/** @see CBitset::NewL(const CBitset& aSource) */
    78 		IMPORT_C static CBitset* NewLC(const CBitset& aSource);
    79 
    80 		virtual ~CBitset();
    81 
    82 	public:
    83 		/** Resets the entire bitset to zero. */
    84 		IMPORT_C void Reset();
    85 
    86 		/** Gets the maximum number of settable/gettable bits. */
    87 		IMPORT_C TInt MaxBits() const;
    88 
    89 		/** Sets all bits in the set to one. */
    90 		IMPORT_C void SetAll();
    91 
    92 		/** Inverts all bits in the set. */
    93 		IMPORT_C void Invert();
    94 		
    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
    98 		*/
    99 		IMPORT_C void Set(TInt aBit);
   100 
   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
   104 		*/
   105 		IMPORT_C void Unset(TInt aBit);
   106 		
   107 		/** 
   108 		 * Queries the single bit of the set.
   109 		 * 
   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
   113 		 * 
   114 		 */
   115 		IMPORT_C TBool IsSet(TInt aBit) const;
   116 
   117 		/** 
   118 		 * Assignment of a bitset. 
   119 		 * 
   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.
   123 		 *
   124 		 * @param aSource	The bitset ......
   125 		 * @return			A bitset.
   126 		 */
   127 		IMPORT_C CBitset& operator=(const CBitset& aSource);
   128 
   129 		/**
   130 		 * Allows comparisons of CBitsets. 
   131 		 * 
   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.
   135 		 *
   136 		 * @param aSource	The bitset .....
   137 		 * @return			ETrue if the ....., EFalse otherwise.
   138 		 */
   139 		IMPORT_C TBool operator==(const CBitset& aSource) const;
   140 		inline TBool operator!=(const CBitset& aSource) const;
   141 
   142 		/** 
   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.
   146 		 *
   147 		 * @param aStream	On return, the .....
   148 		 */
   149 		IMPORT_C void ExternalizeL(RWriteStream& aStream) const;
   150 		
   151 		/**
   152 		 * Internalisation function that allows this object to to be
   153 		 * unmarshalled after transfer across a client-server
   154 		 * interface. 
   155 		 *
   156 		 * @param aStream	On return, the .....
   157 		 */
   158 		IMPORT_C void InternalizeL(RReadStream& aStream);
   159 
   160 		/**
   161 		 * Allows a caller to set multiple bits in the bitset
   162 		 * by allowing a variable-length parameter list. 
   163 		 * 
   164 		 * @param aItems	The number of items following in the
   165 		 * 					parameter list.
   166 		 */
   167 		IMPORT_C void SetListL(TInt aItems, ...);
   168 
   169 		/**
   170 		 * Allows a caller to query multiple bits in the bitset.
   171 		 * 
   172 		 * @param aItems	The number of items following in the
   173 		 * 					parameter list.
   174 		 * @return			ETrue if all of the bits specified were set. EFalse if
   175 		 * 					one or more were unset.
   176 		 */
   177 		IMPORT_C TBool IsSetList(TInt aItems, ...) const;
   178 
   179 	private:
   180 		void ConstructL(TInt aMaxId);
   181 		void ConstructL(const CBitset& aSource);
   182 		CBitset();
   183 		CBitset(const CBitset& aSource);
   184 
   185 		/**
   186 		 * Converts from a bit ID to a byte and 
   187 		 * bit within one of the bit-field sets.
   188 		 * 
   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
   192 		 * 						within the byte.
   193 		 */
   194 		void IdentifyBit(TInt aBitId, TInt& aByte, TInt& aBitInByte) const;
   195 		
   196 		/** 
   197 		* Tests whether the bit value is valid for this bitset.
   198 		*
   199 		* @param aAttributeId	The .....
   200 		* @return				ETrue if the bit value is valid for this bitset, EFalse otherwise.
   201 		*/
   202 		inline TBool ValidBit(TInt aAttributeId) const;
   203 		
   204 	private:
   205 		/** The number of bytes required to allow for maxbits */
   206 		TInt iWidth; 
   207 
   208 		/** The maximum number of bits in this bitset */
   209 		TInt iMaxBits;
   210 
   211 		/** The actual set of bits */
   212 		TUint8* iBitSet;
   213 		};
   214 
   215 }
   216 
   217 inline TBool ContentAccess::CBitset::operator!=(const CBitset& aSource) const
   218 	{
   219 	return !operator==(aSource);
   220 	}
   221 
   222 inline TBool ContentAccess::CBitset::ValidBit(TInt aBit) const
   223 	{
   224 	return (aBit >= 0) && (aBit < iMaxBits);
   225 	}
   226 
   227 #endif // REMOVE_CAF1
   228 
   229 #endif // __BITSET_H__