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.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
/**
sl@0
    20
 @file
sl@0
    21
 @publishedPartner
sl@0
    22
 @deprecated
sl@0
    23
*/
sl@0
    24
sl@0
    25
#ifndef __BITSET_H__
sl@0
    26
#define __BITSET_H__
sl@0
    27
sl@0
    28
#ifndef REMOVE_CAF1
sl@0
    29
sl@0
    30
#include <e32base.h>
sl@0
    31
#include <caf/caftypes.h>
sl@0
    32
sl@0
    33
class RWriteStream;
sl@0
    34
class RReadStream;
sl@0
    35
sl@0
    36
namespace ContentAccess
sl@0
    37
{
sl@0
    38
	
sl@0
    39
	/** @deprecated */
sl@0
    40
	enum TCafUtilsPanics
sl@0
    41
		{
sl@0
    42
		EInvalidBit
sl@0
    43
		};
sl@0
    44
sl@0
    45
	_LIT(KCafUtilsPanic, "CafUtils");
sl@0
    46
sl@0
    47
	/**
sl@0
    48
	 * A container of bits. 
sl@0
    49
	 * 
sl@0
    50
	 * The bits may be retrieved, set, and unset.
sl@0
    51
	 *
sl@0
    52
	 * @publishedPartner
sl@0
    53
	 * @deprecated 
sl@0
    54
	 */
sl@0
    55
	class CBitset : public CBase
sl@0
    56
		{
sl@0
    57
	public:
sl@0
    58
		/**
sl@0
    59
		 * Constructs a new bitset object with a maximum number of bits.
sl@0
    60
		 * 
sl@0
    61
		 * @param aMaxBits	The maximum number of bits this object may contain.
sl@0
    62
		 */
sl@0
    63
		IMPORT_C static CBitset* NewL(TInt aMaxBits);
sl@0
    64
sl@0
    65
		/** @see CBitset::NewL(TInt aMaxBits) */
sl@0
    66
		IMPORT_C static CBitset* NewLC(TInt aMaxBits);
sl@0
    67
		
sl@0
    68
		/** 
sl@0
    69
		 * Copy constructor
sl@0
    70
		 *
sl@0
    71
		 * @param aSource	The object to be copied from.
sl@0
    72
		 */
sl@0
    73
		IMPORT_C static CBitset* NewL(const CBitset& aSource);
sl@0
    74
sl@0
    75
		/** @see CBitset::NewL(const CBitset& aSource) */
sl@0
    76
		IMPORT_C static CBitset* NewLC(const CBitset& aSource);
sl@0
    77
sl@0
    78
		virtual ~CBitset();
sl@0
    79
sl@0
    80
	public:
sl@0
    81
		/** Resets the entire bitset to zero. */
sl@0
    82
		IMPORT_C void Reset();
sl@0
    83
sl@0
    84
		/** Gets the maximum number of settable/gettable bits. */
sl@0
    85
		IMPORT_C TInt MaxBits() const;
sl@0
    86
sl@0
    87
		/** Sets all bits in the set to one. */
sl@0
    88
		IMPORT_C void SetAll();
sl@0
    89
sl@0
    90
		/** Inverts all bits in the set. */
sl@0
    91
		IMPORT_C void Invert();
sl@0
    92
		
sl@0
    93
		/** Sets the 'aBit'th bit of the set. 
sl@0
    94
		* @param aBit the bit to set 
sl@0
    95
		* @panic CafUtils 0 if aBit is out of range
sl@0
    96
		*/
sl@0
    97
		IMPORT_C void Set(TInt aBit);
sl@0
    98
sl@0
    99
		/** Clears the 'aBit'th bit of the set. 
sl@0
   100
		* @param aBit the bit to clear
sl@0
   101
		* @panic CafUtils 0 if aBit is out of range
sl@0
   102
		*/
sl@0
   103
		IMPORT_C void Unset(TInt aBit);
sl@0
   104
		
sl@0
   105
		/** 
sl@0
   106
		 * Queries the single bit of the set.
sl@0
   107
		 * 
sl@0
   108
		 * @param aBit	The bit that requires testing.
sl@0
   109
		 * @return		ETrue if the bit was set, EFalse otherwise.
sl@0
   110
 		 * @panic CafUtils 0 if aBit is out of range
sl@0
   111
		 * 
sl@0
   112
		 */
sl@0
   113
		IMPORT_C TBool IsSet(TInt aBit) const;
sl@0
   114
sl@0
   115
		/** 
sl@0
   116
		 * Assignment of a bitset. 
sl@0
   117
		 * 
sl@0
   118
		 * Note that an assignment of a longer bitset to a
sl@0
   119
		 * shorter bitset will result in the shorter bitset
sl@0
   120
		 * being expanded. This function may leave.
sl@0
   121
		 *
sl@0
   122
		 * @param aSource	The bitset ......
sl@0
   123
		 * @return			A bitset.
sl@0
   124
		 */
sl@0
   125
		IMPORT_C CBitset& operator=(const CBitset& aSource);
sl@0
   126
sl@0
   127
		/**
sl@0
   128
		 * Allows comparisons of CBitsets. 
sl@0
   129
		 * 
sl@0
   130
		 * Note that it is possible to compare a longer
sl@0
   131
		 * bitset with a shorter one. However, only the 
sl@0
   132
		 * relevant (low-order) bits are compared.
sl@0
   133
		 *
sl@0
   134
		 * @param aSource	The bitset .....
sl@0
   135
		 * @return			ETrue if the ....., EFalse otherwise.
sl@0
   136
		 */
sl@0
   137
		IMPORT_C TBool operator==(const CBitset& aSource) const;
sl@0
   138
		inline TBool operator!=(const CBitset& aSource) const;
sl@0
   139
sl@0
   140
		/** 
sl@0
   141
		 * Externalisation function that allows this object to be
sl@0
   142
		 * marshalled prior to being shipped over a client-server
sl@0
   143
		 * interface by related glue-code.
sl@0
   144
		 *
sl@0
   145
		 * @param aStream	On return, the .....
sl@0
   146
		 */
sl@0
   147
		IMPORT_C void ExternalizeL(RWriteStream& aStream) const;
sl@0
   148
		
sl@0
   149
		/**
sl@0
   150
		 * Internalisation function that allows this object to to be
sl@0
   151
		 * unmarshalled after transfer across a client-server
sl@0
   152
		 * interface. 
sl@0
   153
		 *
sl@0
   154
		 * @param aStream	On return, the .....
sl@0
   155
		 */
sl@0
   156
		IMPORT_C void InternalizeL(RReadStream& aStream);
sl@0
   157
sl@0
   158
		/**
sl@0
   159
		 * Allows a caller to set multiple bits in the bitset
sl@0
   160
		 * by allowing a variable-length parameter list. 
sl@0
   161
		 * 
sl@0
   162
		 * @param aItems	The number of items following in the
sl@0
   163
		 * 					parameter list.
sl@0
   164
		 */
sl@0
   165
		IMPORT_C void SetListL(TInt aItems, ...);
sl@0
   166
sl@0
   167
		/**
sl@0
   168
		 * Allows a caller to query multiple bits in the bitset.
sl@0
   169
		 * 
sl@0
   170
		 * @param aItems	The number of items following in the
sl@0
   171
		 * 					parameter list.
sl@0
   172
		 * @return			ETrue if all of the bits specified were set. EFalse if
sl@0
   173
		 * 					one or more were unset.
sl@0
   174
		 */
sl@0
   175
		IMPORT_C TBool IsSetList(TInt aItems, ...) const;
sl@0
   176
sl@0
   177
	private:
sl@0
   178
		void ConstructL(TInt aMaxId);
sl@0
   179
		void ConstructL(const CBitset& aSource);
sl@0
   180
		CBitset();
sl@0
   181
		CBitset(const CBitset& aSource);
sl@0
   182
sl@0
   183
		/**
sl@0
   184
		 * Converts from a bit ID to a byte and 
sl@0
   185
		 * bit within one of the bit-field sets.
sl@0
   186
		 * 
sl@0
   187
		 * @param aBitId		The bit ID being mapped.
sl@0
   188
		 * @param aByte			Modified to contain the resultant byte number.
sl@0
   189
		 * @param aBitInByte	Modified to contain the resultant bit number
sl@0
   190
		 * 						within the byte.
sl@0
   191
		 */
sl@0
   192
		void IdentifyBit(TInt aBitId, TInt& aByte, TInt& aBitInByte) const;
sl@0
   193
		
sl@0
   194
		/** 
sl@0
   195
		* Tests whether the bit value is valid for this bitset.
sl@0
   196
		*
sl@0
   197
		* @param aAttributeId	The .....
sl@0
   198
		* @return				ETrue if the bit value is valid for this bitset, EFalse otherwise.
sl@0
   199
		*/
sl@0
   200
		inline TBool ValidBit(TInt aAttributeId) const;
sl@0
   201
		
sl@0
   202
	private:
sl@0
   203
		/** The number of bytes required to allow for maxbits */
sl@0
   204
		TInt iWidth; 
sl@0
   205
sl@0
   206
		/** The maximum number of bits in this bitset */
sl@0
   207
		TInt iMaxBits;
sl@0
   208
sl@0
   209
		/** The actual set of bits */
sl@0
   210
		TUint8* iBitSet;
sl@0
   211
		};
sl@0
   212
sl@0
   213
}
sl@0
   214
sl@0
   215
inline TBool ContentAccess::CBitset::operator!=(const CBitset& aSource) const
sl@0
   216
	{
sl@0
   217
	return !operator==(aSource);
sl@0
   218
	}
sl@0
   219
sl@0
   220
inline TBool ContentAccess::CBitset::ValidBit(TInt aBit) const
sl@0
   221
	{
sl@0
   222
	return (aBit >= 0) && (aBit < iMaxBits);
sl@0
   223
	}
sl@0
   224
sl@0
   225
#endif // REMOVE_CAF1
sl@0
   226
sl@0
   227
#endif // __BITSET_H__