CLAM-Development  1.4.0
Classes | Public Types | Public Member Functions
CLAM::Enum Class Reference

Instances of this class represents objects that can adquire a symbolic value from a limited set of symbolic values. More...

#include <Enum.hxx>

List of all members.

Classes

struct  tEnumValue

Public Types

typedef int tValue

Public Member Functions

const tEnumValueGetSymbolMap () const
 Returns the symbol map for the enum.
void SetValue (const tValue v)
 Changes the value.
void SetValueSafely (const tValue v) throw (IllegalValue)
 Changes the value safely.
void SetValue (const std::string &s)
 Changes the value.
void SetValueSafely (const std::string &s) throw (IllegalValue)
tValue GetValue () const
 Returns the numeric value.
std::string GetString () const throw (IllegalValue)
 Returns the symbolic value.
Enumoperator= (const tValue &v) throw (IllegalValue)
Enumoperator= (const std::string &v) throw (IllegalValue)
Enumoperator= (const Enum &v) throw (IllegalValue)
 operator tValue () const
 Conversion operiation as a number.
virtual ComponentSpecies () const =0
 Returns a new object of the same class than the receiver object.
virtual ComponentDeepCopy () const
 TODO: Copy documentation for this method from Component.
virtual ComponentShallowCopy () const
 TODO: Copy documentation for this method from Component.
virtual void StoreOn (Storage &storage) const
 Stores component's subitems on the given Storage.
virtual void LoadFrom (Storage &storage)
 Loads component's subitems from the given Storage.
- Public Member Functions inherited from CLAM::Component
virtual ~Component ()

Construction/Destruction

 Enum (const tEnumValue *values, const tValue &value)
 Construction with a numeric value.
 Enum (const tEnumValue *values, const std::string &value)
 Construction with a symbolic value.
virtual ~Enum ()
 The required virtual destructor.
const char * GetClassName () const
 Return the class name.

Additional Inherited Members


Detailed Description

Instances of this class represents objects that can adquire a symbolic value from a limited set of symbolic values.

Enum provides more features that the C enum with a very little overhead:

The way to define an enumerated type is by subclassing Enum.

The subclass MUST redefine its constructors by providing the Enum constructor an array of tEnumValue'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.

// EMyEnum.hxx
class EMyEnum : public CLAM::Enum {
public:
EMyEnum() : CLAM::Enum(ValueTable(), eTwo) {}
EMyEnum(tValue v) : CLAM::Enum(ValueTable(), v) {};
EMyEnum(const std::string & s) : CLAM::Enum(ValueTable(), s) {};
virtual CLAM::Component * Species() const {return new EMyEnum();}
typedef enum {
eZero=0,
eTwo=2,
eHundred=100
} tEnum;
static tEnumValue * ValueTable()
{
static tEnumValue sValueTable[] =
{
{eZero,"zero"},
{eTwo,"two"},
{eHundred,"hundred"},
{0,NULL}
};
return sValueTable;
}
};

Definition at line 93 of file Enum.hxx.


Member Typedef Documentation

Definition at line 97 of file Enum.hxx.


Constructor & Destructor Documentation

CLAM::Enum::Enum ( const tEnumValue values,
const tValue value 
)
inlineprotected

Construction with a numeric value.

Parameters:
valuesAn array of tEnumValue structures in wich the last one has a NULL pointer as name.
valueAn initialization numeric value.
Exceptions:
AIllegalValue exception when the value is not valid.

Definition at line 116 of file Enum.hxx.

References SetValue().

CLAM::Enum::Enum ( const tEnumValue values,
const std::string &  value 
)
inlineprotected

Construction with a symbolic value.

Parameters:
valuesAn array of tEnumValue structures in wich the last one has a NULL pointer as name.
valueAn initialization symbolic value.
Exceptions:
AIllegalValue exception when the value is not valid.

Definition at line 127 of file Enum.hxx.

References SetValue().

CLAM::Enum::~Enum ( )
virtual

The required virtual destructor.

Definition at line 29 of file Enum.cxx.


Member Function Documentation

virtual Component* CLAM::Enum::DeepCopy ( ) const
inlinevirtual

TODO: Copy documentation for this method from Component.

Reimplemented from CLAM::Component.

Definition at line 272 of file Enum.hxx.

References SetValue(), and Species().

const char* CLAM::Enum::GetClassName ( ) const
inlinevirtual

Return the class name.

Implements CLAM::Component.

Definition at line 134 of file Enum.hxx.

References NULL.

std::string CLAM::Enum::GetString ( ) const throw (IllegalValue)
inline

Returns the symbolic value.

Returns:
The symbolic value

Definition at line 226 of file Enum.hxx.

References CLAM_ASSERT, and CLAM::Enum::tEnumValue::name.

Referenced by StoreOn().

const tEnumValue* CLAM::Enum::GetSymbolMap ( ) const
inline

Returns the symbol map for the enum.

Definition at line 142 of file Enum.hxx.

tValue CLAM::Enum::GetValue ( ) const
inline

Returns the numeric value.

Returns:
The numeric value

Definition at line 218 of file Enum.hxx.

void CLAM::Enum::LoadFrom ( Storage storage)
virtual

Loads component's subitems from the given Storage.

Parameters:
storageThe given storage where the subitem will be stored
See also:
Storage TODO: This method can throw and IllegalValue exception

Implements CLAM::Component.

Definition at line 40 of file Enum.cxx.

References CLAM::Storage::Load(), and SetValueSafely().

CLAM::Enum::operator tValue ( ) const
inline

Conversion operiation as a number.

Returns:
The numeric value

Definition at line 255 of file Enum.hxx.

Enum& CLAM::Enum::operator= ( const tValue v) throw (IllegalValue)
inline

Definition at line 236 of file Enum.hxx.

References SetValue().

Enum& CLAM::Enum::operator= ( const std::string &  v) throw (IllegalValue)
inline

Definition at line 241 of file Enum.hxx.

References SetValue().

Enum& CLAM::Enum::operator= ( const Enum v) throw (IllegalValue)
inline

Definition at line 246 of file Enum.hxx.

References SetValue().

void CLAM::Enum::SetValue ( const tValue  v)
inline

Changes the value.

Parameters:
vThe new numeric value

Definition at line 150 of file Enum.hxx.

References CLAM_ASSERT, CLAM_BEGIN_DEBUG_CHECK, CLAM_END_DEBUG_CHECK, and CLAM::Enum::tEnumValue::name.

Referenced by DeepCopy(), Enum(), operator=(), and ShallowCopy().

void CLAM::Enum::SetValue ( const std::string &  s)
inline

Changes the value.

Parameters:
sThe new symbolic value

Definition at line 184 of file Enum.hxx.

References CLAM_ASSERT, CLAM::Enum::tEnumValue::name, and CLAM::Enum::tEnumValue::value.

void CLAM::Enum::SetValueSafely ( const tValue  v) throw (IllegalValue)
inline

Changes the value safely.

That is it checks the value is ok for the enum and throws a catchable exception if not.

Parameters:
vThe new numeric value
Exceptions:
IllegalValuewhen the value is not valid for the enum
Todo:
Fill IllegalValue with useful information to recover instead a insightfull string.

Definition at line 171 of file Enum.hxx.

References CLAM::Enum::tEnumValue::name.

Referenced by LoadFrom().

void CLAM::Enum::SetValueSafely ( const std::string &  s) throw (IllegalValue)
inline

Definition at line 203 of file Enum.hxx.

References CLAM::Enum::tEnumValue::name, and CLAM::Enum::tEnumValue::value.

virtual Component* CLAM::Enum::ShallowCopy ( ) const
inlinevirtual

TODO: Copy documentation for this method from Component.

Reimplemented from CLAM::Component.

Definition at line 281 of file Enum.hxx.

References SetValue(), and Species().

virtual Component* CLAM::Enum::Species ( ) const
pure virtual
void CLAM::Enum::StoreOn ( Storage storage) const
virtual

Stores component's subitems on the given Storage.

Parameters:
storageThe given storage where the subitem will be stored
See also:
Storage TODO: This method can throw and IllegalValue exception

Implements CLAM::Component.

Definition at line 33 of file Enum.cxx.

References GetString(), and CLAM::Storage::Store().


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