rttr  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
Public Member Functions | List of all members
rttr::class_< ClassType > Class Template Reference

This class is used to register the constructors, properties, methods and enumeration for a certain class ClassType. More...

#include <register_reflection.h>

Public Member Functions

 class_ (std::vector< rttr::metadata > data=std::vector< rttr::metadata >())
 
 ~class_ ()
 
template<typename... Args>
class_constructor (std::vector< rttr::metadata > data=std::vector< rttr::metadata >())
 Register a constructor for this class type with with or without arguments. More...
 
template<typename EnumType >
class_enumeration (std::vector< std::pair< std::string, EnumType > > enum_data, std::vector< rttr::metadata > data=std::vector< rttr::metadata >())
 Register a nested enumeration of type EnumType. More...
 
template<typename F >
class_method (const std::string &name, F function)
 Register a method to this class. More...
 
template<typename F >
class_method (const std::string &name, F function, std::vector< rttr::metadata > data)
 Register a method to this class. More...
 
template<typename F , typename Policy >
class_method (const std::string &name, F function, const Policy &policy)
 Register a method to this class. More...
 
template<typename F , typename Policy >
class_method (const std::string &name, F function, std::vector< rttr::metadata > data, const Policy &policy)
 Register a method to this class. More...
 
template<typename A >
class_property (const std::string &name, A acc)
 Register a property with read and write access to this class. More...
 
template<typename A >
class_property (const std::string &name, A acc, std::vector< rttr::metadata > data)
 Register a property with read and write access to this class. More...
 
template<typename A , typename Policy >
class_property (const std::string &name, A acc, const Policy &policy,)
 Register a property with read and write access to this class. More...
 
template<typename A , typename Policy >
class_property (const std::string &name, A acc, std::vector< rttr::metadata > data, const Policy &policy)
 Register a property with read and write access to this class. More...
 
template<typename A1 , typename A2 >
class_property (const std::string &name, A1 getter, A2 setter,)
 Register a property with read and write access to this class. More...
 
template<typename A1 , typename A2 >
class_property (const std::string &name, A1 getter, A2 setter, std::vector< rttr::metadata > data)
 Register a property with read and write access to this class. More...
 
template<typename A1 , typename A2 , typename Policy >
class_property (const std::string &name, A1 getter, A2 setter, const Policy &policy)
 Register a property with read and write access to this class. More...
 
template<typename A1 , typename A2 , typename Policy >
class_property (const std::string &name, A1 getter, A2 setter, std::vector< rttr::metadata > data, const Policy &policy)
 Register a property with read and write access to this class. More...
 
template<typename A >
class_property_readonly (const std::string &name, A accessor)
 Register a property with read only access to this class. More...
 
template<typename A >
class_property_readonly (const std::string &name, A acc, std::vector< rttr::metadata > data)
 Register a property with read only access to this class. More...
 
template<typename A , typename Policy >
class_property_readonly (const std::string &name, A acc, const Policy &policy)
 Register a property with read only access to this class. More...
 
template<typename A , typename Policy >
class_property_readonly (const std::string &name, A acc, std::vector< rttr::metadata > data, const Policy &policy)
 Register a property with read only access to this class. More...
 

Detailed Description

template<typename ClassType>
class rttr::class_< ClassType >

This class is used to register the constructors, properties, methods and enumeration for a certain class ClassType.

Following example show the typical usage:

First the class declaration.

#include <rttr/type>
struct Mesh
{
Mesh();
Mesh(const std::string& name)
Vector3d getPosition() const;
void setPosition(const Vector3d& pos);
enum E_TransformSpace
{
TS_LOCAL,
TS_PARENT,
TS_WORLD
};
void setDirection(const Vector3 &vec, E_TransformSpace ts = TS_LOCAL);
private:
Vector3d _pos;
};
RTTR_DECLARE_STANDARD_TYPE_VARIANTS(Mesh) // to register the type

The in a cpp file, register the constructors, properties and methods of the class Mesh.

#include "Mesh.cpp"
#include <rttr/reflect>
using namespace rttr;
// register the class Mesh before main is called
RTTR_REFLECT
{
.constructor<const string&>()
.enumeration<E_TransformSpace>({{"TS_LOCAL", TS_LOCAL},
{"TS_PARENT", TS_PARENT},
{"TS_WORLD", TS_WORLD}})
.property("pos", &Mesh::getPosition, &Mesh::setPosition)
.method("setDirection", &Mesh::setDirection);
}

Use it then for example like this:

int main()
{
Mesh obj;
const type mesh_type = type::get(obj);
std::cout << mesh_type.get_name() << std::endl; // prints "Mesh"
// sets/gets a property
property pos = mesh_type.get_property("pos");
pos.set_value(obj, Vector3d(1,2,3)); // here we set the value
variant var_pos = pos.get_value(obj); // here we get the value
Vector3d& vec = var_post.get_value<Vector3d>(); // vec == Vector3d(1,2,3)
// invoke a method
method meth_dir = mesh_type.get_method("setDirection");
meth_dir.invoke(obj, Vector3d(1,2,3), Mesh::TS_WORLD);
// retrieve all properties
for (const auto& prop : mesh_type.get_properties())
{
std::cout << prop.get_name(); // prints all property names of the type Mesh
}
for (const auto& meth : mesh_type.get_methods())
{
std::cout << meth.get_name(); // prints all method names of the type Mesh
}
return 0;
}

