rttr  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
Classes | Namespaces | Macros | Functions
type.h File Reference
#include "rttr/base/core_prerequisites.h"
#include <type_traits>
#include <vector>
#include <string>
#include <memory>
#include "rttr/impl/type_impl.h"

Go to the source code of this file.

Classes

class  rttr::type
 This class holds the type information for any arbitrary object. More...
 

Namespaces

 rttr
 The namespace for all rttr components.
 

Macros

#define RTTR_DECLARE_STANDARD_TYPE_VARIANTS(Type)
 This macro will define three common variants of the given type Type. More...
 
#define RTTR_DECLARE_TYPE(Type)
 This macro makes the type Type known to the type system. More...
 
#define RTTR_DEFINE_TYPE(Type)
 This macro makes the type Type immediately known to the type system. More...
 

Functions

template<typename TargetType , typename SourceType >
TargetType rttr::rttr_cast (SourceType object)
 Casts the given object of type SourceType to an object of type TargetType. More...
 

Macro Definition Documentation

#define RTTR_DECLARE_STANDARD_TYPE_VARIANTS (   Type)

This macro will define three common variants of the given type Type.

That are: Type, Type*, const Type* So it is basically a shortcut instead of writing three times RTTR_DECLARE_TYPE.

#define RTTR_DECLARE_TYPE (   Type)

This macro makes the type Type known to the type system.

The macro should be placed directly under declaration of the custom class or struct of Type. So the type class can access it in every translation unit (*.cpp file).

When using a Type without this registration, it will lead to a compile time error with following message: The given type T is not registered to the type system; please register with RTTR_DECLARE_TYPE.

The following example will demonstrate the usage:

// MyStruct.h
struct MyStruct
{
bool visible;
};

When MyStruct is in a namespace, make sure you putt the macro outside the namespace, otherwise type cannot access the Type.

namespace NSMyStruct
{
}
RTTR_DECLARE_TYPE(NSMyStruct::MyStruct)
#define RTTR_DEFINE_TYPE (   Type)

This macro makes the type Type immediately known to the type system.

Place this macro inside the global namespace of one translation unit. Normally it is placed inside the corresponding cpp file of type Type.

The reason for this macro is, to make sure that the given Type is registered before main was executed. Another way to execute the registration process is to call rttr::type::get<Type>(), this will invoke the registration function registered with RTTR_DECLARE_TYPE.

// MyStruct.cpp