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.")
);
}
The array_range class provides a view into an underlying data structure with lower and upper limits.
Definition array_range.h:64
Definition access_levels.h:34
#define RTTR_REGISTRATION
Use this macro to automatically register your reflection information to RTTR before main is called.
Definition registration.h:745

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:

rttr::detail::metadata rttr::metadata( variant key, variant value );
The variant class allows to store data of any type and convert between these types transparently.
Definition variant.h:199
detail::metadata metadata(variant key, variant value)
The metadata function can be used to add additional meta data information during the registration pro...

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.