CLAM::Enum Class Reference

#include <Enum.hxx>

Inheritance diagram for CLAM::Enum:

CLAM::Component CLAM::EAudioFileCodec CLAM::EAudioFileEncoding CLAM::EAudioFileEndianess CLAM::EAudioFileFormat CLAM::EFDFilterGenControls CLAM::EFDFilterType CLAM::EInterpolation CLAM::ELoopPointUnits CLAM::EOscillatorControls CLAM::EPhaseGeneration CLAM::EPitch CLAM::EScale CLAM::ETokenDelayControls CLAM::EWaveType CLAM::EWindowNormalize CLAM::EWindowType CLAM::OutControlSenderConfig::EControlRepresentation CLAM::OutControlSenderConfig::EMapping

List of all 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.


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.

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.

Classes

struct  tEnumValue

Member Typedef Documentation

Definition at line 97 of file Enum.hxx.


Constructor & Destructor Documentation

CLAM::Enum::Enum ( const tEnumValue values,
const tValue value 
) [inline, protected]

Construction with a numeric value.

Parameters:
values An array of tEnumValue structures in wich the last one has a NULL pointer as name.
value An initialization numeric value.
Exceptions:
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.

Parameters:
values An array of tEnumValue structures in wich the last one has a NULL pointer as name.
value An initialization symbolic value.
Exceptions:
A IllegalValue 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

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.

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

Returns the symbol map for the enum.

Definition at line 142 of file Enum.hxx.

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

Changes the value.

Parameters:
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 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:
v The new numeric value
Exceptions:
IllegalValue when 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::SetValue ( const std::string &  s  )  [inline]

Changes the value.

Parameters:
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::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.

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

Returns the numeric value.

Returns:
The numeric value

Definition at line 218 of file Enum.hxx.

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

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

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

Conversion operiation as a number.

Returns:
The numeric value

Definition at line 255 of file Enum.hxx.

virtual Component* CLAM::Enum::Species (  )  const [pure 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().

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

void CLAM::Enum::StoreOn ( Storage storage  )  const [virtual]

Stores component's subitems on the given Storage.

Parameters:
storage The 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().

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

Loads component's subitems from the given Storage.

Parameters:
storage The 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().


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

Generated on Tue Aug 12 22:33:50 2008 for CLAM by  doxygen 1.5.5