Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
Run-Time Type Information

This module provides information for type at run-time. It may be used for very different purposes as: More...

Classes

class  VoidType
 
class  Enumerable
 
class  Serializable
 
class  Type
 
class  ParamType
 
class  TemplateType
 
class  InstanceType
 
class  Tuple
 
class  AbstractClass
 
class  TemplateClass
 
class  InstanceClass
 
class  ObjectType
 
class  Class< T, B, I >
 
class  Enum
 

Macros

#define IS_CLASS_EXTEND(name, base)   ELM_IS_CLASS_EXTEND(name, base)
 
#define IS_CLASS(name)   ELM_IS_CLASS(name)
 
#define CLASS_EXTEND(name, base)   ELM_CLASS_EXTEND(name, base)
 
#define CLASS(name)   ELM_CLASS(name)
 
#define END_CLASS   ELM_END_CLASS
 
#define IMPLEMENT(name)   ELM_IMPLEMENT(name)
 
#define DECLARE_ENUM(name)   ELM_DECLARE_ENUM(name)
 
#define DEFINE_ENUM(type, desc)   ELM_DEFINE_ENUM (type, desc)
 
#define BEGIN_ENUM(type)   ELM_BEGIN_ENUM(type)
 
#define END_ENUM   ELM_END_ENUM
 

Functions

template<class T >
const rtti::Typetype_of (void)
 

Variables

const Typeint8_type = single<IntType<t::int8> >()
 
const Typeuint8_type = single<IntType<t::uint8> >()
 
const Typeint16_type = single<IntType<t::int16> >()
 
const Typeuint16_type = single<IntType<t::uint16> >()
 
const Typeint32_type = single<IntType<t::int32> >()
 
const Typeuint32_type = single<IntType<t::uint32> >()
 
const Typeint64_type = single<IntType<t::int64> >()
 
const Typeuint64_type = single<IntType<t::uint64> >()
 
const Typefloat_type = single<FloatType<float> >()
 
const Typedouble_type = single<FloatType<double> >()
 
const Typelong_double_type = single<FloatType<long double> >()
 
const Typebool_type = single<BoolType>()
 
const Typestring_type = single<StringType>()
 
const Typevoid_type = single<VoidType>()
 
const Typecstring_type = single<CStringType>()
 

Detailed Description

This module provides information for type at run-time. It may be used for very different purposes as:

For each type, it can provide a Type descriptor that includes:

This module provides several specializations for the different possible types:

Additionally, you can use the type_of<T>() function to get the RTTI type instance representing a type.

RTTI for a Class

Basically, it is as easy as declaring a global variable for the class and linking it to the type_of<T>() function:

// in the header
#include <elm/rtti.h>
class MyClass {
...
};
extern Class<MyClass> MyClass_type;
namespace elm { template <> const Type& type<MyClass>(void) { return MyClass_type; } }
// in the source
Class<MyClass> MyClass_type("MyClass");

To avoid the ugly line, you can declare type instance as a static member of the class (the elm::type_of() function will find it automatically):

// in the header
#include <elm/rtti.h>
class MyClass {
public:
static Class<MyClass> __type;
...
};
// in the source
Class<MyClass> MyClass::__type("MyClass");

Another possibility is to use the integrated macros of RTTI system:

// in the header
#include <elm/rtti.h>
CLASS(MyClass)
...
END_CLASS
// in the source
IMPLEMENT(MyClass)

If your class is extending another RTTI class, you will use instead:

// in the header
#include <elm/rtti.h>
CLASS_EXTEND(MyClass, MyBaseClass)
...
END_CLASS
// in the source
IMPLEMENT(MyClass)

And that's it.

RTTI for Enumeration

Providing RTTI for enumration provides several benefits:

In the header file, you have to declare your enumeration following by a call to macro DECLARE_ENUM:

#include <elm/rtti.h>
typedef enum my_enum_t {
A = 0,
B = 1,
C = 2
} my_enum_t;
DECLARE_ENUM(my_enum_t);

Then you have to create in the source the instance of type representing the enumeration followed by a call to macro DEFINE_ENUM:

Enum my_enum_t_type(Enum::make("my_enum_t")
.value("A", A)
.value("B", B)
.value("C", C)
.alias("AA", A));
DEFINE_ENUM(my_enum_t, my_enum_t_type);

Macro Definition Documentation

◆ BEGIN_ENUM

#define BEGIN_ENUM (   type)    ELM_BEGIN_ENUM(type)

#include <include/elm/rtti/Enum.h>

Build the type instance representing an enumeration type. Must be followed by the declaration of values of the type and aliases as in Enum::make and ended by END_ENUM.

Parameters
typeEnumeration type itself.

◆ CLASS

#define CLASS (   name)    ELM_CLASS(name)

#include <include/elm/rtti/Class.h>

All-in-one declaration macro for a class recorded in RTTI. It substitutes to the class keyword and the class definition must be ended by END_CLASS.

Parameters
nameName of the class.

◆ CLASS_EXTEND

#define CLASS_EXTEND (   name,
  base 
)    ELM_CLASS_EXTEND(name, base)

#include <include/elm/rtti/Class.h>

All-in-one declaration macro for a class recorded in RTTI. It substitutes to the class keyword and the class definition must be ended by END_CLASS.

Parameters
nameName of the class.
baseBase class.

◆ DECLARE_ENUM

#define DECLARE_ENUM (   name)    ELM_DECLARE_ENUM(name)

#include <include/elm/rtti/Enum.h>

