GG
Public Types | Static Public Member Functions | List of all members
GG::FlagSpec< FlagType > Class Template Reference

#include <Flags.h>

Public Types

typedef std::set< FlagType >
::iterator 
iterator
 
typedef std::set< FlagType >
::const_iterator 
const_iterator
 

Static Public Member Functions

static FlagSpecinstance ()
 

Exceptions

 GG_ABSTRACT_EXCEPTION (Exception)
 
 GG_CONCRETE_EXCEPTION (UnknownFlag, GG::FlagSpec, Exception)
 
 GG_CONCRETE_EXCEPTION (UnknownString, GG::FlagSpec, Exception)
 

Accessors

bool contains (FlagType flag) const
 
bool permanent (FlagType flag) const
 
const_iterator find (FlagType flag) const
 
const_iterator begin () const
 
const_iterator end () const
 
const std::string & ToString (FlagType flag) const
 
FlagType FromString (const std::string &str) const
 

Mutators

void insert (FlagType flag, const std::string &name, bool permanent=false)
 
bool erase (FlagType flag)
 

Detailed Description

template<class FlagType>
class GG::FlagSpec< FlagType >

A singleton that encapsulates the set of known flags of type FlagType.

New user-defined flags must be registered with FlagSpec in order to be used in Flags objects for operator~ to work properly with flags of type FlagType. FlagSpec is designed to be extensible. That is, it is understood that the flags used by GG may be insufficient for all subclasses that users may write, and FlagSpec allows authors of GG-derived classes to add flags. For instance, a subclass of Wnd may want to add a MINIMIZABLE flag. Doing so is as simple as declaring it and registering it with

FlagSpec<WndFlag>::instance.insert(MINIMIZABLE,
"MINIMIZABLE") 

. If user-defined subclasses and their associated user-defined flags are loaded in a runtime-loaded library, users should take care to erase them from the FlagSpec when the library is unloaded.

Note
All user-instantiated FlagSpecs must provide their own implementations of the instance() static function (all the GG-provided FlagSpec instantiations provide such implementations already).

Definition at line 149 of file Flags.h.

Member Typedef Documentation

template<class FlagType>
typedef std::set<FlagType>::iterator GG::FlagSpec< FlagType >::iterator

Iterator over all known flags.

Definition at line 159 of file Flags.h.

template<class FlagType>
typedef std::set<FlagType>::const_iterator GG::FlagSpec< FlagType >::const_iterator

Const iterator over all known flags.

Definition at line 161 of file Flags.h.

Member Function Documentation

template<class FlagType>
GG::FlagSpec< FlagType >::GG_ABSTRACT_EXCEPTION ( Exception  )

The base class for FlagSpec exceptions.

template<class FlagType>
GG::FlagSpec< FlagType >::GG_CONCRETE_EXCEPTION ( UnknownFlag  ,
GG::FlagSpec< FlagType >  ,
Exception   
)

Thrown when a flag-to-string conversion is requested for an unknown flag.

template<class FlagType>
GG::FlagSpec< FlagType >::GG_CONCRETE_EXCEPTION ( UnknownString  ,
GG::FlagSpec< FlagType >  ,
Exception   
)

Thrown when a string-to-flag conversion is requested for an unknown string.

template<class FlagType>
static FlagSpec& GG::FlagSpec< FlagType >::instance ( )
static

Returns the singelton instance of this class.

Referenced by GG::operator~().

template<class FlagType>
bool GG::FlagSpec< FlagType >::contains ( FlagType  flag) const
inline

Returns true iff FlagSpec contains flag.

Definition at line 179 of file Flags.h.

template<class FlagType>
bool GG::FlagSpec< FlagType >::permanent ( FlagType  flag) const
inline

Returns true iff flag is a "permanent" flag – a flag used internally by the GG library, as opposed to a user-added flag.

Definition at line 183 of file Flags.h.

template<class FlagType>
const_iterator GG::FlagSpec< FlagType >::find ( FlagType  flag) const
inline

Returns an iterator to flag, if flag is in the FlagSpec, or end() otherwise.

Definition at line 187 of file Flags.h.

template<class FlagType>
const_iterator GG::FlagSpec< FlagType >::begin ( ) const
inline

Returns an iterator to the first flag in the FlagSpec.

Definition at line 190 of file Flags.h.

Referenced by GG::operator~().

template<class FlagType>
const_iterator GG::FlagSpec< FlagType >::end ( ) const
inline

Returns an iterator to one past the last flag in the FlagSpec.

Definition at line 193 of file Flags.h.

Referenced by GG::operator~().

template<class FlagType>
const std::string& GG::FlagSpec< FlagType >::ToString ( FlagType  flag) const
inline

Returns the stringification of flag provided when flag was added to the FlagSpec.

Exceptions
ThrowsGG::FlagSpec::UnknownFlag if an unknown flag's stringification is requested.

Definition at line 198 of file Flags.h.

template<class FlagType>
FlagType GG::FlagSpec< FlagType >::FromString ( const std::string &  str) const
inline

Returns the flag whose stringification is str.

Exceptions
ThrowsGG::FlagSpec::UnknownString if an unknown string is provided.

Definition at line 207 of file Flags.h.

template<class FlagType>
void GG::FlagSpec< FlagType >::insert ( FlagType  flag,
const std::string &  name,
bool  permanent = false 
)
inline

Adds flag, with stringification string name, to the FlagSpec. If permanent is true, this flag becomes non-removable. Alls flags added by GG are added as permanent flags. User-added flags should not be added as permanent.

Definition at line 225 of file Flags.h.

template<class FlagType>
bool GG::FlagSpec< FlagType >::erase ( FlagType  flag)
inline

Removes flag from the FlagSpec, returning whether the flag was actually removed or not. Permanent flags are not removed. The removal of flags will probably only be necessary in cases where flags were added for classes in a runtime-loaded DLL/shared library at DLL/shared library unload-time.

Definition at line 241 of file Flags.h.


The documentation for this class was generated from the following file: