This class holds the type information for any arbitrary object. More...
#include <type.h>
Public Types | |
typedef uint16 | type_id |
Public Member Functions | |
type (const type &other) | |
Assigns a type to another one. More... | |
variant | create (std::vector< detail::argument > args) const |
Creates an instance of the given type, with the given arguments for the constructor. More... | |
void | destroy (variant &obj) const |
Destroys the given object obj . More... | |
std::vector< type > | get_base_classes () const |
Returns a list of all base classes of this type. More... | |
constructor | get_constructor (const std::vector< type > ¶ms=std::vector< type >()) const |
Returns a public constructor whose parameters match the types in the specified list. More... | |
std::vector< constructor > | get_constructors () const |
Returns a list of all registered constructors for this type; the order is unspecified. More... | |
std::vector< type > | get_derived_classes () const |
Returns a list of all derived classes of this type. More... | |
destructor | get_destructor () const |
Returns the corresponding destructor for this type. More... | |
enumeration | get_enumeration () const |
Returns the enumerator if this type is an enum type; otherwise the returned value is not valid. More... | |
type_id | get_id () const |
Returns the id of this type. More... | |
method | get_method (const std::string &name) const |
Returns a method with the name name . More... | |
method | get_method (const std::string &name, const std::vector< type > ¶ms) const |
Returns a method with the name name which match the given parameter list params . More... | |
std::vector< method > | get_methods () const |
Returns a list of all registered methods for this type and all its base classes. More... | |
std::string | get_name () const |
Returns the unique and human-readable name of the type. More... | |
std::vector< property > | get_properties () const |
Returns a list of all registered properties for this type and all its base classes. More... | |
property | get_property (const std::string &name) const |
Returns a property with the name name . More... | |
variant | get_property_value (const std::string &name, detail::instance obj) const |
Returns the property value of property named name from the instance obj . More... | |
type | get_raw_type () const |
Returns a type object which represent the raw type. More... | |
variant | invoke (const std::string &name, detail::instance obj, std::vector< detail::argument > args) const |
Invokes the method represented by the current instance object . More... | |
bool | is_array () const |
Returns true whether the given type represents an array. More... | |
bool | is_class () const |
Returns true whether the given type is class; that is not an atomic type or a method. More... | |
bool | is_derived_from (const type &other) const |
Returns true if this type is derived from the given type other , otherwise false. More... | |
template<typename T > | |
bool | is_derived_from () const |
Returns true if this type is derived from the given type T, otherwise false. More... | |
bool | is_enumeration () const |
Returns true whether the given type represents an enumeration. More... | |
bool | is_pointer () const |
Returns true whether the given type represents a pointer. More... | |
bool | is_primitive () const |
Returns true whether the given type represents an primitive type (e.g. More... | |
bool | is_valid () const |
Returns true if this type is valid, that means the type holds valid data to a type. More... | |
operator bool () const | |
Convenience function to check if this type is valid or not. More... | |
bool | operator!= (const type &other) const |
Compares this type with the other type and returns true if both describe different types, otherwise returns false. More... | |
bool | operator< (const type &other) const |
Comparison operator for sorting the type data according to some internal criterion. More... | |
bool | operator<= (const type &other) const |
Comparison operator for sorting the type data according to some internal criterion. More... | |
type & | operator= (const type &other) |
Assigns a type to another one. More... | |
bool | operator== (const type &other) const |
Compares this type with the other type and returns true if both describe the same type, otherwise returns false. More... | |
bool | operator> (const type &other) const |
Comparison operator for sorting the type data according to some internal criterion. More... | |
bool | operator>= (const type &other) const |
Comparison operator for sorting the type data according to some internal criterion. More... | |
bool | set_property_value (const std::string &name, detail::instance obj, detail::argument arg) const |
This function will set the given value arg to a property named name to the instance obj . More... | |
Static Public Member Functions | |
template<typename T > | |
static type | get () |
Returns a type object for the given template type T. More... | |
template<typename T > | |
static type | get (T &&object) |
Returns a type object for the given instance object. More... | |
static type | get (const char *name) |
Returns the type object for the given name. More... | |
static method | get_global_method (const std::string &name) |
Returns a global method with the name name . More... | |
static method | get_global_method (const std::string &name, const std::vector< type > ¶ms) |
Returns a global method with the name name which match the given parameter list params . More... | |
static std::vector< method > | get_global_methods () |
Returns a list of all registered global methods. More... | |
static std::vector< property > | get_global_properties () |
Returns a list of all registered global properties. More... | |
static property | get_global_property (const std::string &name) |
Returns a global property with the name name . More... | |
static variant | get_property_value (const std::string &name) |
Returns the property value of property named name . More... | |
static std::vector< type > | get_types () |
Returns a list of all registered type objects. More... | |
static variant | invoke (const std::string &name, std::vector< detail::argument > args) |
Invokes a global method named name with the specified argument args . More... | |
template<typename F > | |
static void | register_converter_func (F func) |
Register a converter func F . More... | |
static bool | set_property_value (const std::string &name, detail::argument arg) |
This function will set the given value arg to a property named name . More... | |
Friends | |
template<typename TargetType , typename SourceType > | |
TargetType | rttr_cast (SourceType object) |
Casts the given object of type SourceType to an object of type TargetType . More... | |
This class holds the type information for any arbitrary object.
Every class or primitive data type can have an unique type object. With the help of this object you can compare unknown types for equality at runtime or introspect the type for its properties, methods, enumerations, constructors and destructor.
Before you can retrieve data from type, you have to register your struct or class. Therefore use the macro RTTR_DECLARE_TYPE(Type) to make the type known to the type system.
This example shows a typical usage:
A type object cannot be created. It is only possible to retrieve a type object via three static template member functions:
This function just expects the name of the type. This is useful when you know only the name of the type and cannot include the type itself into the source code. The name of the type is the same like you have registered with RTTR_DECLARE_TYPE but as string literal. When you have used a typedef then you need to provide this typedef also as string literal.
This function just expects one template argument. Use it to check against a known type.
This function is a universal reference and returns from every given object the corresponding type object.
When this function is called for a glvalue expression whose type is a polymorphic class type, then the result refers to a type object representing the type of the most derived object.
Any top level
cv-qualifier of the given type T
will be removed.
A type object is lightweight and can be copied by value. However, each copy will refer to the same underlying type.
typedef uint16 rttr::type::type_id |
rttr::type::type | ( | const type & | other | ) |
Assigns a type to another one.
variant rttr::type::create | ( | std::vector< detail::argument > | args | ) | const |
Creates an instance of the given type, with the given arguments for the constructor.
void rttr::type::destroy | ( | variant & | obj | ) | const |
Destroys the given object obj
.
obj
could be destroyed the given obj
is invalid after calling this method; Otherwise it is still valid.
|
static |
Returns a type object for the given template type T.
|
static |
Returns a type object for the given instance object.
|
static |
Returns the type object for the given name.
std::vector<type> rttr::type::get_base_classes | ( | ) | const |
Returns a list of all base classes of this type.
constructor rttr::type::get_constructor | ( | const std::vector< type > & | params = std::vector< type >() | ) | const |
Returns a public constructor whose parameters match the types in the specified list.
std::vector<constructor> rttr::type::get_constructors | ( | ) | const |
Returns a list of all registered constructors for this type; the order is unspecified.
std::vector<type> rttr::type::get_derived_classes | ( | ) | const |
Returns a list of all derived classes of this type.
destructor rttr::type::get_destructor | ( | ) | const |
Returns the corresponding destructor for this type.
enumeration rttr::type::get_enumeration | ( | ) | const |
Returns the enumerator if this type is an enum type; otherwise the returned value is not valid.
|
static |
Returns a global method with the name name
.
name
, and invalid method is returned.name
.
|
static |
Returns a global method with the name name
which match the given parameter list params
.
name
and matching parameter list params
, then an invalid method is returned.name
and parameter signature params
.
|
static |
Returns a list of all registered global methods.
|
static |
Returns a list of all registered global properties.
|
static |
Returns a global property with the name name
.
name
, and invalid property is returned.name
. type_id rttr::type::get_id | ( | ) | const |
Returns the id of this type.
method rttr::type::get_method | ( | const std::string & | name | ) | const |
Returns a method with the name name
.
name
, then an invalid method is returned.name
. method rttr::type::get_method | ( | const std::string & | name, |
const std::vector< type > & | params | ||
) | const |
Returns a method with the name name
which match the given parameter list params
.
name
and matching parameter list params
, then an invalid method is returned.name
. std::vector<method> rttr::type::get_methods | ( | ) | const |
Returns a list of all registered methods for this type and all its base classes.
std::string rttr::type::get_name | ( | ) | const |
Returns the unique and human-readable name of the type.
std::vector<property> rttr::type::get_properties | ( | ) | const |
Returns a list of all registered properties for this type and all its base classes.
property rttr::type::get_property | ( | const std::string & | name | ) | const |
Returns a property with the name name
.
name
, and invalid property is returned.name
. variant rttr::type::get_property_value | ( | const std::string & | name, |
detail::instance | obj | ||
) | const |
Returns the property value of property named name
from the instance obj
.
|
static |
Returns the property value of property named name
.
type rttr::type::get_raw_type | ( | ) | const |
Returns a type object which represent the raw type.
A raw type, is a type type without any qualifiers (const and volatile) nor any pointer.
|
static |
Returns a list of all registered type objects.
variant rttr::type::invoke | ( | const std::string & | name, |
detail::instance | obj, | ||
std::vector< detail::argument > | args | ||
) | const |
Invokes the method represented by the current instance object
.
empty_instance()
.
|
static |
Invokes a global method named name
with the specified argument args
.
bool rttr::type::is_array | ( | ) | const |
Returns true whether the given type represents an array.
bool rttr::type::is_class | ( | ) | const |
Returns true whether the given type is class; that is not an atomic type or a method.
bool rttr::type::is_derived_from | ( | const type & | other | ) | const |
Returns true if this type is derived from the given type other
, otherwise false.
other
, otherwise false. bool rttr::type::is_derived_from | ( | ) | const |
Returns true if this type is derived from the given type T, otherwise false.
bool rttr::type::is_enumeration | ( | ) | const |
Returns true whether the given type represents an enumeration.
bool rttr::type::is_pointer | ( | ) | const |
Returns true whether the given type represents a pointer.
bool rttr::type::is_primitive | ( | ) | const |
Returns true whether the given type represents an primitive type (e.g.
int, bool, etc.).
bool rttr::type::is_valid | ( | ) | const |
Returns true if this type is valid, that means the type holds valid data to a type.
rttr::type::operator bool | ( | ) | const |
bool rttr::type::operator!= | ( | const type & | other | ) | const |
Compares this type with the other type and returns true if both describe different types, otherwise returns false.
bool rttr::type::operator< | ( | const type & | other | ) | const |
Comparison operator for sorting the type data according to some internal criterion.
bool rttr::type::operator<= | ( | const type & | other | ) | const |
Comparison operator for sorting the type data according to some internal criterion.
Assigns a type to another one.
bool rttr::type::operator== | ( | const type & | other | ) | const |
Compares this type with the other type and returns true if both describe the same type, otherwise returns false.
bool rttr::type::operator> | ( | const type & | other | ) | const |
Comparison operator for sorting the type data according to some internal criterion.
bool rttr::type::operator>= | ( | const type & | other | ) | const |
Comparison operator for sorting the type data according to some internal criterion.
|
static |
Register a converter func F
.
This function converts a source Type to a target type. The signature of this function has to be the following: <TargetType (SourceType, bool& ok)> e.g.:
bool rttr::type::set_property_value | ( | const std::string & | name, |
detail::instance | obj, | ||
detail::argument | arg | ||
) | const |
This function will set the given value arg
to a property named name
to the instance obj
.
name
will be tryed to set.
|
static |
This function will set the given value arg
to a property named name
.
|
friend |
Casts the given object
of type SourceType
to an object of type TargetType
.
When the given the given object is an instance of type TargetType
, then this function will cast the pointer to the TargetType
; otherwise it will return a nullptr. If object is already a nullptr then it will also return a nullptr.
SourceType
and TargetType
must be both pointer types.TargetType