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) 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< typeget_base_classes () const noexcept
 Returns a range of all base classes of this type. More...
 
constructor get_constructor (const std::vector< type > &params=std::vector< type >()) const noexcept
 Returns a public constructor whose parameters match the types in the specified list. More...
 
array_range< constructorget_constructors () const noexcept
 Returns a range of all registered public constructors for this type. More...
 
array_range< constructorget_constructors (filter_items filter) const noexcept
 Returns a range of all registered constructors for this type, based on the given filter. More...
 
array_range< typeget_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< methodget_methods () const noexcept
 Returns a range of all registered public methods for this type and all its base classes. More...
 
array_range< methodget_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< propertyget_properties () const noexcept
 Returns a range of all registered public properties for this type and all its base classes. More...
 
array_range< propertyget_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...
 
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_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_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...
 
typeoperator= (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 > &params) noexcept
 Returns a global method with the name name which match the given parameter list params. More...
 
static array_range< methodget_global_methods () noexcept
 Returns a range of all registered global methods. More...
 
static array_range< propertyget_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< typeget_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...
 
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<int>() == type::get<int>(); // yields to true
type::get<int>() == type::get<bool>(); // yields to false

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.

type::get_by_name("int") == type::get<int>(); // yields to true
type::get_by_name("bool") == type::get<int>(); // yields to false
type::get_by_name("MyNameSpace::MyStruct") == type::get<MyNameSpace::MyStruct>(); // yields to true
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.

int int_obj;
int* int_obj_ptr = &int_obj;
const int* c_int_obj_ptr = int_obj_ptr;
type::get<int>() == type::get(int_obj); // yields to true
type::get<int*>() == type::get(int_obj_ptr); // yields to true
type::get<const int*>() == type::get(c_int_obj_ptr); // yields to true

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.

struct Base { RTTR_ENABLE() };
struct Derived : Base { RTTR_ENABLE(Base) };
//...
Derived d;
Base& base = d;
type::get<Derived>() == type::get(base); // yields to true
type::get<Base>() == type::get(base); // yields to false
// remark, when called with pointers:
Base* base_ptr = &d;
type::get<Derived>() == type::get(base_ptr); // yields to false
type::get<Base*>() == type::get(base_ptr); // yields to true
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.
class D { ... };
D d1;
const D d2;
type::get(d1) == type::get(d2); // yields true
type::get<D>() == type::get<const D>(); // yields true
type::get<D>() == type::get(d2); // yields true
type::get<D>() == type::get<const D&>(); // yields true
type::get<D>() == type::get<const D*>(); // yields false

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)
noexcept

Assigns a type to another one.

Member Function Documentation

variant rttr::type::create ( std::vector< argument args = std::vector< argument >()) const

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.
bool rttr::type::destroy ( variant obj) const
noexcept

Destroys the contained object in the variant obj.

Remarks
When the obj could be destroyed the given obj is invalid after calling this method; Otherwise it is still valid.
Returns
True if the destructor of the object could be invoked, otherwise false.
template<typename T >
static type rttr::type::get ( )
staticnoexcept

Returns a type object for the given template type T.

Returns
type for the template type T.
template<typename T >
static type rttr::type::get ( T &&  object)
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.
array_range<type> rttr::type::get_base_classes ( ) const
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.
static type rttr::type::get_by_name ( string_view  name)
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.
constructor rttr::type::get_constructor ( const std::vector< type > &  params = std::vector< type >()) const
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.
array_range<constructor> rttr::type::get_constructors ( ) const
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.
array_range<constructor> rttr::type::get_constructors ( filter_items  filter) const
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:

#include <rttr/registration>
struct my_struct { my_struct() {} my_struct(int) {} my_struct(bool) {} RTTR_ENABLE() };
{
.constructor<>() ( policy::ctor::as_object )
.constructor<int>() ( policy::ctor::as_object );
}
int main()
{
type t = rttr::type::get<my_struct>();
for (auto& ctor : t.get_constructors())
std::cout << ctor.get_signature() << ", "; // prints "my_struct( ), my_struct( int ),"
std::cout << std::endl;
for (auto& ctor : t.get_constructors(filter_item::instance_item | filter_item::non_public_access))
std::cout << ctor.get_signature() << ", "; // prints "my_struct( bool ),"
std::cout << std::endl;
for (auto& ctor : t.get_constructors(filter_item::static_item | filter_item::non_public_access))
std::cout << ctor.get_signature() << ", "; // prints "my_struct( bool ),"
std::cout << std::endl;
std::cout << ctor.get_signature() << std::endl; // prints "my_struct( ), my_struct( int ),"
return 0;
}
Remarks
The properties are sorted after its order of registration.
Returns
A range of properties.
array_range<type> rttr::type::get_derived_classes ( ) const
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.
destructor rttr::type::get_destructor ( ) const
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.
enumeration rttr::type::get_enumeration ( ) const
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.
static method rttr::type::get_global_method ( string_view  name)
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.
static method rttr::type::get_global_method ( string_view  name,
const std::vector< type > &  params 
)
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 list params, then an invalid method is returned.
Returns
A method with name name and parameter signature params.
static array_range<method> rttr::type::get_global_methods ( )
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.
static array_range<property> rttr::type::get_global_properties ( )
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.
static property rttr::type::get_global_property ( string_view  name)
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.
type_id rttr::type::get_id ( ) const
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.
variant rttr::type::get_metadata ( const variant key) const

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 ( string_view  name) const
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.
method rttr::type::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.

Remarks
When there exists no method with the name name and matching parameter type list type_list, then an invalid method is returned.
Returns
A method with name name.
array_range<method> rttr::type::get_methods ( ) const
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.
array_range<method> rttr::type::get_methods ( filter_items  filter) const
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:

#include <rttr/registration>
struct base { void func_1() {} void func_2() {} RTTR_ENABLE() };
struct derived : base { void func_3() {} static void func_4() {} RTTR_ENABLE(base) };
{
.method("func_1", &base::func_1)
.method("func_2", &base::func_2, rttr::registration::private_access);
.method("func_3", &derived::func_3)
.method("func_4", &derived::func_4, rttr::registration::private_access);
}
int main()
{
type t = rttr::type::get<derived>();
for (auto& meth : t.get_methods())
std::cout << meth.get_name() << ", "; // prints "func_1, func_3,"
std::cout << std::endl;
for (auto& meth : t.get_methods(filter_item::instance_item | filter_item::non_public_access))
std::cout << meth.get_name() << ", "; // prints "func_2,"
std::cout << std::endl;
for (auto& meth : t.get_methods(filter_item::static_item | filter_item::non_public_access))
std::cout << meth.get_name() << ", "; // prints "func_4,"
std::cout << std::endl;
std::cout << meth.get_name() << ", "; // prints "func_3,"
return 0;
}
Remarks
The methods are sorted after its order of registration.
Returns
A range of methods.
string_view rttr::type::get_name ( ) const
noexcept

Returns the unique and human-readable name of the type.

Remarks
The content of this string is compiler depended.
Returns
The type name.
array_range<property> rttr::type::get_properties ( ) const
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.
array_range<property> rttr::type::get_properties ( filter_items  filter) const
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:

#include <rttr/registration>
struct base { int p1, p2; RTTR_ENABLE() };
struct derived : base { int p3; static const int p4 = 23; RTTR_ENABLE(base) };
{
.property("p1", &base::p1)
.property("p3", &derived::p3)
}
int main()
{
type t = rttr::type::get<derived>();
for (auto& prop : t.get_properties())
std::cout << prop.get_name() << ", "; // prints "p1, p3,"
std::cout << std::endl;
for (auto& prop : t.get_properties(filter_item::instance_item | filter_item::non_public_access))
std::cout << meth.get_name() << ", "; // prints "p2,"
std::cout << std::endl;
for (auto& prop : t.get_properties(filter_item::static_item | filter_item::non_public_access))
std::cout << meth.get_name() << ", "; // prints "p4,"
std::cout << std::endl;
std::cout << meth.get_name() << ", "; // prints "p3"
return 0;
}
Remarks
The properties are sorted after its order of registration.
Returns
A range of properties.
property rttr::type::get_property ( string_view  name) const
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 variant rttr::type::get_property_value ( string_view  name)
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
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.
std::size_t rttr::type::get_sizeof ( ) const
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.
static array_range<type> rttr::type::get_types ( )
staticnoexcept

Returns a range of all registered type objects.

Remarks
The order of the type object is unspecified.
Returns
A range of type objects.
type rttr::type::get_wrapped_type ( ) const
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:

type wrapped_type = type::get<std::shared_ptr<int>>().get_wrapped_type();
wrapped_type == type::get<int*>(); // yields to true
wrapped_type = type::get<std::reference_wrapper<int>>().get_wrapped_type();
wrapped_type == type::get<int>(); // yields to true
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 variant rttr::type::invoke ( string_view  name,
std::vector< argument args 
)
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.
bool rttr::type::is_arithmetic ( ) const
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.
bool rttr::type::is_array ( ) const
noexcept

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_associative_container ( ) const
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>
bool rttr::type::is_class ( ) const
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.
bool rttr::type::is_derived_from ( const type other) const
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.
template<typename T >
bool rttr::type::is_derived_from ( ) const
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.
bool rttr::type::is_enumeration ( ) const
noexcept

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
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.
bool rttr::type::is_member_function_pointer ( ) const
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.
bool rttr::type::is_member_object_pointer ( ) const
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.
bool rttr::type::is_pointer ( ) const
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.
bool rttr::type::is_valid ( ) const
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.
bool rttr::type::is_wrapper ( ) const
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.
rttr::type::operator bool ( ) const
explicitnoexcept

Convenience function to check if this type is valid or not.

Returns
True if this type is valid, otherwise false.
bool rttr::type::operator!= ( const type other) const
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.
bool rttr::type::operator< ( const type other) const
noexcept

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
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.
type& rttr::type::operator= ( const type other)
noexcept

Assigns a type to another one.

Returns
A type object.
bool rttr::type::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.

Returns
True if both type are equal, otherwise false.
bool rttr::type::operator> ( const type other) const
noexcept

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
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.
template<typename T >
static void rttr::type::register_comparators ( )
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:

// two variants, same content
variant a = std::make_tuple<int, std::string>(12, std::string("some text"));
variant b = std::make_tuple<int, std::string>(12, std::string("some text"));
a == b; // yields to false
// register comparators for type 'std::tuple<std::string, int>'
type::register_comparators<std::tuple<std::string, int>>();
a == b; // yields to true
See also
variant::operator==(), variant::operator<()
template<typename F >
static void rttr::type::register_converter_func ( func)
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:

std::string conv_func(int value, bool& ok)
{
std::string result = std::to_string(value);
ok = true;
return result;
}
// register the conversion function
See also
variant::convert()
template<typename T >
static void rttr::type::register_equal_comparator ( )
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:

// two variants, same content
variant a = std::make_tuple<int, int>(42, 42);
variant b = std::make_tuple<int, int>(42, 42);
a == b; // yields to false
// register comparators for type 'std::tuple<int, int>'
type::register_comparators<std::tuple<int, int>>();
a == b; // yields to true
See also
variant::operator==()
template<typename T >
static void rttr::type::register_less_than_comparator ( )
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:

struct my_id
{
my_id(int i) : id(i) {}
bool operator<(const foo& rhs) const { return (id < rhs.id); }
int id;
};
// two variants, same content
variant a = my_id(23);
variant b = my_id(42);
a < b; // yields to false
// register comparators for type 'my_id'
type::register_less_than_comparator<my_id>();
a < b; // yields to true
See also
variant::operator<()
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 bool rttr::type::set_property_value ( string_view  name,
argument  arg 
)
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

template<typename Target_Type , typename Source_Type >
Target_Type rttr_cast ( Source_Type  object)
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 and Target_Type must be both pointer types.
Returns
A pointer of type Target_Type

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