rttr::policy::prop Struct Reference

The prop class groups all policies that can be used during registration of properties. More...

#include <policy.h>

Static Public Attributes

static const detail::as_reference_wrapper as_reference_wrapper
 The as_reference_wrapper policy will bind a member object as std::reference_wrapper type. More...
 
static const detail::bind_as_ptr bind_as_ptr
 The bind_as_ptr policy will bind a member object as pointer type. More...
 

Detailed Description

The prop class groups all policies that can be used during registration of properties.

Member Data Documentation

◆ as_reference_wrapper

const detail::as_reference_wrapper rttr::policy::prop::as_reference_wrapper
static

The as_reference_wrapper policy will bind a member object as std::reference_wrapper type.

This can be useful when binding big data types, like arrays, to avoid copies during get/set of the property.

See following example code:

using namespace rttr;
struct Foo
{
std::vector<int> vec;
};
{
.property("vec", &Foo::vec)
(
);
}
int main()
{
Foo obj;
property prop = type::get<Foo>().get_property("vec");
variant var = prop.get_value(obj);
std::cout << var.is_type<std::reference_wrapper<std::vector<int>>>(); // prints "true"
prop.set_value(obj, var); // not really necessary, but remark that now a std::reference_wrapper<std::vector<int>> is expected
return 0;
}

◆ bind_as_ptr

const detail::bind_as_ptr rttr::policy::prop::bind_as_ptr
static

The bind_as_ptr policy will bind a member object as pointer type.

This can be useful when binding big data types, like arrays, to avoid copies during get/set of the property.

See following example code:

using namespace rttr;
struct Foo
{
std::vector<int> vec;
};
{
.property("vec", &Foo::vec)
(
);
}
int main()
{
Foo obj;
property prop = type::get<Foo>().get_property("vec");
variant var = prop.get_value(obj);
std::cout << var.is_type<std::vector<int>*>(); // prints "true"
prop.set_value(obj, var); // not really necessary, but remark that now a std::vector<int>* is expected
return 0;
}

The documentation for this struct was generated from the following file:
bind< detail::prop, Class_Type, A, acc_level > property(string_view name, A acc, acc_level level=acc_level())
Register a property to this class.
bool is_type() const
Returns true if the containing variant data is of the given template type T.
Definition: access_levels.h:32
static const detail::as_reference_wrapper as_reference_wrapper
The as_reference_wrapper policy will bind a member object as std::reference_wrapper type.
Definition: policy.h:240
The class_ is used to register classes to RTTR.
Definition: registration.h:152
#define RTTR_REGISTRATION
Use this macro to automatically register your reflection information to RTTR before main is called.
Definition: registration.h:768
T & get_value()
Returns a reference to the containing value as type T.
The variant class allows to store data of any type and convert between these types transparently.
Definition: variant.h:220
static const detail::bind_as_ptr bind_as_ptr
The bind_as_ptr policy will bind a member object as pointer type.
Definition: policy.h:205