For registration of a property to RTTR you can use following functions: registration::property() and registration::property_readonly().
They have following synopsis:
name
is the name of the propertyA
is the pointer to the property
It is also possible to use function pointers for the property as getter and setter functions. Therefore the property() function is overloaded.
It has following synopsis:
name
is the name of the propertyA1
is the function pointer to the getter and A2 is the function pointer to the setter of the property
The following example shows how to use these register functions:
There can be not two global properties with the same name. The later registered property with an already existing name will be discarded.
Invoke properties
For setting and getting a property you have two options like with methods:
- calling type::set_property_value() and type::get_property_value() from the type class or
- retrieving a property object from type::get_global_property() and then calling property::set_value() and property::get_value()
The static type::set_property_value() function calls directly a global property with the given name. This function has a bool value as return value, indicating whether the property was invoked or not. For retrieving a property value use the static function type::get_property_value(). The returned variant object contains the property value and also indicates whether the call to retrieve the property was successful or not. When the variant is not valid then the call could not be done.
Another option is to retrieve a handle to the property via type::get_global_property(). This is the preferred option, because then you directly set/get the value without searching every time for the property. The property object is very lightweight and can be simply copied around different locations. The object stays valid till end of the main()
function.