1.1 --- a/epoc32/include/babitflags.h Tue Nov 24 13:55:44 2009 +0000
1.2 +++ b/epoc32/include/babitflags.h Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -1,1 +1,250 @@
1.4 -babitflags.h
1.5 +// Copyright (c) 1999-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 "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
1.9 +// which accompanies this distribution, and is available
1.10 +// at the URL "http://www.symbianfoundation.org/legal/licencesv10.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 +#ifndef __BABITFLAGS_H__
1.21 +#define __BABITFLAGS_H__
1.22 +
1.23 +// System includes
1.24 +#include <e32std.h>
1.25 +
1.26 +///////////////////////////////////////////////////////////////////////////////////////
1.27 +// ----> TBitFlagsT (header)
1.28 +///////////////////////////////////////////////////////////////////////////////////////
1.29 +template <class T>
1.30 +class TBitFlagsT
1.31 +/**
1.32 +A simple class which manages the process of setting and clearing
1.33 +flags in an abstract fashion.
1.34 +@publishedAll
1.35 +@released
1.36 +*/
1.37 + {
1.38 +///////////////////////////////////////////////////////////////////////////////////////
1.39 +public: // CONSTRUCT
1.40 +///////////////////////////////////////////////////////////////////////////////////////
1.41 +
1.42 + /**
1.43 + * Default constructor - initialize all flags to zero
1.44 + */
1.45 + inline TBitFlagsT();
1.46 +
1.47 + /**
1.48 + * Initialize the whole flag to a certain value
1.49 + */
1.50 + inline TBitFlagsT(T aFlags);
1.51 +
1.52 + /**
1.53 + * Copy constructor - initialize this flag object to mirror
1.54 + * that of aFlags.
1.55 + */
1.56 + inline TBitFlagsT(const TBitFlagsT& aFlags);
1.57 +
1.58 +///////////////////////////////////////////////////////////////////////////////////////
1.59 +public: // MANIPULATORS
1.60 +///////////////////////////////////////////////////////////////////////////////////////
1.61 +
1.62 + /**
1.63 + * Set all the flags
1.64 + */
1.65 + inline void SetAll();
1.66 +
1.67 + /**
1.68 + * Clear all the flags
1.69 + */
1.70 + inline void ClearAll();
1.71 +
1.72 + /**
1.73 + * Set a particular flag
1.74 + */
1.75 + inline void Set(TInt aFlagIndex);
1.76 +
1.77 + /**
1.78 + * Clear a particular flag
1.79 + */
1.80 + inline void Clear(TInt aFlagIndex);
1.81 +
1.82 + /**
1.83 + * Set or clear a particular flag
1.84 + *
1.85 + * If aValue is 1, then the flag is set
1.86 + * If aValue is 0, then the flag is cleared
1.87 + */
1.88 + inline void Assign(TInt aFlagIndex, TBool aValue);
1.89 +
1.90 + /**
1.91 + * Change the state of a particular flag. If the flag at the specified
1.92 + * index was clear, then it becomes set, otherwise it becomes clear.
1.93 + */
1.94 + inline void Toggle(TInt aFlagIndex);
1.95 +
1.96 +///////////////////////////////////////////////////////////////////////////////////////
1.97 +public: // OPERATORS
1.98 +///////////////////////////////////////////////////////////////////////////////////////
1.99 +
1.100 + /**
1.101 + * Check if a particular flag is set or not
1.102 + *
1.103 + * @return A boolean indicating whether the specified flag is set or clear
1.104 + */
1.105 + inline TBool operator[](TInt aFlagIndex) const;
1.106 +
1.107 + /**
1.108 + * Assignment operator - assign specific value to the whole flag, replacing
1.109 + * any existing value.
1.110 + */
1.111 + inline TBitFlagsT& operator=(const TBitFlagsT& aFlags);
1.112 +
1.113 + /**
1.114 + * Compare the value of the whole flag with a given value.
1.115 + *
1.116 + * @return A boolean indicating whether the two flags are identical.
1.117 + */
1.118 + inline TBool operator==(const TBitFlagsT& aFlags);
1.119 +
1.120 +///////////////////////////////////////////////////////////////////////////////////////
1.121 +public: // ACCESS
1.122 +///////////////////////////////////////////////////////////////////////////////////////
1.123 +
1.124 + /**
1.125 + * Check if a particular flag is set
1.126 + */
1.127 + inline TBool IsSet(TInt aFlagIndex) const;
1.128 +
1.129 + /**
1.130 + * Check if a particular flag is clear
1.131 + */
1.132 + inline TBool IsClear(TInt aFlagIndex) const;
1.133 +
1.134 + /**
1.135 + * Access the underlying value of the flag.
1.136 + */
1.137 + inline T Value() const { return iFlags; }
1.138 +
1.139 + /**
1.140 + * Assign a new value (directly) to this flag object. Replaces any
1.141 + * existing individual flag settings.
1.142 + */
1.143 + inline void SetValue(T aFlags) { iFlags = aFlags; }
1.144 +
1.145 +///////////////////////////////////////////////////////////////////////////////////////
1.146 +private: // INTERNAL
1.147 +///////////////////////////////////////////////////////////////////////////////////////
1.148 +
1.149 + /**
1.150 + * Generate a mask for a particular flag
1.151 + */
1.152 + inline T FlagMask(TInt aFlagIndex) const;
1.153 +
1.154 +///////////////////////////////////////////////////////////////////////////////////////
1.155 +public: // MEMBER DATA
1.156 +///////////////////////////////////////////////////////////////////////////////////////
1.157 +
1.158 + // The underlying object container which represents the flags.
1.159 + T iFlags;
1.160 + };
1.161 +
1.162 +/**
1.163 +Type definitions
1.164 +@publishedAll
1.165 +@released
1.166 +*/
1.167 +typedef TBitFlagsT<TUint8> TBitFlags8;
1.168 +//
1.169 +
1.170 +/**
1.171 +Type definitions
1.172 +@publishedAll
1.173 +@released
1.174 +*/
1.175 +typedef TBitFlagsT<TUint16> TBitFlags16;
1.176 +//
1.177 +
1.178 +/**
1.179 +Type definitions
1.180 +@publishedAll
1.181 +@released
1.182 +*/
1.183 +typedef TBitFlagsT<TUint32> TBitFlags32;
1.184 +//
1.185 +
1.186 +
1.187 +typedef TBitFlags32 TBitFlags;
1.188 +
1.189 +
1.190 +///////////////////////////////////////////////////////////////////////////////////////
1.191 +// ----> TBitFlagsT (inlines)
1.192 +///////////////////////////////////////////////////////////////////////////////////////
1.193 +template <class T>
1.194 +inline TBitFlagsT<T>::TBitFlagsT() : iFlags(T(0))
1.195 + {}
1.196 +
1.197 +template <class T>
1.198 +inline TBitFlagsT<T>::TBitFlagsT(T aFlags) : iFlags(aFlags)
1.199 + {}
1.200 +
1.201 +template <class T>
1.202 +inline TBitFlagsT<T>::TBitFlagsT(const TBitFlagsT<T>& aFlags) : iFlags(aFlags.iFlags)
1.203 + {}
1.204 +
1.205 +template <class T>
1.206 +inline T TBitFlagsT<T>::FlagMask(TInt aFlagIndex) const
1.207 + { return T(T(1)<<aFlagIndex); }
1.208 +
1.209 +template <class T>
1.210 +inline TBool TBitFlagsT<T>::IsSet(TInt aFlagIndex) const
1.211 + { return iFlags & FlagMask(aFlagIndex); }
1.212 +
1.213 +template <class T>
1.214 +inline TBool TBitFlagsT<T>::IsClear(TInt aFlagIndex) const
1.215 + { return !IsSet(aFlagIndex); }
1.216 +
1.217 +template <class T>
1.218 +inline void TBitFlagsT<T>::Set(TInt aFlagIndex)
1.219 + { iFlags = T(iFlags | FlagMask(aFlagIndex)); }
1.220 +
1.221 +template <class T>
1.222 +inline void TBitFlagsT<T>::Clear(TInt aFlagIndex)
1.223 + { iFlags = T(iFlags & ~(FlagMask(aFlagIndex))); }
1.224 +
1.225 +template <class T>
1.226 +inline void TBitFlagsT<T>::Assign(TInt aFlagIndex, TBool aVal)
1.227 + { if (aVal) Set(aFlagIndex); else Clear(aFlagIndex); }
1.228 +
1.229 +template <class T>
1.230 +inline void TBitFlagsT<T>::Toggle(TInt aFlagIndex)
1.231 + { iFlags = T(iFlags^FlagMask(aFlagIndex)); }
1.232 +
1.233 +template <class T>
1.234 +inline TBool TBitFlagsT<T>::operator[](TInt aFlagIndex) const
1.235 + { return IsSet(aFlagIndex); }
1.236 +
1.237 +template <class T>
1.238 +inline TBitFlagsT<T>& TBitFlagsT<T>::operator=(const TBitFlagsT<T>& aFlags)
1.239 + { iFlags = aFlags.iFlags; return *this; }
1.240 +
1.241 +template <class T>
1.242 +inline TBool TBitFlagsT<T>::operator==(const TBitFlagsT<T>& aFlags)
1.243 + { return iFlags == aFlags.Value(); }
1.244 +
1.245 +template <class T>
1.246 +inline void TBitFlagsT<T>::SetAll()
1.247 + { iFlags = T(~(T(0))); }
1.248 +
1.249 +template <class T>
1.250 +inline void TBitFlagsT<T>::ClearAll()
1.251 + { iFlags = T(0); }
1.252 +
1.253 +
1.254 +#endif