Constructor & Destructor Documentation

template<typename ClassType >
rttr::class_< ClassType >::class_ ( std::vector< rttr::metadata data = std::vector< rttr::metadata >())
template<typename ClassType >
rttr::class_< ClassType >::~class_ ( )

Member Function Documentation

template<typename ClassType >
template<typename... Args>
class_& rttr::class_< ClassType >::constructor ( std::vector< rttr::metadata data = std::vector< rttr::metadata >())

Register a constructor for this class type with with or without arguments.

See also
rttr::type::get_constructor, rttr::type::create
Returns
Reference to this, in order to chain other calls.
template<typename ClassType >
template<typename EnumType >
class_& rttr::class_< ClassType >::enumeration ( std::vector< std::pair< std::string, EnumType > >  enum_data,
std::vector< rttr::metadata data = std::vector< rttr::metadata >() 
)

Register a nested enumeration of type EnumType.

Parameters
enum_dataThe name of the property.
dataAdditional meta data.
Remarks
Before using this make sure you have registered the type with RTTR_DECLARE_TYPE.
Returns
Reference to this, in order to chain other calls.
template<typename ClassType >
template<typename F >
class_& rttr::class_< ClassType >::method ( const std::string &  name,
function 
)

Register a method to this class.

Parameters
nameThe name of the method.
functionThe function accessor to this method; this can be a member function, a function or an std::function.
Remarks
The method name does not have to be unique for this class.
Returns
Reference to this, in order to chain other calls.
template<typename ClassType >
template<typename F >
class_& rttr::class_< ClassType >::method ( const std::string &  name,
function,
std::vector< rttr::metadata data 
)

Register a method to this class.

Parameters
nameThe name of the method.
functionThe function accessor to this method; this can be a member function, a function or an std::function.
dataAdditional meta data.
Remarks
The method name does not have to be unique for this class.
Returns
Reference to this, in order to chain other calls.
template<typename ClassType >
template<typename F , typename Policy >
class_& rttr::class_< ClassType >::method ( const std::string &  name,
function,
const Policy &  policy 
)

Register a method to this class.

Parameters
nameThe name of the method.
functionThe function accessor to this method; this can be a member function, a function or an std::function.
policyThe policies parameter describes how the method should be binded to the type system.
Remarks
The method name does not have to be unique for this class.
Returns
Reference to this, in order to chain other calls.
template<typename ClassType >
template<typename F , typename Policy >
class_& rttr::class_< ClassType >::method ( const std::string &  name,
function,
std::vector< rttr::metadata data,
const Policy &  policy 
)

Register a method to this class.

Parameters
nameThe name of the method.
functionThe function accessor to this method; this can be a member function, a function or an std::function.
dataAdditional meta data.
policyThe policies parameter describes how the method should be binded to the type system.
Remarks
The method name does not have to be unique for this class.
Returns
Reference to this, in order to chain other calls.
template<typename ClassType >
template<typename A >
class_& rttr::class_< ClassType >::property ( const std::string &  name,
acc 
)

Register a property with read and write access to this class.

Parameters
nameThe name of the property.
accThe accessor to the property; this can be a pointer to a member or a pointer to a variable.
Remarks
The name of the property has to be unique for this class, otherwise it will not be registered.
Returns
Reference to this, in order to chain other calls.
template<typename ClassType >
template<typename A >
class_& rttr::class_< ClassType >::property ( const std::string &  name,
acc,
std::vector< rttr::metadata data 
)

Register a property with read and write access to this class.

Parameters
nameThe name of the property.
accThe accessor to the property; this can be a pointer to a member or a pointer to a variable.
dataAdditional meta data.
Remarks
The name of the property has to be unique for this class, otherwise it will not be registered.
Returns
Reference to this, in order to chain other calls.
template<typename ClassType >
template<typename A , typename Policy >
class_& rttr::class_< ClassType >::property ( const std::string &  name,
acc,
const Policy &  policy 
)

Register a property with read and write access to this class.

Parameters
nameThe name of the property.
accThe accessor to the property; this can be a pointer to a member or a pointer to a variable.
policyThe policies parameter describes how the property should be binded to the type system.
Remarks
The name of the property has to be unique for this class, otherwise it will not be registered.
Returns
Reference to this, in order to chain other calls.
template<typename ClassType >
template<typename A , typename Policy >
class_& rttr::class_< ClassType >::property ( const std::string &  name,
acc,
std::vector< rttr::metadata data,
const Policy &  policy 
)

Register a property with read and write access to this class.

