28 #ifndef __RTTR_PROPERTY_CONTAINER_FUNC_H__
29 #define __RTTR_PROPERTY_CONTAINER_FUNC_H__
35 template<
typename Getter,
typename Setter>
36 class property_container<function_ptr, Getter, Setter, return_as_copy, set_value> :
public property_container_base
38 using return_type =
typename function_traits<Getter>::return_type;
39 using arg_type =
typename param_types<Setter, 0>::type;
42 property_container(
const std::string& name,
const type declaring_type, Getter getter, Setter setter)
43 : property_container_base(name, declaring_type),
47 static_assert(function_traits<Getter>::arg_count == 0,
"Invalid number of argument, please provide a getter-function without arguments.");
48 static_assert(function_traits<Setter>::arg_count == 1,
"Invalid number of argument, please provide a setter-function with exactly one argument.");
49 static_assert(std::is_same<return_type, arg_type>::value,
"Please provide the same signature for getter and setter!");
52 bool is_readonly()
const {
return false; }
53 bool is_static()
const {
return true; }
54 type get_type()
const {
return type::get<return_type>(); }
55 bool is_array()
const {
return detail::is_array<return_type>::value; }
57 bool set_value(detail::instance&
object, detail::argument& arg)
const
59 if (arg.is_type<arg_type>())
61 _setter(arg.get_value<arg_type>());
67 variant get_value(detail::instance&
object)
const
69 return variant(_getter());
81 template<
typename Getter>
82 class property_container<function_ptr, Getter, void, return_as_copy, read_only> :
public property_container_base
84 using return_type =
typename function_traits<Getter>::return_type;
87 property_container(
const std::string& name,
const type declaring_type, Getter func)
88 : property_container_base(name, declaring_type),
91 static_assert(function_traits<Getter>::arg_count == 0,
"Invalid number of argument, please provide a getter-function without arguments.");
94 bool is_readonly()
const {
return true; }
95 bool is_static()
const {
return true; }
96 type get_type()
const {
return type::get<return_type>(); }
97 bool is_array()
const {
return detail::is_array<return_type>::value; }
99 bool set_value(detail::instance&
object, detail::argument& arg)
const
104 variant get_value(detail::instance&
object)
const
106 return (variant(_accessor()));
119 template<
typename Getter,
typename Setter>
120 class property_container<function_ptr, Getter, Setter, return_as_ptr, set_as_ptr> :
public property_container_base
122 using return_type =
typename function_traits<Getter>::return_type;
123 using arg_type =
typename param_types<Setter, 0>::type;
126 property_container(
const std::string& name,
const type declaring_type, Getter getter, Setter setter)
127 : property_container_base(name, declaring_type),
131 static_assert(std::is_reference<return_type>::value,
"Please provide a getter-function with a reference as return value!");
132 static_assert(std::is_reference<arg_type>::value,
"Please provide a setter-function with a reference as argument!");
134 static_assert(function_traits<Getter>::arg_count == 0,
"Invalid number of argument, please provide a getter-function without arguments.");
135 static_assert(function_traits<Setter>::arg_count == 1,
"Invalid number of argument, please provide a setter-function with exactly one argument.");
137 static_assert(std::is_same<return_type, arg_type>::value,
"Please provide the same signature for getter and setter!");
140 bool is_readonly()
const {
return false; }
141 bool is_static()
const {
return true; }
142 type get_type()
const {
return type::get<typename std::remove_reference<return_type>::type*>(); }
143 bool is_array()
const {
return detail::is_array<return_type>::value; }
145 bool set_value(detail::instance&
object, detail::argument& arg)
const
147 using arg_type =
typename std::remove_reference<arg_type>::type;
148 if (arg.is_type<arg_type*>())
150 _setter(*arg.get_value<arg_type*>());
156 variant get_value(detail::instance&
object)
const
158 return variant(&(_getter()));
170 template<
typename Getter>
171 class property_container<function_ptr, Getter, void, return_as_ptr, read_only> :
public property_container_base
173 using return_type =
typename function_traits<Getter>::return_type;
175 property_container(
const std::string& name,
const type declaring_type, Getter func)
176 : property_container_base(name, declaring_type),
179 static_assert(std::is_reference<return_type>::value,
"Please provide a function with a reference as return value!");
182 bool is_readonly()
const {
return true; }
183 bool is_static()
const {
return true; }
184 type get_type()
const {
return type::get<typename std::add_const<typename std::remove_reference<return_type>::type>::type*>(); }
185 bool is_array()
const {
return detail::is_array<return_type>::value; }
187 bool set_value(detail::instance&
object, detail::argument& arg)
const
192 variant get_value(detail::instance&
object)
const
194 return (variant(
const_cast<const typename std::remove_reference<return_type>::type*
>(&(_accessor()))));
202 #endif // __RTTR_PROPERTY_CONTAINER_FUNC_H__