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.

Public Member Functions

virtual ~Flags ()
 The required virtual destructor.
const char * GetClassName () const
virtual unsigned int GetNFlags () const
virtual ComponentSpecies () const =0
 Returns a new object of the same class than the receiver object.
virtual ComponentDeepCopy () const
virtual ComponentShallowCopy () 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)

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.

Accessing individual flags

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();

Bitwise operations

Non Standard operations

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.

CLAMFlagsmtg::FlagsComments
SizesizeReturns the number of flags
NSetcountCounts the set flags
ResetresetSets to 0 all the flags
NFlagsnot presentRevise This!!!!
operator intoperator intThe interface is unchanged but throws a

Creating your own flags

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.


Constructor & Destructor Documentation

template<unsigned int N>
CLAM::Flags< N >::Flags ( tFlagValue names  )  [inline, protected]

The default constructor.

Definition at line 256 of file Flags.hxx.

template<unsigned int N>
CLAM::Flags< N >::Flags ( tFlagValue names,
const Flags< N > &  t 
) [inline, protected]

The derived copy constructor will use this.

Definition at line 262 of file Flags.hxx.

template<unsigned int N>
template<class T >
CLAM::Flags< N >::Flags ( tFlagValue names,
const T &  t 
) [inline, protected]

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 >
CLAM::Flags< N >::Flags ( tFlagValue names,
const T1 &  t1,
const T2 &  t2 
) [inline, protected]

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.

template<unsigned int N>
virtual CLAM::Flags< N >::~Flags (  )  [inline, virtual]

The required virtual destructor.

Definition at line 289 of file Flags.hxx.


Member Function Documentation

template<unsigned int N>
virtual Component* CLAM::Flags< N >::DeepCopy (  )  const [inline, virtual]

Reimplemented from CLAM::Component.

Definition at line 317 of file Flags.hxx.

template<unsigned int N>
const char* CLAM::Flags< N >::GetClassName (  )  const [inline, virtual]
Todo:
GetClassName for Flags

Implements CLAM::Component.

Definition at line 292 of file Flags.hxx.

template<unsigned int N>
virtual unsigned int CLAM::Flags< N >::GetNFlags (  )  const [inline, virtual]
Returns:
the number of flags contained

Implements CLAM::FlagsBase.

Definition at line 296 of file Flags.hxx.

template<unsigned int N>
virtual bool CLAM::Flags< N >::IsSetFlag ( unsigned int  whichOne  )  const [inline, protected, virtual]

Implements CLAM::FlagsBase.

Definition at line 300 of file Flags.hxx.

template<unsigned int N>
virtual void CLAM::Flags< N >::SetFlag ( unsigned int  whichOne,
bool  value = true 
) [inline, protected, virtual]

Implements CLAM::FlagsBase.

Definition at line 303 of file Flags.hxx.

template<unsigned int N>
virtual Component* CLAM::Flags< N >::ShallowCopy (  )  const [inline, virtual]

Reimplemented from CLAM::Component.

Definition at line 323 of file Flags.hxx.

template<unsigned int N>
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.

Returns:
a new allocated component. The pointer belongs to the caller.

Implemented in CLAM::SpecTypeFlags.

Referenced by CLAM::Flags< 4 >::DeepCopy(), and CLAM::Flags< 4 >::ShallowCopy().


The documentation for this class was generated from the following file:
Generated by  doxygen 1.6.3