Declare an enumeration as supported by RTTI. Must be put just after the enumeration declaration in the header file.

Parameters
nameEnumeration type name.

◆ DEFINE_ENUM

#define DEFINE_ENUM (   type,
  desc 
)    ELM_DEFINE_ENUM (type, desc)

#include <include/elm/rtti/Enum.h>

Define the instance of type for an enumeration type. Must be put in a source file.

Parameters
typeThe enumeration type.
descThe instance of type describing the enumeration type.

◆ END_CLASS

#define END_CLASS   ELM_END_CLASS

#include <include/elm/rtti/Class.h>

Ends the declaration of a RTTI class declared by CLASS or CLASS_EXTEND.

◆ END_ENUM

#define END_ENUM   ELM_END_ENUM

#include <include/elm/rtti/Enum.h>

End the definition of the type instance of an enumeration type. Must follow a BEGIN_ENUM.

◆ IMPLEMENT

#define IMPLEMENT (   name)    ELM_IMPLEMENT(name)

#include <include/elm/rtti/Class.h>

Provide the implementation of a RTTI class. Must be put in the source file of the class.

Parameters
nameName of the class.

◆ IS_CLASS

#define IS_CLASS (   name)    ELM_IS_CLASS(name)

#include <include/elm/rtti/Class.h>

Generate the content of a class to record it in the RTTI database.

Parameters
nameName of the class.

◆ IS_CLASS_EXTEND

#define IS_CLASS_EXTEND (   name,
  base 
)    ELM_IS_CLASS_EXTEND(name, base)

#include <include/elm/rtti/Class.h>

Generate the content of a class to record it in the RTTI database.

Parameters
nameName of the class.
baseBase of the class.

Function Documentation

◆ type_of()

const Type & type_of< T > ( void  )
inline

#include <include/elm/rtti/type_of.h>

Get the instance type corresponding to the given type. Retrieve automatically the type for scalar and pointer or for any specialization of type_of(). For class types, look for the static __type member.

Parameters
TType an instance is looked for.
Returns
Corresponding type instance.

References _type< T >::_().

Variable Documentation

◆ bool_type

const Type & bool_type = single<BoolType>()

#include <include/elm/rtti/type_of.h>

Type for booleans.

Referenced by _type< T >::_().

◆ cstring_type

const Type & cstring_type = single<CStringType>()

#include <include/elm/rtti/type_of.h>

Type for C strings.

Referenced by _type< T >::_().

◆ double_type

const Type & double_type = single<FloatType<double> >()

#include <include/elm/rtti/type_of.h>

Type for double-precision floating-point real.

Referenced by _type< T >::_().

◆ float_type

const Type & float_type = single<FloatType<float> >()

#include <include/elm/rtti/type_of.h>

Type for single-precision floating-point real.

Referenced by _type< T >::_().

◆ int16_type

const Type & int16_type = single<IntType<t::int16> >()

#include <include/elm/rtti/type_of.h>

Type for signed 16-bit integer.

Referenced by _type< T >::_().

◆ int32_type

const Type & int32_type = single<IntType<t::int32> >()

#include <include/elm/rtti/type_of.h>

Type for signed 32-bit integer.

Referenced by _type< T >::_().

◆ int64_type

const Type & int64_type = single<IntType<t::int64> >()

#include <include/elm/rtti/type_of.h>

Type for signed 64-bit integer.

Referenced by _type< T >::_().

◆ int8_type

const Type & int8_type = single<IntType<t::int8> >()

#include <include/elm/rtti/type_of.h>

Type for signed 8-bit integer.

Referenced by _type< T >::_().

◆ long_double_type

const Type & long_double_type = single<FloatType<long double> >()

#include <include/elm/rtti/type_of.h>

Type for quadruple-precision floating-point real.

Referenced by _type< T >::_().

◆ string_type

const Type & string_type = single<StringType>()

#include <include/elm/rtti/type_of.h>

Type for strings.

Referenced by _type< T >::_().

◆ uint16_type

const Type & uint16_type = single<IntType<t::uint16> >()

#include <include/elm/rtti/type_of.h>

Type for unsigned 8-bit integer.

Referenced by _type< T >::_().

◆ uint32_type

const Type & uint32_type = single<IntType<t::uint32> >()

#include <include/elm/rtti/type_of.h>

Type for unsigned 32-bit integer.

Referenced by _type< T >::_().

◆ uint64_type

const Type & uint64_type = single<IntType<t::uint64> >()

#include <include/elm/rtti/type_of.h>

Type for unsigned 64-bit integer.

Referenced by _type< T >::_().

◆ uint8_type

const Type & uint8_type = single<IntType<t::uint8> >()

#include <include/elm/rtti/type_of.h>

Type for unsigned 8-bit integer.

Referenced by _type< T >::_().

◆ void_type

const Type & void_type = single<VoidType>()

#include <include/elm/rtti/type_of.h>

Void type representation.

Referenced by _type< T >::_(), AbstractClass::downCast(), and AbstractClass::upCast().

CLASS_EXTEND
#define CLASS_EXTEND(name, base)
DEFINE_ENUM
#define DEFINE_ENUM(type, desc)
CLASS
#define CLASS(name)
elm::rtti::value
rtti::Enum::Value value(cstring name, int value)
Definition: Enum.h:79
elm
Definition: adapter.h:26
IMPLEMENT
#define IMPLEMENT(name)
DECLARE_ENUM
#define DECLARE_ENUM(name)