Description

Run-time type information defining and querying.

Classes

class  IReflectable
 Interface implemented by classes that provide run time type information. More...
 
struct  RTTIPlainType< T >
 Template that you may specialize with a class if you want to provide simple serialization for it. More...
 
class  RTTIType< Type, BaseType, MyRTTIType >
 Allows you to provide a run-time type information for a specific class, along with support for serialization/deserialization. More...
 

Macros

#define BS_ALLOW_MEMCPY_SERIALIZATION(type)
 Notify the RTTI system that the specified type may be serialized just by using a memcpy. More...
 
#define BS_BEGIN_RTTI_MEMBERS
 Starts definitions for member fields within a RTTI type. More...
 
#define BS_RTTI_MEMBER_PLAIN(name, id)
 Registers a new member field in the RTTI type. More...
 
#define BS_RTTI_MEMBER_PLAIN_NAMED(name, field, id)
 Same as BS_RTTI_MEMBER_PLAIN, but allows you to specify separate names for the field name and the member variable. More...
 
#define BS_RTTI_MEMBER_PLAIN_ARRAY(name, id)
 Registers a new member field in the RTTI type. More...
 
#define BS_RTTI_MEMBER_PLAIN_ARRAY_NAMED(name, field, id)
 Same as BS_RTTI_MEMBER_PLAIN_ARRAY, but allows you to specify separate names for the field name and the member variable. More...
 
#define BS_RTTI_MEMBER_REFL(name, id)
 Registers a new member field in the RTTI type. More...
 
#define BS_RTTI_MEMBER_REFL_NAMED(name, field, id)
 Same as BS_RTTI_MEMBER_REFL, but allows you to specify separate names for the field name and the member variable. More...
 
#define BS_RTTI_MEMBER_REFL_ARRAY(name, id)
 Registers a new member field in the RTTI type. More...
 
#define BS_RTTI_MEMBER_REFL_ARRAY_NAMED(name, field, id)
 Same as BS_RTTI_MEMBER_REFL_ARRAY, but allows you to specify separate names for the field name and the member variable. More...
 
#define BS_RTTI_MEMBER_REFLPTR(name, id)
 Registers a new member field in the RTTI type. More...
 
#define BS_RTTI_MEMBER_REFLPTR_NAMED(name, field, id)
 Same as BS_RTTI_MEMBER_REFLPTR, but allows you to specify separate names for the field name and the member variable. More...
 
#define BS_RTTI_MEMBER_REFLPTR_ARRAY(name, id)
 Registers a new member field in the RTTI type. More...
 
#define BS_RTTI_MEMBER_REFLPTR_ARRAY_NAMED(name, field, id)
 Same as BS_RTTI_MEMBER_REFLPTR_ARRAY, but allows you to specify separate names for the field name and the member variable. More...
 
#define BS_END_RTTI_MEMBERS
 Ends definitions for member fields with a RTTI type. More...
 

Functions

template<class ElemType >
UINT32 rttiGetElemSize (const ElemType &data)
 Helper method when serializing known data types that have valid RTTIPlainType specialization. More...
 
template<class ElemType >
char * rttiWriteElem (const ElemType &data, char *memory)
 Helper method when serializing known data types that have valid RTTIPlainType specialization. More...
 
template<class ElemType >
char * rttiWriteElem (const ElemType &data, char *memory, UINT32 &size)
 Helper method when serializing known data types that have valid RTTIPlainType specialization. More...
 
template<class ElemType >
char * rttiReadElem (ElemType &data, char *memory)
 Helper method when serializing known data types that have valid RTTIPlainType specialization. More...
 
template<class ElemType >
char * rttiReadElem (ElemType &data, char *memory, UINT32 &size)
 Helper method when serializing known data types that have valid RTTIPlainType specialization. More...
 
template<class T >
bool rtti_is_of_type (IReflectable *object)
 Returns true if the provided object can be safely cast into type T. More...
 