Parameters
nameThe name of the property.
accThe accessor to the property; this can be a pointer to a member or a pointer to a variable.
dataAdditional meta data.
policyThe policies parameter describes how the property should be binded to the type system.
Remarks
The name of the property has to be unique for this class, otherwise it will not be registered.
Returns
Reference to this, in order to chain other calls.
template<typename ClassType >
template<typename A1 , typename A2 >
class_& rttr::class_< ClassType >::property ( const std::string &  name,
A1  getter,
A2  setter 
)

Register a property with read and write access to this class.

Parameters
nameThe name of the property.
getterThe getter accessor to the property; this can be a pointer to a member function, a pointer to a function or a std::function.
setterThe setter accessor to the property; this can be a pointer to a member function, a pointer to a function or a std::function.
Remarks
The name of the property has to be unique for this class, otherwise it will not be registered.
Returns
Reference to this, in order to chain other calls.
template<typename ClassType >
template<typename A1 , typename A2 >
class_& rttr::class_< ClassType >::property ( const std::string &  name,
A1  getter,
A2  setter,
std::vector< rttr::metadata data 
)

Register a property with read and write access to this class.

Parameters
nameThe name of the property.
getterThe getter accessor to the property; this can be a pointer to a member function, a pointer to a function or a std::function.
setterThe setter accessor to the property; this can be a pointer to a member function, a pointer to a function or a std::function.
dataAdditional meta data.
Remarks
The name of the property has to be unique for this class, otherwise it will not be registered.
Returns
Reference to this, in order to chain other calls.
template<typename ClassType >
template<typename A1 , typename A2 , typename Policy >
class_& rttr::class_< ClassType >::property ( const std::string &  name,
A1  getter,
A2  setter,
const Policy &  policy 
)

Register a property with read and write access to this class.

Parameters
nameThe name of the property.
getterThe getter accessor to the property; this can be a pointer to a member function, a pointer to a function or a std::function.
setterThe setter accessor to the property; this can be a pointer to a member function, a pointer to a function or a std::function.
policyThe policies parameter describes how the property should be binded to the type system.
Remarks
The name of the property has to be unique for this class, otherwise it will not be registered.
Returns
Reference to this, in order to chain other calls.
template<typename ClassType >
template<typename A1 , typename A2 , typename Policy >
class_& rttr::class_< ClassType >::property ( const std::string &  name,
A1  getter,
A2  setter,
std::vector< rttr::metadata data,
const Policy &  policy 
)

Register a property with read and write access to this class.

Parameters
nameThe name of the property.
getterThe getter accessor to the property; this can be a pointer to a member function, a pointer to a function or a std::function.
setterThe setter accessor to the property; this can be a pointer to a member function, a pointer to a function or a std::function.
dataAdditional meta data.
policyThe policies parameter describes how the property should be binded to the type system.
Remarks
The name of the property has to be unique for this class, otherwise it will not be registered.
Returns
Reference to this, in order to chain other calls.
template<typename ClassType >
template<typename A >
class_& rttr::class_< ClassType >::property_readonly ( const std::string &  name,
accessor 
)

Register a property with read only access to this class.

Parameters
nameThe name of the property.
accThe accessor to the property; this can be a pointer to a member, a pointer to a variable, a pointer to a member function, a pointer to a function or a std::function.
Remarks
The name of the property has to be unique for this class, otherwise it will not be registered.
Returns
Reference to this, in order to chain other calls.
template<typename ClassType >
template<typename A >
class_& rttr::class_< ClassType >::property_readonly ( const std::string &  name,
acc,
std::vector< rttr::metadata data 
)

Register a property with read only access to this class.

Parameters
nameThe name of the property.
accThe accessor to the property; this can be a pointer to a member, a pointer to a variable, a pointer to a member function, a pointer to a function or a std::function.
dataAdditional meta data.
Remarks
The name of the property has to be unique for this class, otherwise it will not be registered.
Returns
Reference to this, in order to chain other calls.
template<typename ClassType >
template<typename A , typename Policy >
class_& rttr::class_< ClassType >::property_readonly ( const std::string &  name,
acc,
const Policy &  policy 
)

Register a property with read only access to this class.

Parameters
nameThe name of the property.
accThe accessor to the property; this can be a pointer to a member, a pointer to a variable, a pointer to a member function, a pointer to a function or a std::function.
policyThe policies parameter describes how the property should be binded to the type system.
Remarks
The name of the property has to be unique for this class, otherwise it will not be registered.
Returns
Reference to this, in order to chain other calls.
template<typename ClassType >
template<typename A , typename Policy >
class_& rttr::class_< ClassType >::property_readonly ( const std::string &  name,
acc,
std::vector< rttr::metadata data,
const Policy &  policy 
)

Register a property with read only access to this class.

Parameters
nameThe name of the property.
accThe accessor to the property; this can be a pointer to a member, a pointer to a variable, a pointer to a member function, a pointer to a function or a std::function.
dataAdditional meta data.
policyThe policies parameter describes how the property should be binded to the type system.
Remarks
The name of the property has to be unique for this class, otherwise it will not be registered.
Returns
Reference to this, in order to chain other calls.

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