Metadata

Adding additional meta information to properties or methods can be very useful. So for instance, it allows to add ToolTips or the information what kind of editor should be created in the GUI. You can also tag certain properties to make only those available in a scripting engine which has a certain key set.

The metadata consists of a key and a value, both objects are forwarded to variants. So the only requirement for metadata is that it has to be copyable.

Please take a look at following example:

#include <rttr/registration>
enum class MetaData_Type
{
SCRIPTABLE,
GUI
};
{
using namespace rttr;
registration::property("value", &g_Value)
(
metadata(MetaData_Type::SCRIPTABLE, false),
metadata("Description", "This is a value.")
);
}

In order to add metadata to a registered item you have to use the () operator of the returned bind object. Then you call for every metadata item you want to add, the function metadata().

It has following synopsis:

This will register a global property named "value" with two metadata informations. The first use an enum type as key, the second a string.

And the following snippet shows, how to retrieve this information:

int main()
{
using namespace rttr;
property prop = type::get_global_property("value");
variant value = prop.get_metadata(MetaData_Type::SCRIPTABLE);
std::cout << value.get_value<bool>(); // prints "false"
value = prop.get_metadata("Description");
std::cout << value.get_value<std::string>(); // prints "This is a value."
}

Every property, method, enumeration and constructor can have metadata.


Definition: access_levels.h:33
detail::metadata metadata(variant key, variant value)
The metadata function can be used to add additional meta data information during the registration pro...
detail::enum_data< Enum_Type > value(string_view, Enum_Type value)
The value function should be used to add a mapping from enum name to value during the registration pr...
#define RTTR_REGISTRATION
Use this macro to automatically register your reflection information to RTTR before main is called.
Definition: registration.h:770
The variant class allows to store data of any type and convert between these types transparently.
Definition: variant.h:222
static property get_global_property(string_view name) noexcept
Returns a global property with the name name.
static bind< detail::prop, detail::invalid_type, A, detail::public_access > property(string_view name, A acc)
Register a global property with read write access.