The type class holds the type information for any arbitrary object. More...
#include <type.h>
Public Types | |
typedef uint16_t | type_id |
Public Member Functions | |
type (const type &other) | |
Assigns a type to another one. More... | |
variant | create (std::vector< argument > args=std::vector< argument >()) const |
Creates an instance of the current type, with the given arguments args for the constructor. More... | |
void | destroy (variant &obj) const |
Destroys the given object obj . 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... | |
variant | get_metadata (const variant &key) const |
Returns the meta data for the given key key . More... | |
method | get_method (const char *name) const |
Returns a method with the name name . More... | |
method | get_method (const char *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 char *name) const |
Returns a property with the name name . More... | |
variant | get_property_value (const char *name, 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... | |
std::size_t | get_sizeof () const |
Returns the size in bytes of the object representation of the current type (i.e. More... | |
type | get_wrapped_type () const |
Returns a type object which represent the wrapped type. More... | |
variant | invoke (const char *name, instance obj, std::vector< argument > args) const |
Invokes the method represented by the current instance object . More... | |
bool | is_arithmetic () const |
Returns true whether the given type represents an arithmetic type. 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_function_pointer () const |
Returns true whether the given type represents a pointer to a function e.g. More... | |
bool | is_member_function_pointer () const |
Returns true whether the given type represents a pointer to a member function. More... | |
bool | is_member_object_pointer () const |
Returns true whether the given type represents a pointer to a member object. More... | |
bool | is_pointer () const |
Returns true whether the given type represents a pointer. More... | |
bool | is_valid () const |
Returns true if this type is valid, that means the type holds valid data to a type. More... | |
bool | is_wrapper () const |
Returns true whether the given type represents a wrapper 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 char *name, instance obj, 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_by_name (const char *name) |
Returns the type object with the given name name . More... | |
static method | get_global_method (const char *name) |
Returns a global method with the name name . More... | |
static method | get_global_method (const char *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 char *name) |
Returns a global property with the name name . More... | |
static variant | get_property_value (const char *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 char *name, std::vector< argument > args) |
Invokes a global method named name with the specified argument args . More... | |
template<typename T > | |
static void | register_comparators () |
Register comparison operators for template type T . More... | |
template<typename F > | |
static void | register_converter_func (F func) |
Register a converter func F , which will be used internally by the variant class to convert between types. More... | |
static bool | set_property_value (const char *name, argument arg) |
This function will set the given value arg to a property named name . More... | |
Friends | |
template<typename Target_Type , typename Source_Type > | |
Target_Type | rttr_cast (Source_Type object) |
Casts the given object of type Source_Type to an object of type Target_Type . More... | |
Detailed Description
The type 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.
Retrieve type
A type object cannot be created. It is only possible to retrieve a type object via three static template member functions:
type::get<T>()
This function just expects one template argument. Use it to check against a known type.
type::get_by_name(const char*)
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.
- Remarks
- Before using the function type::get_by_name(), you have to use one time the function via type::get<T>(), otherwise the type is not registered in the type system.
type::get<T>(T&& obj)
This function takes 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.
- Remarks
- If the type of the expression is a cv-qualified type, the result of the rttr::type::get expression refers to a rttr::type object representing the cv-unqualified type.
Any top level
cv-qualifier of the given type T
will be removed.
Copying and Assignment
A type object is lightweight and can be copied by value. However, each copy will refer to the same underlying type.
Member Typedef Documentation
typedef uint16_t rttr::type::type_id |
Constructor & Destructor Documentation
rttr::type::type | ( | const type & | other | ) |
Assigns a type to another one.
Member Function Documentation
Creates an instance of the current type, with the given arguments args
for the constructor.
- Remarks
- When the argument types does not match the parameter list of the constructor then the he will not be invoked. Constructors with registered default_arguments will be honored.
- Returns
- Returns an instance of the given type.
void rttr::type::destroy | ( | variant & | obj | ) | const |
Destroys the given object obj
.
- Remarks
- When the
obj
could be destroyed the givenobj
is invalid after calling this method; Otherwise it is still valid.
|
static |
Returns a type object for the given template type T.
- Returns
- type for the template type T.
|
static |
Returns a type object for the given instance object.
- Remarks
- If the type of the expression is a cv-qualified type, the result of the type::get() expression refers to a type object representing the cv-unqualified type. When type::get() is applied to a glvalue expression whose type is a polymorphic class type, the result refers to a type object representing the type of the most derived object.
- Returns
- type for an object of type T.
|
static |
Returns the type object with the given name name
.
- Remarks
- The search for the type is case sensitive. White spaces will be ignored. The name of the type corresponds to the name which was used during RTTR_REGISTRATION. Only after the registration process was executed, then the type can be retrieved with this function. Otherwise and invalid type will be returned.
- Returns
- type object with the name
name
.
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.
- Remarks
- When no parameter list is given, it will be searched for the default constructor.
- Returns
- A valid constructor will be returned when the parameter matches the registered constructor; otherwise an invalid constructor.
std::vector<constructor> rttr::type::get_constructors | ( | ) | const |
Returns a list of all registered constructors for this type; the order is unspecified.
- Returns
- Returns a list of all registered constructors.
std::vector<type> rttr::type::get_derived_classes | ( | ) | const |
Returns a list of all derived classes of this type.
- Remarks
- Make sure that the complete class hierarchy has the macro RTTR_ENABLE inside the class declaration, otherwise the returned information of this function is not correct. The order of this list depends on the declaration order of classes inside RTTR_ENABLE. E.g. RTTR_ENABLE(A1, A2) => A1 will be for A2 in the list.
- Returns
- A list of type objects.
destructor rttr::type::get_destructor | ( | ) | const |
Returns the corresponding destructor for this type.
- Remarks
- When there is no constructor registered for this type, then also the destructor is not available. A destructor will always been automatically registered.
- Returns
- Returns the 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.
- See also
- is_enumeration()
- Returns
- A enumeration object.
|
static |
Returns a global method with the name name
.
- Remarks
- When there exists no method with the name
name
, and invalid method is returned.
- Returns
- A method with name
name
.
|
static |
Returns a global method with the name name
which match the given parameter list params
.
- Remarks
- When there exists no method with the name
name
and matching parameter listparams
, then an invalid method is returned.
- Returns
- A method with name
name
and parameter signatureparams
.
|
static |
Returns a list of all registered global methods.
- Remarks
- The order of the methods in the vector is undefined. Client code should not depend on the order in which methods are returned, because that order varies.
- Returns
- A vector with methods.
|
static |
Returns a list of all registered global properties.
- Remarks
- The order of the properties in the vector is undefined. Client code should not depend on the order in which properties are returned, because that order varies.
- Returns
- A vector with properties.
|
static |
Returns a global property with the name name
.
- Remarks
- When there exists no property with the name
name
, then an invalid property is returned.
- Returns
- A property with name
name
.
type_id rttr::type::get_id | ( | ) | const |
Returns the id of this type.
- Note
- This id is unique at process runtime, but the id can be changed every time the process is executed.
- Returns
- The type id.
Returns the meta data for the given key key
.
- Remarks
- When no meta data is registered with the given
key
, an invalid variant object is returned (see variant::is_valid).
- Returns
- A variant object, containing arbitrary data.
method rttr::type::get_method | ( | const char * | name | ) | const |
Returns a method with the name name
.
- Remarks
- When there exists no method with the name
name
, then an invalid method is returned.
- Returns
- A method with name
name
.
Returns a method with the name name
which match the given parameter list params
.
- Remarks
- When there exists no method with the name
name
and matching parameter listparams
, then an invalid method is returned.
- Returns
- A method with name
name
.
std::vector<method> rttr::type::get_methods | ( | ) | const |
Returns a list of all registered methods for this type and all its base classes.
- Remarks
- The methods are sorted after its order of registration.
- Returns
- A vector with method objects
std::string rttr::type::get_name | ( | ) | const |
Returns the unique and human-readable name of the type.
- Remarks
- The content of this string is compiler depended.
- Returns
- The type name.
std::vector<property> rttr::type::get_properties | ( | ) | const |
Returns a list of all registered properties for this type and all its base classes.
- Remarks
- The properties are sorted after its order of registration.
- Returns
- A vector with properties.
property rttr::type::get_property | ( | const char * | name | ) | const |
Returns a property with the name name
.
- Remarks
- When there exists no property with the name
name
, then an invalid property is returned.
- Returns
- A property with name
name
.
Returns the property value of property named name
from the instance obj
.
- Remarks
- When the given instance is empty, the value of global property will be tryed to returned.
- Returns
- A variant containing the value of the property.
|
static |
Returns the property value of property named name
.
- Returns
- A variant containing the value of the property.
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.
- Remarks
- When the current type is already the raw type, it will return an copy from itself.
- Returns
- The corresponding raw type object.
std::size_t rttr::type::get_sizeof | ( | ) | const |
Returns the size in bytes of the object representation of the current type (i.e.
sizeof(T)
).
- Returns
- The size of the type in bytes.
|
static |
Returns a list of all registered type objects.
- Remarks
- The order of the type object is unspecified.
- Returns
- A vector of type objects.
type rttr::type::get_wrapped_type | ( | ) | const |
Returns a type object which represent the wrapped type.
A wrapper type is a class which encapsulate an instance of another type. This encapsulate type is also called wrapped type.
See following example code:
- Remarks
- When the current type is not a wrapper type, this function will return an invalid type.
- See also
- wrapper_mapper<T>
- Returns
- The type object of the wrapped type.
Invokes the method represented by the current instance object
.
- Remarks
- When it's a static method you still need to provide an instance object, use therefore the default ctor of instance(), or as shortcut use simply
{}
. Methods with registered default_arguments will be honored.
- Returns
- A variant object containing the possible return value, otherwise when it is a void function an empty but valid variant object.
Invokes a global method named name
with the specified argument args
.
- Returns
- A variant object containing the possible return value, otherwise when it is a void function an empty but valid variant object. Methods with registered default_arguments will be honored.
bool rttr::type::is_arithmetic | ( | ) | const |
Returns true whether the given type represents an arithmetic type.
An arithmetic type is a integral type or a floating point type. e.g. bool
, int
, float
, etc...
- Returns
- True if the type is a arithmetic type, otherwise false.
bool rttr::type::is_array | ( | ) | const |
Returns true whether the given type represents an array.
- Returns
- True if the type is an array, otherwise false.
- See also
- array_mapper<T>
bool rttr::type::is_class | ( | ) | const |
Returns true whether the given type is class; that is not an atomic type or a method.
- Returns
- True if the type is a class, otherwise false.
bool rttr::type::is_derived_from | ( | const type & | other | ) | const |
Returns true if this type is derived from the given type other
, otherwise false.
- Remarks
- Make sure that the complete class hierarchy has the macro RTTR_ENABLE inside the class declaration, otherwise the returned information of this function is not correct.
- Returns
- Returns true if this type is a derived type from
other
, otherwise false.
bool rttr::type::is_derived_from | ( | ) | const |
Returns true if this type is derived from the given type T, otherwise false.
- Remarks
- Make sure that the complete class hierarchy has the macro RTTR_ENABLE inside the class declaration, otherwise the returned information of this function is not correct.
- Returns
- Returns true if this type is a derived type from T, otherwise false.
bool rttr::type::is_enumeration | ( | ) | const |
Returns true whether the given type represents an enumeration.
- Returns
- True if the type is an enumeration, otherwise false.
bool rttr::type::is_function_pointer | ( | ) | const |
Returns true whether the given type represents a pointer to a function e.g.
void (*)(void)
- Returns
- True if the type is a function pointer, otherwise false.
bool rttr::type::is_member_function_pointer | ( | ) | const |
Returns true whether the given type represents a pointer to a member function.
e.g. void (MyClass::*)(void)
- Returns
- True if the type is a member function pointer type, otherwise false.
bool rttr::type::is_member_object_pointer | ( | ) | const |
Returns true whether the given type represents a pointer to a member object.
e.g. int (MyClass::*)
- Returns
- True if the type is a member object pointer, otherwise false.
bool rttr::type::is_pointer | ( | ) | const |
Returns true whether the given type represents a pointer.
e.g. int*
, or bool*
- Returns
- True if the type is a pointer, otherwise false.
bool rttr::type::is_valid | ( | ) | const |
Returns true if this type is valid, that means the type holds valid data to a type.
- Returns
- True if this type is valid, otherwise false.
bool rttr::type::is_wrapper | ( | ) | const |
Returns true whether the given type represents a wrapper type.
A wrapper type is a class which encapsulate an instance of another type. RTTR recognize automatically following wrapper types:
std::shared_ptr<T>
std::reference_wrapper<T>
std::weak_ptr<T>
std::unique_ptr<T>
In order to work with custom wrapper types, its required to specialize the class wrapper_mapper<T> and implement a getter function to retrieve the encapsulate type.
- See also
- wrapper_mapper<T>
- Returns
- True if the type is an wrapper, otherwise false.
|
explicit |
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.
- Returns
- True if both type are not equal, otherwise false.
bool rttr::type::operator< | ( | const type & | other | ) | const |
Comparison operator for sorting the type data according to some internal criterion.
- Returns
- True if this type is less than the other.
bool rttr::type::operator<= | ( | const type & | other | ) | const |
Comparison operator for sorting the type data according to some internal criterion.
- Returns
- True if this type is less than or equal to other.
Assigns a type to another one.
- Returns
- A type object.
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.
- Returns
- True if both type are equal, otherwise false.
bool rttr::type::operator> | ( | const type & | other | ) | const |
Comparison operator for sorting the type data according to some internal criterion.
- Returns
- True if this type is greater than the other.
bool rttr::type::operator>= | ( | const type & | other | ) | const |
Comparison operator for sorting the type data according to some internal criterion.
- Returns
- True if this type is greater than or equal to other.
|
static |
Register comparison operators for template type T
.
This requires a valid operator==
and operator<
for type T
.
The registered comparison operators will be used in the variant class.
See following example code:
|
static |
Register a converter func F
, which will be used internally by the variant class to convert between types.
This function converts a source type to a target type. The signature of this function has to be the following: TargetType (SourceType, bool& ok)
See following example code:
- See also
- variant::convert()
This function will set the given value arg
to a property named name
to the instance obj
.
- Remarks
- When the given instance is empty, the value of a global property with name
name
will be tryed to set.
- Returns
- A bool value, which is true, when the value could be set, otherwise false.
|
static |
This function will set the given value arg
to a property named name
.
- Returns
- A bool value, which is true, when the value could be set, otherwise false.
Friends And Related Function Documentation
|
friend |
Casts the given object
of type Source_Type
to an object of type Target_Type
.
When the given the given object
is an instance of type Target_Type
, 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
.
- Remarks
- Both class types must contain the macro RTTR_ENABLE in the class declaration.
Source_Type
andTarget_Type
must be both pointer types.
- Returns
- A pointer of type
Target_Type
The documentation for this class was generated from the following file: