Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
Enum Class Reference

#include <elm/rtti/Enum.h>

+ Inheritance diagram for Enum:

Classes

class  make
 
class  Value
 

Public Types

typedef Vector< Value >::Iter Iter
 
- Public Types inherited from Type
typedef HashMap< string, const Type * >::Iter TypeIter
 

Public Member Functions

 Enum (const make &make)
 
 Enum (cstring name, const Value values[])
 
Iter values (void) const
 
virtual const Typetype (void) const
 
virtual int valueFor (string text) const
 
virtual cstring nameFor (int value) const
 
virtual bool canCast (const Type *t) const
 
virtual bool isEnum (void) const
 
virtual const EnumerableasEnum (void) const
 
- Public Member Functions inherited from Type
 Type (string name="")
 
virtual ~Type (void)
 
string name (void) const
 
const PointerTypepointer (void) const
 
virtual bool isVoid (void) const
 
virtual bool isBool (void) const
 
virtual bool isInt (void) const
 
virtual bool isFloat (void) const
 
virtual bool isPtr (void) const
 
virtual const PointerTypeasPtr (void) const
 
virtual bool isClass (void) const
 
virtual const AbstractClassasClass (void) const
 
virtual bool isSerial (void) const
 
virtual const SerializableasSerial (void) const
 
virtual const TemplateTypeasTemplate (void) const
 
virtual const InstanceTypeasInstance (void) const
 
virtual const ParamTypeasParam (void) const
 
void initialize (void)
 
bool operator== (const Type &t) const
 
bool operator!= (const Type &t) const
 
- Public Member Functions inherited from Enumerable
virtual ~Enumerable (void)
 

Additional Inherited Members

- Static Public Member Functions inherited from Type
static const Typeget (string name)
 
static TypeIter types (void)
 
- Static Public Attributes inherited from Type
static const Typeparam0
 
static const Typeparam1
 
static const Typeparam2
 
static const Typeparam3
 

Detailed Description

Type for an enumerated type. Recording an enumration in the RTTI system requires several actions:

  • defining an Enum descriptor,
  • link the Enum descriptor with the type itself,
  • providing support for other facilities (input/output, etc).

To help providing this stuff, two macros are provided, DECLARE_ENUM is used in the header file and DEFINE_ENUM in the source file.

The code below represents an heade file where an enumerated type is provided:

#include <elm/rtti.h>
typedef enum my_enum {
A,
B,
C
} my_enum;
DECLARE_ENUM(my_enum);

The code below shows the source corresponding part:

elm::rtti::Enum my_enum_type(elm::rtti::make("my_enum")
.value("A", A)
.value("B", B)
.value("C", C));
DEFINE_ENUM(my_enum, my_enum_type);

Concrete representation of an enumerated type.

Member Typedef Documentation

◆ Iter

typedef Vector<Value>::Iter Iter

Constructor & Destructor Documentation

◆ Enum() [1/2]

Enum ( const make make)

Constructor using a make object.

Parameters
makeObject providing enumeration description.

◆ Enum() [2/2]

Enum ( cstring  name,
const Value  values[] 
)

Old-style enumerated type builder.

Parameters
nameFull-qualified enumerated name.
valuesValues of the enumerated type.

Old-style constructor only provided for backward compatibility.

References Enum::values().

Member Function Documentation

◆ asEnum()

const Enumerable & asEnum ( void  ) const
virtual

Get the enumeration description corresponding to this type. If the type is not enumerated, an assertion failure is raised.

Returns
Corresponding class instance.

Reimplemented from Type.

◆ canCast()

bool canCast ( const Type t) const
virtual

Test if the type can be casted to the given type.

Parameters
tType to cast to.
Returns
True if the type can be casted to the given type, false else.

Reimplemented from Type.

References Type::isInt().

◆ isEnum()

bool isEnum ( void  ) const
virtual

Test if the type is enumerated. Default implementation return false.

Returns
True if the type is a class, false else.

Reimplemented from Type.

◆ nameFor()

cstring nameFor ( int  value) const
virtual

Find the name corresponding to the gi en enumerated value.

Parameters
valueValue to look text for.
Returns
If found, corresponding name or empty string.

Implements Enumerable.

References elm::rtti::value(), and Enum::values().

◆ type()

const Type & type ( void  ) const
virtual

Get the type corresponding to this enumerable interface.

Returns
Corresponding type.

Implements Enumerable.

◆ valueFor()

int valueFor ( string  text) const
virtual

Get the value for a text.

Parameters
textText to lookup.

Implements Enumerable.

◆ values()

Iter values ( void  ) const
inline

Referenced by Enum::Enum(), and Enum::nameFor().


The documentation for this class was generated from the following files:
DEFINE_ENUM
#define DEFINE_ENUM(type, desc)
elm::rtti::Enum
Definition: Enum.h:31
elm::rtti::value
rtti::Enum::Value value(cstring name, int value)
Definition: Enum.h:79
DECLARE_ENUM
#define DECLARE_ENUM(name)
elm::rtti::make
Definition: Class.h:251