CLAM::Flags< N > Class Template Reference
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>
List of all members.
Detailed Description
template<unsigned int N>
class CLAM::Flags< N >
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.
- Bitwise operators
- Several ways to access to individual flags
- Formated input and output to an std::stream as symbols with the insertion (<<) and extraction (>>) operators
- Implements the Component interface: StoreOn, DeepCopy, ShallowCopy...
- Runtime symbolic representation
- Runtime checking of the values
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.
class MyFlags : public Flags<5> {
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))
{
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;
};
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.
Constructor & Destructor Documentation
The default constructor.
Definition at line 256 of file Flags.hxx.
The derived copy constructor will use this.
Definition at line 262 of file Flags.hxx.
template<unsigned int N>
template<class T >
A lazy way to redefine all unary constructors in bitset by forwarding it.
- See also:
- std::bitset To obtain the complete set of available constructors.
Definition at line 271 of file Flags.hxx.
template<unsigned int N>
template<class T1 , class T2 >
A template binary constructor that fordwards to the matching std::bitset.
<N>
constructor A lazy way to redefine all binary constructors in bitset by forwarding it.
- See also:
- std::bitset To obtain the complete set of available constructors.
Definition at line 282 of file Flags.hxx.
The required virtual destructor.
Definition at line 289 of file Flags.hxx.
Member Function Documentation
template<unsigned int N>
const char* CLAM::Flags< N >::GetClassName |
( |
|
) |
const [inline, virtual] |
The documentation for this class was generated from the following file: