Instances of this class represents objects containing a set of booleans values (flags) that can be accessed by their symbolic name. More...
#include <Flags.hxx>
Public Member Functions | |
virtual | ~Flags () |
The required virtual destructor. | |
const char * | GetClassName () const |
virtual unsigned int | GetNFlags () const |
virtual Component * | Species () const =0 |
Returns a new object of the same class than the receiver object. | |
virtual Component * | DeepCopy () const |
virtual Component * | ShallowCopy () const |
Protected Member Functions | |
Flags (tFlagValue *names) | |
The default constructor. | |
Flags (tFlagValue *names, const Flags< N > &t) | |
The derived copy constructor will use this. | |
template<class T > | |
Flags (tFlagValue *names, const T &t) | |
A lazy way to redefine all unary constructors in bitset by forwarding it. | |
template<class T1 , class T2 > | |
Flags (tFlagValue *names, const T1 &t1, const T2 &t2) | |
A template binary constructor that fordwards to the matching std::bitset. | |
virtual bool | IsSetFlag (unsigned int whichOne) const |
virtual void | SetFlag (unsigned int whichOne, bool value=true) |
Instances of this class represents objects containing a set of booleans values (flags) that can be accessed by their symbolic name.
Because Flags derives from std::bitset<N> it provides all the standard operations like bitwise operators and so. This interface has been fattened to provide symbolic representation (name string) for each flag. If symbolic names for flags are not useful to you, consider use std::bitset instead which has a pure positional approach.
You can acces an individual flag of the Flags object in different ways:
Access by name: | flags.bFlagName |
Access by indexation plus enums: | flags[MyFlagsClass::eFlagName] |
Access by symbol: | flags["FlagName"] |
You can use references this individual flags like any reference to a boolean. Moreover, you can use some extra operations like flip
that inverses the actual value of the flag:
bool isTrue= flags.bFlagName; bool isFalse= ~(flags.bFlagName); flags.bFlagName=true; flags.bFlagName.flip();
Because older versions of this class didn't derive from bitfield, a different interface for a few functions was used. This old interface has the advantage that uses the same function name convention as the rest of the CLAM classes.
CLAMFlags | mtg::Flags | Comments |
Size | size | Returns the number of flags |
NSet | count | Counts the set flags |
Reset | reset | Sets to 0 all the flags |
NFlags | not present | Revise This!!!! |
operator int | operator int | The interface is unchanged but throws a |
The way to define a new Flags type is by subclassing Flags<N>
. The subclass MUST redefine its constructors by providing the Flags constructor an array of tFlagsValue's, which defines the mapping between numeric and symbolic values, and an initialization value, than can be both a symbol (char* or std::string) or an integer.
// MyFlags.hxx class MyFlags : public Flags<5> { // Construction/Destruction public: static tFlagValue sFlagValues[]; static tValue sDefault; virtual Component * Species() const { return new MyFlags(); } typedef enum { eFlag0=0, eFlag1=1, eFlag2=2, eFlag3=3, eFlag4=4 } tFlag; MyFlags () : Flags<5>(sFlagValues), flag0(operator[](eFlag0)), flag1(operator[](eFlag1)), flag2(operator[](eFlag2)), flag3(operator[](eFlag3)), flag4(operator[](eFlag4)) { // The default flag configuration is set here flag4=true; }; MyFlags (const MyFlags& someFlags) : Flags<5>(sFlagValues,someFlags), flag0(operator[](eFlag0)), flag1(operator[](eFlag1)), flag2(operator[](eFlag2)), flag3(operator[](eFlag3)), flag4(operator[](eFlag4)) {}; template <class T> MyFlags(const T &t) : Flags<5>(sFlagValues,t), flag0(operator[](eFlag0)), flag1(operator[](eFlag1)), flag2(operator[](eFlag2)), flag3(operator[](eFlag3)), flag4(operator[](eFlag4)) {}; template <class T1, class T2> MyFlags(const T1 &t1, const T2 &t2) : Flags<5>(sFlagValues,t1,t2), flag0(operator[](eFlag0)), flag1(operator[](eFlag1)), flag2(operator[](eFlag2)), flag3(operator[](eFlag3)), flag4(operator[](eFlag4)) {} reference flag0; reference flag1; reference flag2; reference flag3; reference flag4; };
// MyFlags.cxx Flags<5>::tFlagValue MyFlags::sFlagValues[] = { {MyFlags::eFlag0, "flag0"}, {MyFlags::eFlag1, "flag1"}, {MyFlags::eFlag2, "flag2"}, {MyFlags::eFlag3, "flag3"}, {MyFlags::eFlag4, "flag4"}, {0,NULL} };
Definition at line 251 of file Flags.hxx.
CLAM::Flags< N >::Flags | ( | tFlagValue * | names | ) | [inline, protected] |
CLAM::Flags< N >::Flags | ( | tFlagValue * | names, | |
const Flags< N > & | t | |||
) | [inline, protected] |
CLAM::Flags< N >::Flags | ( | tFlagValue * | names, | |
const T & | t | |||
) | [inline, protected] |
CLAM::Flags< N >::Flags | ( | tFlagValue * | names, | |
const T1 & | t1, | |||
const T2 & | t2 | |||
) | [inline, protected] |
virtual CLAM::Flags< N >::~Flags | ( | ) | [inline, virtual] |
virtual Component* CLAM::Flags< N >::DeepCopy | ( | ) | const [inline, virtual] |
Reimplemented from CLAM::Component.
const char* CLAM::Flags< N >::GetClassName | ( | ) | const [inline, virtual] |
virtual unsigned int CLAM::Flags< N >::GetNFlags | ( | ) | const [inline, virtual] |
Implements CLAM::FlagsBase.
virtual bool CLAM::Flags< N >::IsSetFlag | ( | unsigned int | whichOne | ) | const [inline, protected, virtual] |
Implements CLAM::FlagsBase.
virtual void CLAM::Flags< N >::SetFlag | ( | unsigned int | whichOne, | |
bool | value = true | |||
) | [inline, protected, virtual] |
Implements CLAM::FlagsBase.
virtual Component* CLAM::Flags< N >::ShallowCopy | ( | ) | const [inline, virtual] |
Reimplemented from CLAM::Component.
virtual Component* CLAM::Flags< N >::Species | ( | ) | const [pure virtual] |
Returns a new object of the same class than the receiver object.
To be reimplemented by subclasses.
Implemented in CLAM::SpecTypeFlags.
Referenced by CLAM::Flags< 4 >::DeepCopy(), and CLAM::Flags< 4 >::ShallowCopy().