diff -r 666f914201fb -r 2fe1408b6811 epoc32/include/babitflags.h --- a/epoc32/include/babitflags.h Tue Nov 24 13:55:44 2009 +0000 +++ b/epoc32/include/babitflags.h Tue Mar 16 16:12:26 2010 +0000 @@ -1,1 +1,250 @@ -babitflags.h +// Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// 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 +// which accompanies this distribution, and is available +// at the URL "http://www.symbianfoundation.org/legal/licencesv10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// + +#ifndef __BABITFLAGS_H__ +#define __BABITFLAGS_H__ + +// System includes +#include + +/////////////////////////////////////////////////////////////////////////////////////// +// ----> TBitFlagsT (header) +/////////////////////////////////////////////////////////////////////////////////////// +template +class TBitFlagsT +/** +A simple class which manages the process of setting and clearing +flags in an abstract fashion. +@publishedAll +@released +*/ + { +/////////////////////////////////////////////////////////////////////////////////////// +public: // CONSTRUCT +/////////////////////////////////////////////////////////////////////////////////////// + + /** + * Default constructor - initialize all flags to zero + */ + inline TBitFlagsT(); + + /** + * Initialize the whole flag to a certain value + */ + inline TBitFlagsT(T aFlags); + + /** + * Copy constructor - initialize this flag object to mirror + * that of aFlags. + */ + inline TBitFlagsT(const TBitFlagsT& aFlags); + +/////////////////////////////////////////////////////////////////////////////////////// +public: // MANIPULATORS +/////////////////////////////////////////////////////////////////////////////////////// + + /** + * Set all the flags + */ + inline void SetAll(); + + /** + * Clear all the flags + */ + inline void ClearAll(); + + /** + * Set a particular flag + */ + inline void Set(TInt aFlagIndex); + + /** + * Clear a particular flag + */ + inline void Clear(TInt aFlagIndex); + + /** + * Set or clear a particular flag + * + * If aValue is 1, then the flag is set + * If aValue is 0, then the flag is cleared + */ + inline void Assign(TInt aFlagIndex, TBool aValue); + + /** + * Change the state of a particular flag. If the flag at the specified + * index was clear, then it becomes set, otherwise it becomes clear. + */ + inline void Toggle(TInt aFlagIndex); + +/////////////////////////////////////////////////////////////////////////////////////// +public: // OPERATORS +/////////////////////////////////////////////////////////////////////////////////////// + + /** + * Check if a particular flag is set or not + * + * @return A boolean indicating whether the specified flag is set or clear + */ + inline TBool operator[](TInt aFlagIndex) const; + + /** + * Assignment operator - assign specific value to the whole flag, replacing + * any existing value. + */ + inline TBitFlagsT& operator=(const TBitFlagsT& aFlags); + + /** + * Compare the value of the whole flag with a given value. + * + * @return A boolean indicating whether the two flags are identical. + */ + inline TBool operator==(const TBitFlagsT& aFlags); + +/////////////////////////////////////////////////////////////////////////////////////// +public: // ACCESS +/////////////////////////////////////////////////////////////////////////////////////// + + /** + * Check if a particular flag is set + */ + inline TBool IsSet(TInt aFlagIndex) const; + + /** + * Check if a particular flag is clear + */ + inline TBool IsClear(TInt aFlagIndex) const; + + /** + * Access the underlying value of the flag. + */ + inline T Value() const { return iFlags; } + + /** + * Assign a new value (directly) to this flag object. Replaces any + * existing individual flag settings. + */ + inline void SetValue(T aFlags) { iFlags = aFlags; } + +/////////////////////////////////////////////////////////////////////////////////////// +private: // INTERNAL +/////////////////////////////////////////////////////////////////////////////////////// + + /** + * Generate a mask for a particular flag + */ + inline T FlagMask(TInt aFlagIndex) const; + +/////////////////////////////////////////////////////////////////////////////////////// +public: // MEMBER DATA +/////////////////////////////////////////////////////////////////////////////////////// + + // The underlying object container which represents the flags. + T iFlags; + }; + +/** +Type definitions +@publishedAll +@released +*/ +typedef TBitFlagsT TBitFlags8; +// + +/** +Type definitions +@publishedAll +@released +*/ +typedef TBitFlagsT TBitFlags16; +// + +/** +Type definitions +@publishedAll +@released +*/ +typedef TBitFlagsT TBitFlags32; +// + + +typedef TBitFlags32 TBitFlags; + + +/////////////////////////////////////////////////////////////////////////////////////// +// ----> TBitFlagsT (inlines) +/////////////////////////////////////////////////////////////////////////////////////// +template +inline TBitFlagsT::TBitFlagsT() : iFlags(T(0)) + {} + +template +inline TBitFlagsT::TBitFlagsT(T aFlags) : iFlags(aFlags) + {} + +template +inline TBitFlagsT::TBitFlagsT(const TBitFlagsT& aFlags) : iFlags(aFlags.iFlags) + {} + +template +inline T TBitFlagsT::FlagMask(TInt aFlagIndex) const + { return T(T(1)< +inline TBool TBitFlagsT::IsSet(TInt aFlagIndex) const + { return iFlags & FlagMask(aFlagIndex); } + +template +inline TBool TBitFlagsT::IsClear(TInt aFlagIndex) const + { return !IsSet(aFlagIndex); } + +template +inline void TBitFlagsT::Set(TInt aFlagIndex) + { iFlags = T(iFlags | FlagMask(aFlagIndex)); } + +template +inline void TBitFlagsT::Clear(TInt aFlagIndex) + { iFlags = T(iFlags & ~(FlagMask(aFlagIndex))); } + +template +inline void TBitFlagsT::Assign(TInt aFlagIndex, TBool aVal) + { if (aVal) Set(aFlagIndex); else Clear(aFlagIndex); } + +template +inline void TBitFlagsT::Toggle(TInt aFlagIndex) + { iFlags = T(iFlags^FlagMask(aFlagIndex)); } + +template +inline TBool TBitFlagsT::operator[](TInt aFlagIndex) const + { return IsSet(aFlagIndex); } + +template +inline TBitFlagsT& TBitFlagsT::operator=(const TBitFlagsT& aFlags) + { iFlags = aFlags.iFlags; return *this; } + +template +inline TBool TBitFlagsT::operator==(const TBitFlagsT& aFlags) + { return iFlags == aFlags.Value(); } + +template +inline void TBitFlagsT::SetAll() + { iFlags = T(~(T(0))); } + +template +inline void TBitFlagsT::ClearAll() + { iFlags = T(0); } + + +#endif