os/security/contentmgmt/contentaccessfwfordrm/inc/bitset.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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  @file
    21  @publishedPartner
    22  @deprecated
    23 */
    24 
    25 #ifndef __BITSET_H__
    26 #define __BITSET_H__
    27 
    28 #ifndef REMOVE_CAF1
    29 
    30 #include <e32base.h>
    31 #include <caf/caftypes.h>
    32 
    33 class RWriteStream;
    34 class RReadStream;
    35 
    36 namespace ContentAccess
    37 {
    38 	
    39 	/** @deprecated */
    40 	enum TCafUtilsPanics
    41 		{
    42 		EInvalidBit
    43 		};
    44 
    45 	_LIT(KCafUtilsPanic, "CafUtils");
    46 
    47 	/**
    48 	 * A container of bits. 
    49 	 * 
    50 	 * The bits may be retrieved, set, and unset.
    51 	 *
    52 	 * @publishedPartner
    53 	 * @deprecated 
    54 	 */
    55 	class CBitset : public CBase
    56 		{
    57 	public:
    58 		/**
    59 		 * Constructs a new bitset object with a maximum number of bits.
    60 		 * 
    61 		 * @param aMaxBits	The maximum number of bits this object may contain.
    62 		 */
    63 		IMPORT_C static CBitset* NewL(TInt aMaxBits);
    64 
    65 		/** @see CBitset::NewL(TInt aMaxBits) */
    66 		IMPORT_C static CBitset* NewLC(TInt aMaxBits);
    67 		
    68 		/** 
    69 		 * Copy constructor
    70 		 *
    71 		 * @param aSource	The object to be copied from.
    72 		 */
    73 		IMPORT_C static CBitset* NewL(const CBitset& aSource);
    74 
    75 		/** @see CBitset::NewL(const CBitset& aSource) */
    76 		IMPORT_C static CBitset* NewLC(const CBitset& aSource);
    77 
    78 		virtual ~CBitset();
    79 
    80 	public:
    81 		/** Resets the entire bitset to zero. */
    82 		IMPORT_C void Reset();
    83 
    84 		/** Gets the maximum number of settable/gettable bits. */
    85 		IMPORT_C TInt MaxBits() const;
    86 
    87 		/** Sets all bits in the set to one. */
    88 		IMPORT_C void SetAll();
    89 
    90 		/** Inverts all bits in the set. */
    91 		IMPORT_C void Invert();
    92 		
    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
    96 		*/
    97 		IMPORT_C void Set(TInt aBit);
    98 
    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
   102 		*/
   103 		IMPORT_C void Unset(TInt aBit);
   104 		
   105 		/** 
   106 		 * Queries the single bit of the set.
   107 		 * 
   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
   111 		 * 
   112 		 */
   113 		IMPORT_C TBool IsSet(TInt aBit) const;
   114 
   115 		/** 
   116 		 * Assignment of a bitset. 
   117 		 * 
   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.
   121 		 *
   122 		 * @param aSource	The bitset ......
   123 		 * @return			A bitset.
   124 		 */
   125 		IMPORT_C CBitset& operator=(const CBitset& aSource);
   126 
   127 		/**
   128 		 * Allows comparisons of CBitsets. 
   129 		 * 
   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.
   133 		 *
   134 		 * @param aSource	The bitset .....
   135 		 * @return			ETrue if the ....., EFalse otherwise.
   136 		 */
   137 		IMPORT_C TBool operator==(const CBitset& aSource) const;
   138 		inline TBool operator!=(const CBitset& aSource) const;
   139 
   140 		/** 
   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.
   144 		 *
   145 		 * @param aStream	On return, the .....
   146 		 */
   147 		IMPORT_C void ExternalizeL(RWriteStream& aStream) const;
   148 		
   149 		/**
   150 		 * Internalisation function that allows this object to to be
   151 		 * unmarshalled after transfer across a client-server
   152 		 * interface. 
   153 		 *
   154 		 * @param aStream	On return, the .....
   155 		 */
   156 		IMPORT_C void InternalizeL(RReadStream& aStream);
   157 
   158 		/**
   159 		 * Allows a caller to set multiple bits in the bitset
   160 		 * by allowing a variable-length parameter list. 
   161 		 * 
   162 		 * @param aItems	The number of items following in the
   163 		 * 					parameter list.
   164 		 */
   165 		IMPORT_C void SetListL(TInt aItems, ...);
   166 
   167 		/**
   168 		 * Allows a caller to query multiple bits in the bitset.
   169 		 * 
   170 		 * @param aItems	The number of items following in the
   171 		 * 					parameter list.
   172 		 * @return			ETrue if all of the bits specified were set. EFalse if
   173 		 * 					one or more were unset.
   174 		 */
   175 		IMPORT_C TBool IsSetList(TInt aItems, ...) const;
   176 
   177 	private:
   178 		void ConstructL(TInt aMaxId);
   179 		void ConstructL(const CBitset& aSource);
   180 		CBitset();
   181 		CBitset(const CBitset& aSource);
   182 
   183 		/**
   184 		 * Converts from a bit ID to a byte and 
   185 		 * bit within one of the bit-field sets.
   186 		 * 
   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
   190 		 * 						within the byte.
   191 		 */
   192 		void IdentifyBit(TInt aBitId, TInt& aByte, TInt& aBitInByte) const;
   193 		
   194 		/** 
   195 		* Tests whether the bit value is valid for this bitset.
   196 		*
   197 		* @param aAttributeId	The .....
   198 		* @return				ETrue if the bit value is valid for this bitset, EFalse otherwise.
   199 		*/
   200 		inline TBool ValidBit(TInt aAttributeId) const;
   201 		
   202 	private:
   203 		/** The number of bytes required to allow for maxbits */
   204 		TInt iWidth; 
   205 
   206 		/** The maximum number of bits in this bitset */
   207 		TInt iMaxBits;
   208 
   209 		/** The actual set of bits */
   210 		TUint8* iBitSet;
   211 		};
   212 
   213 }
   214 
   215 inline TBool ContentAccess::CBitset::operator!=(const CBitset& aSource) const
   216 	{
   217 	return !operator==(aSource);
   218 	}
   219 
   220 inline TBool ContentAccess::CBitset::ValidBit(TInt aBit) const
   221 	{
   222 	return (aBit >= 0) && (aBit < iMaxBits);
   223 	}
   224 
   225 #endif // REMOVE_CAF1
   226 
   227 #endif // __BITSET_H__