The property class provides several meta information about a property and gives read/write access to its value. More...
#include <property.h>
Public Member Functions | |
type | get_declaring_type () const |
Returns the type of the class or struct that declares this property. More... | |
enumeration | get_enumeration () const |
Returns the enumerator if this property is an enum type; otherwise the returned value is not valid. More... | |
variant | get_metadata (int key) const |
Returns the metadata for the given key key . More... | |
variant | get_metadata (const std::string &key) const |
Returns the metadata for the given key key . More... | |
std::string | get_name () const |
Returns the name of this property. More... | |
type | get_type () const |
Returns the underlying type object of this property. More... | |
variant | get_value (detail::instance object) const |
Returns the current property value of the given instance object . More... | |
bool | is_array () const |
Returns true if the underlying property is an array. More... | |
bool | is_enumeration () const |
Returns true if the underlying property is an enumeration. More... | |
bool | is_readonly () const |
Returns true if this property is read only, otherwise false. More... | |
bool | is_static () const |
Returns true if this property is static property, otherwise false. More... | |
bool | is_valid () const |
Returns true if this property is valid, otherwise false. More... | |
operator bool () const | |
Convenience function to check if this property is valid or not. More... | |
bool | operator!= (const property &other) const |
Returns true if this property is the not the same like the other . More... | |
bool | operator== (const property &other) const |
Returns true if this property is the same like the other . More... | |
bool | set_value (detail::instance object, detail::argument arg) const |
Set the property of the given instance object to the given value arg . More... | |
The property class provides several meta information about a property and gives read/write access to its value.
A instance of a property class can only be obtained from the type class. See type::get_property() and type::get_properties().
For registration a property, nested inside a class, see class_::property_() and for global properties see property_.
A property has a name, and a type as well as attributes that specify its behavior: is_readonly(), is_static(), is_enumeration(), is_array(). When the property was declared inside a class, then get_declaring_type() can be used to obtain the type of this class.
The property's values are set and retrieved with set_value() and get_value(); When its not a static property you have to provide a class instance to set/get the property value. This instance can be the raw type on the stack; the current hierarchy level doesn't matter. It can be also a raw pointer to the object or a variant which contains the instance, again as pointer or stack object. When the property is declared as static you you still have to provide a dummy instance object, therefore the function rttr::empty_instance()
should be used.
A property will be successfully set when the provided instance can be converted to the declared class type. The new forwarded property value must 100% match the type of the registered property. An automatically type conversion is not performed.
The return type of get_value() is variant object. This object contains not only the value of the property, it also indicates whether the property value could be retrieved or not. A valid variant object means, that the property was successfully retrieved, otherwise not.
Another way to get access a property is through type's set and get functions. See type::set_property_value() and type::get_property_value() for details.
A property object is lightweight and can be copied by value. However, each copy will refer to the same underlying property.
type rttr::property::get_declaring_type | ( | ) | const |
Returns the type of the class or struct that declares this property.
enumeration rttr::property::get_enumeration | ( | ) | const |
Returns the enumerator if this property is an enum type; otherwise the returned value is not valid.
variant rttr::property::get_metadata | ( | int | key | ) | const |
Returns the metadata for the given key key
.
key
, an invalid variant object is returned (see variant::is_valid).variant rttr::property::get_metadata | ( | const std::string & | key | ) | const |
Returns the metadata for the given key key
.
key
, an invalid variant object is returned (see variant::is_valid).std::string rttr::property::get_name | ( | ) | const |
Returns the name of this property.
type rttr::property::get_type | ( | ) | const |
variant rttr::property::get_value | ( | detail::instance | object | ) | const |
Returns the current property value of the given instance object
.
object
. bool rttr::property::is_array | ( | ) | const |
Returns true if the underlying property is an array.
bool rttr::property::is_enumeration | ( | ) | const |
Returns true if the underlying property is an enumeration.
bool rttr::property::is_readonly | ( | ) | const |
Returns true if this property is read only, otherwise false.
bool rttr::property::is_static | ( | ) | const |
Returns true if this property is static property, otherwise false.
A static property does not need an instance for performing set_value/get_value.
bool rttr::property::is_valid | ( | ) | const |
Returns true if this property is valid, otherwise false.
rttr::property::operator bool | ( | ) | const |
Convenience function to check if this property is valid or not.
bool rttr::property::operator!= | ( | const property & | other | ) | const |
Returns true if this property is the not the same like the other
.
bool rttr::property::operator== | ( | const property & | other | ) | const |
Returns true if this property is the same like the other
.
bool rttr::property::set_value | ( | detail::instance | object, |
detail::argument | arg | ||
) | const |
Set the property of the given instance object
to the given value arg
.