Instances of this class represents objects that can adquire a symbolic value from a limited set of symbolic values. More...
#include <Enum.hxx>
Classes | |
struct | tEnumValue |
Public Types | |
typedef int | tValue |
Public Member Functions | |
const tEnumValue * | GetSymbolMap () 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. | |
Enum & | operator= (const tValue &v) throw (IllegalValue) |
Enum & | operator= (const std::string &v) throw (IllegalValue) |
Enum & | operator= (const Enum &v) throw (IllegalValue) |
operator tValue () const | |
Conversion operiation as a number. | |
virtual Component * | Species () const =0 |
Returns a new object of the same class than the receiver object. | |
virtual Component * | DeepCopy () const |
TODO: Copy documentation for this method from Component. | |
virtual Component * | ShallowCopy () 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. | |
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. |
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.
typedef int CLAM::Enum::tValue |
CLAM::Enum::Enum | ( | const tEnumValue * | values, | |
const tValue & | value | |||
) | [inline, protected] |
Construction with a numeric value.
values | An array of tEnumValue structures in wich the last one has a NULL pointer as name. | |
value | An initialization numeric value. |
A | IllegalValue 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 | |||
) | [inline, protected] |
Construction with a symbolic value.
values | An array of tEnumValue structures in wich the last one has a NULL pointer as name. | |
value | An initialization symbolic value. |
A | IllegalValue exception when the value is not valid. |
Definition at line 127 of file Enum.hxx.
References SetValue().
CLAM::Enum::~Enum | ( | ) | [virtual] |
virtual Component* CLAM::Enum::DeepCopy | ( | ) | const [inline, virtual] |
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 [inline, virtual] |
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.
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] |
tValue CLAM::Enum::GetValue | ( | ) | const [inline] |
void CLAM::Enum::LoadFrom | ( | Storage & | storage | ) | [virtual] |
Loads component's subitems from the given Storage.
storage | The given storage where the subitem will be stored |
Implements CLAM::Component.
Definition at line 40 of file Enum.cxx.
References CLAM::Storage::Load(), and SetValueSafely().
CLAM::Enum::operator tValue | ( | ) | const [inline] |
Enum& CLAM::Enum::operator= | ( | const Enum & | v | ) | throw (IllegalValue) [inline] |
Definition at line 246 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 tValue & | v | ) | throw (IllegalValue) [inline] |
Definition at line 236 of file Enum.hxx.
References SetValue().
void CLAM::Enum::SetValue | ( | const std::string & | s | ) | [inline] |
Changes the value.
s | The 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::SetValue | ( | const tValue | v | ) | [inline] |
Changes the value.
v | The 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::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.
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.
v | The new numeric value |
IllegalValue | when the value is not valid for the enum |
Definition at line 171 of file Enum.hxx.
References CLAM::Enum::tEnumValue::name.
Referenced by LoadFrom().
virtual Component* CLAM::Enum::ShallowCopy | ( | ) | const [inline, virtual] |
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] |
Returns a new object of the same class than the receiver object.
To be reimplemented by subclasses.
Implemented in CLAM::EAudioFileCodec, CLAM::EAudioFileFormat, CLAM::EAudioFileEncoding, CLAM::EAudioFileEndianess, CLAM::EPitch, CLAM::EWindowNormalize, CLAM::EnumTypedTypes, CLAM::OutControlSenderConfig::EControlRepresentation, CLAM::OutControlSenderConfig::EMapping, CLAM::EOscillatorControls, CLAM::EWaveType, CLAM::ELoopPointUnits, CLAM::EPhaseGeneration, CLAM::EFDFilterGenControls, CLAM::EFDFilterType, CLAM::EInterpolation, CLAM::EScale, and CLAM::EWindowType.
Referenced by DeepCopy(), and ShallowCopy().
void CLAM::Enum::StoreOn | ( | Storage & | storage | ) | const [virtual] |
Stores component's subitems on the given Storage.
storage | The given storage where the subitem will be stored |
Implements CLAM::Component.
Definition at line 33 of file Enum.cxx.
References GetString(), and CLAM::Storage::Store().