template<class T >
bool rtti_is_of_type (SPtr< IReflectable > object)
 Returns true if the provided object can be safely cast into type T. More...
 
BS_UTILITY_EXPORT SPtr< IReflectable > rtti_create (UINT32 rttiId)
 Creates a new object just from its type ID. More...
 
template<class T >
bool rtti_is_subclass (IReflectable *object)
 Checks is the current object a subclass of some type. More...
 

Variables

static InitRTTIOnStart< Type, BaseType > initOnStart
 

Macro Definition Documentation

#define BS_ALLOW_MEMCPY_SERIALIZATION (   type)
Value:
template<> struct RTTIPlainType<type> \
{ enum { id=0 }; enum { hasDynamicSize = 0 }; \
static void toMemory(const type& data, char* memory) \
{ memcpy(memory, &data, sizeof(type)); } \
static UINT32 fromMemory(type& data, char* memory) \
{ memcpy(&data, memory, sizeof(type)); return sizeof(type); } \
static UINT32 getDynamicSize(const type& data) \
{ return sizeof(type); } \
};

Notify the RTTI system that the specified type may be serialized just by using a memcpy.

Note
Internally this creates a basic RTTIPlainType<T> specialization for the type.
See also
RTTIPlainType<T>
#define BS_BEGIN_RTTI_MEMBERS
Value:
struct META_FirstEntry {}; \
void META_InitPrevEntry(META_FirstEntry typeId) { } \
\
typedef META_FirstEntry

Starts definitions for member fields within a RTTI type.

Follow this with calls to BS_RTTI_MEMBER* calls, and finish by calling BS_END_RTTI_MEMBERS. You must also initialize mInitMembers field in the parent class' constructor.

#define BS_END_RTTI_MEMBERS
Value:
META_LastEntry; \
\
struct META_InitAllMembers \
{ \
META_InitAllMembers(MyType* owner) \
{ \
owner->META_InitPrevEntry(META_LastEntry()); \
} \
}; \
\
META_InitAllMembers mInitMembers;

Ends definitions for member fields with a RTTI type.

Must follow BS_BEGIN_RTTI_MEMBERS.

#define BS_RTTI_MEMBER_PLAIN (   name,
  id 
)
Value:
META_Entry_##name; \
\
decltype(OwnerType::name)& get##name(OwnerType* obj) { return obj->name; } \
void set##name(OwnerType* obj, decltype(OwnerType::name)& val) { obj->name = val; } \
\
struct META_NextEntry_##name{}; \
void META_InitPrevEntry(META_NextEntry_##name typeId) \
{ \
addPlainField(#name, id, &MyType::get##name, &MyType::set##name); \
META_InitPrevEntry(META_Entry_##name()); \
} \
\
typedef META_NextEntry_##name

Registers a new member field in the RTTI type.

The field references the name member in the owner class. The type of the member must be a valid plain type. Each field must specify a unique ID for id.

#define BS_RTTI_MEMBER_PLAIN_ARRAY (   name,
  id 
)
Value:
META_Entry_##name; \
\
std::common_type<decltype(OwnerType::name)>::type::value_type& get##name(OwnerType* obj, UINT32 idx) { return obj->name[idx]; } \
void set##name(OwnerType* obj, UINT32 idx, std::common_type<decltype(OwnerType::name)>::type::value_type& val) { obj->name[idx] = val; } \
UINT32 getSize##name(OwnerType* obj) { return (UINT32)obj->name.size(); } \
void setSize##name(OwnerType* obj, UINT32 val) { obj->name.resize(val); } \
\
struct META_NextEntry_##name{}; \
void META_InitPrevEntry(META_NextEntry_##name typeId) \
{ \
addPlainArrayField(#name, id, &MyType::get##name, &MyType::getSize##name, &MyType::set##name, &MyType::setSize##name); \
META_InitPrevEntry(META_Entry_##name()); \
} \
\
typedef META_NextEntry_##name

Registers a new member field in the RTTI type.

The field references the name member in the owner class. The type of the member must be an array of valid plain types. Each field must specify a unique ID for id.

#define BS_RTTI_MEMBER_PLAIN_ARRAY_NAMED (   name,
  field,
  id 
)
Value:
META_Entry_##name; \
\
std::common_type<decltype(OwnerType::field)>::type::value_type& get##name(OwnerType* obj, UINT32 idx) { return obj->field[idx]; } \
void set##name(OwnerType* obj, UINT32 idx, std::common_type<decltype(OwnerType::field)>::type::value_type& val) { obj->field[idx] = val; } \
UINT32 getSize##name(OwnerType* obj) { return (UINT32)obj->field.size(); } \
void setSize##name(OwnerType* obj, UINT32 val) { obj->field.resize(val); } \
\
struct META_NextEntry_##name{}; \
void META_InitPrevEntry(META_NextEntry_##name typeId) \
{ \
addPlainArrayField(#name, id, &MyType::get##name, &MyType::getSize##name, &MyType::set##name, &MyType::setSize##name); \
META_InitPrevEntry(META_Entry_##name()); \
} \
\
typedef META_NextEntry_##name

Same as BS_RTTI_MEMBER_PLAIN_ARRAY, but allows you to specify separate names for the field name and the member variable.

#define BS_RTTI_MEMBER_PLAIN_NAMED (   name,
  field,
  id 
)
Value:
META_Entry_##name; \
\
decltype(OwnerType::field)& get##name(OwnerType* obj) { return obj->field; } \
void set##name(OwnerType* obj, decltype(OwnerType::field)& val) { obj->field = val; } \
\
struct META_NextEntry_##name{}; \
void META_InitPrevEntry(META_NextEntry_##name typeId) \
{ \
addPlainField(#name, id, &MyType::get##name, &MyType::set##name); \
META_InitPrevEntry(META_Entry_##name()); \
} \
\
typedef META_NextEntry_##name

Same as BS_RTTI_MEMBER_PLAIN, but allows you to specify separate names for the field name and the member variable.

#define BS_RTTI_MEMBER_REFL (   name,
  id 
)
Value:
META_Entry_##name; \
\
decltype(OwnerType::name)& get##name(OwnerType* obj) { return obj->name; } \
void set##name(OwnerType* obj, decltype(OwnerType::name)& val) { obj->name = val; } \
\
struct META_NextEntry_##name{}; \
void META_InitPrevEntry(META_NextEntry_##name typeId) \
{ \
addReflectableField(#name, id, &MyType::get##name, &MyType::set##name); \
META_InitPrevEntry(META_Entry_##name()); \
} \
\
typedef META_NextEntry_##name

Registers a new member field in the RTTI type.

The field references the name member in the owner class. The type of the member must be a valid reflectable (non-pointer) type. Each field must specify a unique ID for id.

#define BS_RTTI_MEMBER_REFL_ARRAY (   name,
  id 
)
Value:
META_Entry_##name; \
\
std::common_type<decltype(OwnerType::name)>::type::value_type& get##name(OwnerType* obj, UINT32 idx) { return obj->name[idx]; } \
void set##name(OwnerType* obj, UINT32 idx, std::common_type<decltype(OwnerType::name)>::type::value_type& val) { obj->name[idx] = val; } \
UINT32 getSize##name(OwnerType* obj) { return (UINT32)obj->name.size(); } \
void setSize##name(OwnerType* obj, UINT32 val) { obj->name.resize(val); } \
\
struct META_NextEntry_##name{}; \
void META_InitPrevEntry(META_NextEntry_##name typeId) \
{ \
addReflectableArrayField(#name, id, &MyType::get##name, &MyType::getSize##name, &MyType::set##name, &MyType::setSize##name); \
META_InitPrevEntry(META_Entry_##name()); \
} \
\
typedef META_NextEntry_##name

Registers a new member field in the RTTI type.

The field references the name member in the owner class. The type of the member must be an array of valid reflectable (non-pointer) types. Each field must specify a unique ID for id.

#define BS_RTTI_MEMBER_REFL_ARRAY_NAMED (   name,
  field,
  id 
)
Value:
META_Entry_##name; \
\
std::common_type<decltype(OwnerType::field)>::type::value_type& get##name(OwnerType* obj, UINT32 idx) { return obj->field[idx]; } \
void set##name(OwnerType* obj, UINT32 idx, std::common_type<decltype(OwnerType::field)>::type::value_type& val) { obj->field[idx] = val; } \
UINT32 getSize##name(OwnerType* obj) { return (UINT32)obj->field.size(); } \
void setSize##name(OwnerType* obj, UINT32 val) { obj->field.resize(val); } \
\
struct META_NextEntry_##name{}; \
void META_InitPrevEntry(META_NextEntry_##name typeId) \
{ \
addReflectableArrayField(#name, id, &MyType::get##name, &MyType::getSize##name, &MyType::set##name, &MyType::setSize##name); \
META_InitPrevEntry(META_Entry_##name()); \
} \
\
typedef META_NextEntry_##name

Same as BS_RTTI_MEMBER_REFL_ARRAY, but allows you to specify separate names for the field name and the member variable.

#define BS_RTTI_MEMBER_REFL_NAMED (   name,
  field,
  id 
)
Value:
META_Entry_##name; \
\
decltype(OwnerType::field)& get##name(OwnerType* obj) { return obj->field; } \
void set##name(OwnerType* obj, decltype(OwnerType::field)& val) { obj->field = val; } \
\
struct META_NextEntry_##name{}; \
void META_InitPrevEntry(META_NextEntry_##name typeId) \
{ \
addReflectableField(#name, id, &MyType::get##name, &MyType::set##name); \
META_InitPrevEntry(META_Entry_##name()); \
} \
\
typedef META_NextEntry_##name

Same as BS_RTTI_MEMBER_REFL, but allows you to specify separate names for the field name and the member variable.

#define BS_RTTI_MEMBER_REFLPTR (   name,
  id 
)
Value:
META_Entry_##name; \
\
decltype(OwnerType::name) get##name(OwnerType* obj) { return obj->name; } \
void set##name(OwnerType* obj, decltype(OwnerType::name) val) { obj->name = val; } \
\
struct META_NextEntry_##name{}; \
void META_InitPrevEntry(META_NextEntry_##name typeId) \
{ \
addReflectablePtrField(#name, id, &MyType::get##name, &MyType::set##name); \
META_InitPrevEntry(META_Entry_##name()); \
} \
\
typedef META_NextEntry_##name

Registers a new member field in the RTTI type.

The field references the name member in the owner class. The type of the member must be a valid reflectable pointer type. Each field must specify a unique ID for id.

#define BS_RTTI_MEMBER_REFLPTR_ARRAY (   name,
  id 
)
Value:
META_Entry_##name; \
\
std::common_type<decltype(OwnerType::name)>::type::value_type get##name(OwnerType* obj, UINT32 idx) { return obj->name[idx]; } \
void set##name(OwnerType* obj, UINT32 idx, std::common_type<decltype(OwnerType::name)>::type::value_type val) { obj->name[idx] = val; } \
UINT32 getSize##name(OwnerType* obj) { return (UINT32)obj->name.size(); } \
void setSize##name(OwnerType* obj, UINT32 val) { obj->name.resize(val); } \
\
struct META_NextEntry_##name{}; \
void META_InitPrevEntry(META_NextEntry_##name typeId) \
{ \
addReflectablePtrArrayField(#name, id, &MyType::get##name, &MyType::getSize##name, &MyType::set##name, &MyType::setSize##name); \
META_InitPrevEntry(META_Entry_##name()); \
} \
\
typedef META_NextEntry_##name

Registers a new member field in the RTTI type.

The field references the name member in the owner class. The type of the member must be a valid reflectable pointer type. Each field must specify a unique ID for id.

#define BS_RTTI_MEMBER_REFLPTR_ARRAY_NAMED (   name,
  field,
  id 
)
Value:
META_Entry_##name; \
\
std::common_type<decltype(OwnerType::field)>::type::value_type get##name(OwnerType* obj, UINT32 idx) { return obj->field[idx]; } \
void set##name(OwnerType* obj, UINT32 idx, std::common_type<decltype(OwnerType::field)>::type::value_type val) { obj->field[idx] = val; } \
UINT32 getSize##name(OwnerType* obj) { return (UINT32)obj->field.size(); } \
void setSize##name(OwnerType* obj, UINT32 val) { obj->field.resize(val); } \
\
struct META_NextEntry_##name{}; \
void META_InitPrevEntry(META_NextEntry_##name typeId) \
{ \
addReflectablePtrArrayField(#name, id, &MyType::get##name, &MyType::getSize##name, &MyType::set##name, &MyType::setSize##name); \
META_InitPrevEntry(META_Entry_##name()); \
} \
\
typedef META_NextEntry_##name

Same as BS_RTTI_MEMBER_REFLPTR_ARRAY, but allows you to specify separate names for the field name and the member variable.

#define BS_RTTI_MEMBER_REFLPTR_NAMED (   name,
  field,
  id 
)
Value:
META_Entry_##name; \
\
decltype(OwnerType::field) get##name(OwnerType* obj) { return obj->field; } \
void set##name(OwnerType* obj, decltype(OwnerType::field) val) { obj->field = val; } \
\
struct META_NextEntry_##name{}; \
void META_InitPrevEntry(META_NextEntry_##name typeId) \
{ \
addReflectablePtrField(#name, id, &MyType::get##name, &MyType::set##name); \
META_InitPrevEntry(META_Entry_##name()); \
} \
\
typedef META_NextEntry_##name

Same as BS_RTTI_MEMBER_REFLPTR, but allows you to specify separate names for the field name and the member variable.

Function Documentation

BS_UTILITY_EXPORT SPtr<IReflectable> bs::rtti_create ( UINT32  rttiId)

Creates a new object just from its type ID.

bool bs::rtti_is_of_type ( IReflectable object)

Returns true if the provided object can be safely cast into type T.

bool bs::rtti_is_of_type ( SPtr< IReflectable object)

Returns true if the provided object can be safely cast into type T.

bool bs::rtti_is_subclass ( IReflectable object)

Checks is the current object a subclass of some type.

UINT32 bs::rttiGetElemSize ( const ElemType &  data)

Helper method when serializing known data types that have valid RTTIPlainType specialization.

Returns the size of the element. If elements serializable type is specialized with hasDynamicSize == true, the dynamic size is calculated, otherwise sizeof() is used.

char* bs::rttiReadElem ( ElemType &  data,
char *  memory 
)

Helper method when serializing known data types that have valid RTTIPlainType specialization.

Reads the specified data into memory, advances the memory pointer by the bytes read and returns pointer to new memory.

char* bs::rttiReadElem ( ElemType &  data,
char *  memory,
UINT32 &  size 
)

Helper method when serializing known data types that have valid RTTIPlainType specialization.

Reads the specified data into memory, advances the memory pointer by the bytes read and returns pointer to new memory. Also increases the size value by the size of the read element.

char* bs::rttiWriteElem ( const ElemType &  data,
char *  memory 
)

Helper method when serializing known data types that have valid RTTIPlainType specialization.

Writes the specified data into memory, advances the memory pointer by the bytes written and returns pointer to new memory.

char* bs::rttiWriteElem ( const ElemType &  data,
char *  memory,
UINT32 &  size 
)

Helper method when serializing known data types that have valid RTTIPlainType specialization.

Writes the specified data into memory, advances the memory pointer by the bytes written and returns pointer to new memory. Also increases the size value by the size of the written element.