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 | |
access_levels | get_access_level () const noexcept |
Returns the access level with which this property was registered. More... | |
type | get_declaring_type () const noexcept |
Returns the type of the class or struct that declares this property. More... | |
enumeration | get_enumeration () const noexcept |
Returns the enumerator if this property is an enum type; otherwise the returned value is not valid. More... | |
variant | get_metadata (const variant &key) const |
Returns the meta data for the given key key . More... | |
string_view | get_name () const noexcept |
Returns the name of this property. More... | |
type | get_type () const noexcept |
Returns the underlying type object of this property. More... | |
variant | get_value (instance object) const |
Returns the current property value of the given instance object . More... | |
bool | is_enumeration () const noexcept |
Returns true if the underlying property is an enumeration. More... | |
bool | is_readonly () const noexcept |
Returns true if this property is read only, otherwise false. More... | |
bool | is_static () const noexcept |
Returns true if this property is static property, otherwise false. More... | |
bool | is_valid () const noexcept |
Returns true if this property is valid, otherwise false. More... | |
operator bool () const noexcept | |
Convenience function to check if this property is valid or not. More... | |
bool | operator!= (const property &other) const noexcept |
Returns true if this property is the not the same like the other . More... | |
bool | operator== (const property &other) const noexcept |
Returns true if this property is the same like the other . More... | |
bool | set_value (instance object, argument arg) const |
Set the property of the given instance object to the given value arg . More... | |
Detailed Description
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 registration::class_<T>::property() and for global properties see registration::property().
Meta Information
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 an empty instance object, use therefore the default ctor of instance(), or as shortcut use simply {}
.
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.
Copying and Assignment
A property object is lightweight and can be copied by value. However, each copy will refer to the same underlying property.
Typical Usage
- See also
- method, enumeration, constructor and type
Member Function Documentation
|
noexcept |
Returns the access level with which this property was registered.
- Remarks
- When the property is not valid, this function will return level access_levels::public_access.
- Returns
- access_levels of the property.
|
noexcept |
Returns the type of the class or struct that declares this property.
- Remarks
- When this property does not belong to a class (i.e. is a global property) it will return an invalid type object. When this property is not valid, this function will return an invalid type object (see type::is_valid).
- Returns
- Type of the declaring class/struct for this property.
|
noexcept |
Returns the enumerator if this property is an enum type; otherwise the returned value is not valid.
- See also
- is_enumeration()
- Returns
- An enumeration object.
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 the name of this property.
- Remarks
- When the property is not valid, this function will return an empty string_view.
- Returns
- Name of the property.
|
noexcept |
Returns the current property value of the given instance object
.
- Remarks
- When the property is static, you can forward an empty instance.
- See also
- set_value().
- Returns
- The property value of the given instance
object
.
|
noexcept |
Returns true if the underlying property is an enumeration.
- Remarks
- When the property is not valid, this function will return false.
- Returns
- True if this is a enumeration type, otherwise false.
|
noexcept |
Returns true if this property is read only, otherwise false.
- Remarks
- When the property is not valid, this function will return false.
- Returns
- True if this is a read only property, otherwise false.
|
noexcept |
Returns true if this property is static property, otherwise false.
A static property does not need an instance for performing set_value/get_value.
- Remarks
- When the property is not valid, this function will return false.
- Returns
- True if this is a static property, otherwise false.
|
noexcept |
Returns true if this property is valid, otherwise false.
- Returns
- True if this property is valid, otherwise false.
|
explicitnoexcept |
Convenience function to check if this property is valid or not.
- Returns
- True if this property is valid, otherwise false.
|
noexcept |
Returns true if this property is the not the same like the other
.
- Returns
- True if both properties are different, otherwise false.
|
noexcept |
Returns true if this property is the same like the other
.
- Returns
- True if both properties are equal, otherwise false.
Set the property of the given instance object
to the given value arg
.
- Remarks
- When the property is declared as read only this function will return false. When you have a static property just pass an empty instance as object argument. When the property is not valid, this function will return false.
- See also
- get_value().
- Returns
- The return value indicates whether the operation was successful or not.
The documentation for this class was generated from the following file: