The type class holds the type information for any arbitrary object. More...
#include <type.h>
Public Types | |
typedef uintptr_t | type_id |
Public Member Functions | |
type (const type &other) noexcept | |
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... | |
bool | destroy (variant &obj) const noexcept |
Destroys the contained object in the variant obj . More... | |
array_range< type > | get_base_classes () const noexcept |
Returns a range of all base classes of this type. More... | |
constructor | get_constructor (const std::vector< type > ¶ms=std::vector< type >()) const noexcept |
Returns a public constructor whose parameters match the types in the specified list. More... | |
array_range< constructor > | get_constructors () const noexcept |
Returns a range of all registered public constructors for this type. More... | |
array_range< constructor > | get_constructors (filter_items filter) const noexcept |
Returns a range of all registered constructors for this type, based on the given filter . More... | |
array_range< type > | get_derived_classes () const noexcept |
Returns a range of all derived classes of this type. More... | |
destructor | get_destructor () const noexcept |
Returns the corresponding destructor for this type. More... | |
enumeration | get_enumeration () const noexcept |
Returns the enumerator if this type is an enum type; otherwise the returned value is not valid. More... | |
type_id | get_id () const noexcept |
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 (string_view name) const noexcept |
Returns a method with the name name . More... | |
method | get_method (string_view name, const std::vector< type > &type_list) const noexcept |
Returns a method with the name name which match the given parameter type list type_list . More... | |
array_range< method > | get_methods () const noexcept |
Returns a range of all registered public methods for this type and all its base classes. More... | |
array_range< method > | get_methods (filter_items filter) const noexcept |
Returns a range of all registered methods for this type, based on the given filter . More... | |
string_view | get_name () const noexcept |
Returns the unique and human-readable name of the type. More... | |
array_range< property > | get_properties () const noexcept |
Returns a range of all registered public properties for this type and all its base classes. More... | |
array_range< property > | get_properties (filter_items filter) const noexcept |
Returns a range of all registered properties for this type, based on the given filter . More... | |
property | get_property (string_view name) const noexcept |
Returns a property with the name name . More... | |
variant | get_property_value (string_view name, instance obj) const |
Returns the property value of property named name from the instance obj . More... | |
type | get_raw_type () const noexcept |
Returns a type object which represent the raw type. More... | |
std::size_t | get_sizeof () const noexcept |
Returns the size in bytes of the object representation of the current type (i.e. More... | |
array_range< type > | get_template_arguments () const noexcept |
Returns a list of type objects that represents the template arguments. More... | |
type | get_wrapped_type () const noexcept |
Returns a type object which represent the wrapped type. More... | |
variant | invoke (string_view name, instance obj, std::vector< argument > args) const |
Invokes the method represented by the current instance object . More... | |
bool | is_arithmetic () const noexcept |
Returns true whether the given type represents an arithmetic type. More... | |
bool | is_array () const noexcept |
Returns true whether the given type represents an array. More... | |
bool | is_associative_container () const noexcept |
Returns true whether the given type represents an associative container. More... | |
bool | is_base_of (const type &other) const noexcept |
Returns true if this type is the base class from the given type other , otherwise false. More... | |
template<typename T > | |
bool | is_base_of () const noexcept |
Returns true if this type is the base class from the given type T, otherwise false. More... | |
bool | is_class () const noexcept |
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 noexcept |
Returns true if this type is derived from the given type other , otherwise false. More... | |
template<typename T > | |
bool | is_derived_from () const noexcept |
Returns true if this type is derived from the given type T, otherwise false. More... | |
bool | is_enumeration () const noexcept |
Returns true whether the given type represents an enumeration. More... | |
bool | is_function_pointer () const noexcept |
Returns true whether the given type represents a pointer to a function e.g. More... | |
bool | is_member_function_pointer () const noexcept |
Returns true whether the given type represents a pointer to a member function. More... | |
bool | is_member_object_pointer () const noexcept |
Returns true whether the given type represents a pointer to a member object. More... | |
bool | is_pointer () const noexcept |
Returns true whether the given type represents a pointer. More... | |
bool | is_sequential_container () const noexcept |
Returns true whether the given type represents an sequence container. More... | |
bool | is_template_instantiation () const noexcept |
Returns true whether the given type is an instantiation of a class template. More... | |
bool | is_valid () const noexcept |
Returns true if this type is valid, that means the type holds valid data to a type. More... | |
bool | is_wrapper () const noexcept |
Returns true whether the given type represents a wrapper type. More... | |
operator bool () const noexcept | |
Convenience function to check if this type is valid or not. More... | |
bool | operator!= (const type &other) const noexcept |
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 noexcept |
Comparison operator for sorting the type data according to some internal criterion. More... | |
bool | operator<= (const type &other) const noexcept |
Comparison operator for sorting the type data according to some internal criterion. More... | |
type & | operator= (const type &other) noexcept |
Assigns a type to another one. More... | |
bool | operator== (const type &other) const noexcept |
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 noexcept |
Comparison operator for sorting the type data according to some internal criterion. More... | |
bool | operator>= (const type &other) const noexcept |
Comparison operator for sorting the type data according to some internal criterion. More... | |
bool | set_property_value (string_view 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 () noexcept |
Returns a type object for the given template type T. More... | |
template<typename T > | |
static type | get (T &&object) noexcept |
Returns a type object for the given instance object. More... | |
static type | get_by_name (string_view name) noexcept |
Returns the type object with the given name name . More... | |
static method | get_global_method (string_view name) noexcept |
Returns a global method with the name name . More... | |
static method | get_global_method (string_view name, const std::vector< type > ¶ms) noexcept |
Returns a global method with the name name which match the given parameter list params . More... | |
static array_range< method > | get_global_methods () noexcept |
Returns a range of all registered global methods. More... | |
static array_range< property > | get_global_properties () noexcept |
Returns a range of all registered global properties. More... | |
static property | get_global_property (string_view name) noexcept |
Returns a global property with the name name . More... | |
static variant | get_property_value (string_view name) |
Returns the property value of property named name . More... | |
static array_range< type > | get_types () noexcept |
Returns a range of all registered type objects. More... | |
static variant | invoke (string_view 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... | |
template<typename T > | |
static void | register_equal_comparator () |
Register the equal comparison operators for template type T . More... | |
template<typename T > | |
static void | register_less_than_comparator () |
Register the less than comparison operators for template type T . More... | |
template<typename T > | |
static void | register_wrapper_converter_for_base_classes () |
Register for all base classes of the giving type T wrapper converter functions. More... | |
static bool | set_property_value (string_view 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) noexcept |
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(string_view)
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 uintptr_t rttr::type::type_id |
Constructor & Destructor Documentation
|
noexcept |
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.
|
noexcept |
Destroys the contained object in the variant obj
.
- Remarks
- When the
obj
could be destroyed the givenobj
is invalid after calling this method; Otherwise it is still valid.
- Returns
- True if the destructor of the object could be invoked, otherwise false.
|
staticnoexcept |
Returns a type object for the given template type T.
- Returns
- type for the template type T.
|
staticnoexcept |
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.
|
noexcept |
Returns a range of all base 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. Accordingly the root (or parent or base) class is always the first type in the list.
- Returns
- A range of types.
|
staticnoexcept |
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
.
|
noexcept |
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.
|
noexcept |
Returns a range of all registered public constructors for this type.
- Remarks
- In order to retrieve private constructors, use type::get_constructors(filter_items) const with following filter combination
filter_item::instance_item | filter_item::static_item | filter_item::non_public_access
The constructors are sorted after its order of registration.
- Returns
- A range of constructors.
|
noexcept |
Returns a range of all registered constructors for this type, based on the given filter
.
The base classes are not included in the search.
Combine the enum values inside filter_item with the OR operator to return a certain range of constructors.
See following example code:
- Remarks
- The properties are sorted after its order of registration.
- Returns
- A range of properties.
|
noexcept |
Returns a range 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 range of type objects.
|
noexcept |
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.
|
noexcept |
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.
|
staticnoexcept |
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
.
|
staticnoexcept |
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
.
|
staticnoexcept |
Returns a range of all registered global methods.
- Remarks
- The order of the methods in the range is undefined. Client code should not depend on the order in which methods are returned, because that order varies.
- Returns
- A range of methods.
|
staticnoexcept |
Returns a range of all registered global properties.
- Remarks
- The order of the properties in the range is undefined. Client code should not depend on the order in which properties are returned, because that order varies.
- Returns
- A range of properties.
|
staticnoexcept |
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
.
|
noexcept |
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.
|
noexcept |
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
.
|
noexcept |
|
noexcept |
Returns a range of all registered public methods for this type and all its base classes.
- Remarks
- In order to retrieve private methods, use type::get_methods(filter_items) const with following filter combination
filter_item::instance_item | filter_item::static_item | filter_item::non_public_access
The methods are sorted after its order of registration.
- Returns
- A range of methods.
|
noexcept |
Returns a range of all registered methods for this type, based on the given filter
.
The base classes are included in the search.
Combine the enum values inside filter_item with the OR operator to return a certain range of methods.
See following example code:
- Remarks
- The methods are sorted after its order of registration.
- Returns
- A range of methods.
|
noexcept |
Returns the unique and human-readable name of the type.
- Remarks
- The content of this string is compiler depended.
- Returns
- The type name.
|
noexcept |
Returns a range of all registered public properties for this type and all its base classes.
- Remarks
- In order to retrieve private properties, use type::get_properties(filter_items) const with following filter combination
filter_item::instance_item | filter_item::static_item | filter_item::non_public_access
The properties are sorted after its order of registration.
- Returns
- A range of properties.
|
noexcept |
Returns a range of all registered properties for this type, based on the given filter
.
The base classes are included in the search.
Combine the enum values inside filter_item with the OR operator to return a certain range of properties.
See following example code:
- Remarks
- The properties are sorted after its order of registration.
- Returns
- A range of properties.
|
noexcept |
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
.
variant rttr::type::get_property_value | ( | string_view | name, |
instance | obj | ||
) | const |
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.
|
noexcept |
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.
|
noexcept |
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.
|
noexcept |
Returns a list of type objects that represents the template arguments.
An empty list is returned when this type is not an instantiation of a template or contains no template arguments at all.
See following example code:
- Returns
- A list of nested types.
- See also
- is_template_instantiation()
|
staticnoexcept |
Returns a range of all registered type objects.
- Remarks
- The order of the type object is unspecified.
- Returns
- A range of type objects.
|
noexcept |
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.
variant rttr::type::invoke | ( | string_view | name, |
instance | obj, | ||
std::vector< argument > | args | ||
) | const |
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.
|
static |
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.
|
noexcept |
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.
|
noexcept |
Returns true
whether the given type represents an array.
An array is always also a sequential container. The check will return true
only for raw C-Style arrays:
- Returns
true
if the type is an array, otherwisefalse
.
- See also
- is_sequential_container()
|
noexcept |
Returns true whether the given type represents an associative container.
- Returns
- True if the type is an associative container, otherwise false.
- See also
- associative_container_mapper<T>
|
noexcept |
Returns true if this type is the base class 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 base class type from
other
, otherwise false.
|
noexcept |
Returns true if this type is the base class 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 base class type from T, otherwise false.
|
noexcept |
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.
|
noexcept |
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.
|
noexcept |
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.
|
noexcept |
Returns true whether the given type represents an enumeration.
- Returns
- True if the type is an enumeration, otherwise false.
|
noexcept |
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.
|
noexcept |
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.
|
noexcept |
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.
|
noexcept |
Returns true whether the given type represents a pointer.
e.g. int*
, or bool*
- Returns
- True if the type is a pointer, otherwise false.
|
noexcept |
Returns true whether the given type represents an sequence container.
- Returns
- True if the type is an sequential container, otherwise false.
- See also
- sequential_container_mapper<T>
|
noexcept |
Returns true whether the given type is an instantiation of a class template.
See following example code:
- Returns
true
if the type is a class template, otherwisefalse
.
- See also
- get_template_arguments()
|
noexcept |
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.
|
noexcept |
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.
|
explicitnoexcept |
|
noexcept |
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.
|
noexcept |
Comparison operator for sorting the type data according to some internal criterion.
- Returns
- True if this type is less than the other.
|
noexcept |
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.
|
noexcept |
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.
|
noexcept |
Comparison operator for sorting the type data according to some internal criterion.
- Returns
- True if this type is greater than the other.
|
noexcept |
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()
|
static |
Register the equal comparison operators for template type T
.
This requires a valid operator==
for type T
.
The registered comparison operators will be used in the variant class.
See following example code:
- See also
- variant::operator==()
|
static |
Register the less than comparison operators for template type T
.
This requires a valid operator<
for type T
.
The registered comparison operators will be used in the variant class.
See following example code:
- See also
- variant::operator<()
|
static |
Register for all base classes of the giving type T
wrapper converter functions.
The converters are registered in both directions respectively. From derived to base class and vice versa.
See following example code:
- See also
- variant::convert(), wrapper_mapper<T>
bool rttr::type::set_property_value | ( | string_view | name, |
instance | obj, | ||
argument | arg | ||
) | const |
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: