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