28 #ifndef __RTTR_PROPERTY_CONTAINER_MEMBER_FUNC_H__
29 #define __RTTR_PROPERTY_CONTAINER_MEMBER_FUNC_H__
35 template<
typename Getter,
typename Setter>
36 class property_container<member_func_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;
40 using class_type =
typename function_traits<Getter>::class_type;
43 property_container(
const std::string& name,
const type declaring_type, Getter
get, Setter set)
44 : property_container_base(name, declaring_type),
48 static_assert(function_traits<Getter>::arg_count == 0,
"Invalid number of argument, please provide a getter-member-function without arguments.");
49 static_assert(function_traits<Setter>::arg_count == 1,
"Invalid number of argument, please provide a setter-member-function with exactly one argument.");
50 static_assert(std::is_same<return_type, arg_type>::value,
"Please provide the same signature for getter and setter!");
53 bool is_readonly()
const {
return false; }
54 bool is_static()
const {
return false; }
55 type get_type()
const {
return type::get<return_type>(); }
56 bool is_array()
const {
return detail::is_array<return_type>::value; }
58 bool set_value(detail::instance&
object, detail::argument& arg)
const
60 class_type* ptr =
object.try_convert<class_type>();
61 if (ptr && arg.is_type<arg_type>() )
63 (ptr->*_setter)(arg.get_value<arg_type>());
69 variant get_value(detail::instance&
object)
const
71 if (class_type* ptr =
object.try_convert<class_type>())
72 return variant((ptr->*_getter)());
86 template<
typename Getter>
87 class property_container<member_func_ptr, Getter, void, return_as_copy, read_only> :
public property_container_base
89 using return_type =
typename function_traits<Getter>::return_type;
90 using class_type =
typename function_traits<Getter>::class_type;
93 property_container(
const std::string& name,
const type declaring_type, Getter
get)
94 : property_container_base(name, declaring_type),
97 static_assert(function_traits<Getter>::arg_count == 0,
"Invalid number of argument, please provide a getter-member-function without arguments.");
100 bool is_readonly()
const {
return false; }
101 bool is_static()
const {
return false; }
102 type get_type()
const {
return type::get<return_type>(); }
103 bool is_array()
const {
return detail::is_array<return_type>::value; }
105 bool set_value(detail::instance&
object, detail::argument& arg)
const
110 variant get_value(detail::instance&
object)
const
112 if (class_type* ptr =
object.try_convert<class_type>())
113 return variant((ptr->*_getter)());
127 template<
typename Getter,
typename Setter>
128 class property_container<member_func_ptr, Getter, Setter, return_as_ptr, set_as_ptr> :
public property_container_base
130 using return_type =
typename function_traits<Getter>::return_type;
131 using arg_type =
typename param_types<Setter, 0>::type;
132 using class_type =
typename function_traits<Getter>::class_type;
135 property_container(
const std::string& name,
const type declaring_type, Getter
get, Setter set)
136 : property_container_base(name, declaring_type),
140 static_assert(function_traits<Getter>::arg_count == 0,
"Invalid number of argument, please provide a getter-member-function without arguments.");
141 static_assert(function_traits<Setter>::arg_count == 1,
"Invalid number of argument, please provide a setter-member-function with exactly one argument.");
142 static_assert(std::is_same<return_type, arg_type>::value,
"Please provide the same signature for getter and setter!");
144 static_assert(std::is_reference<return_type>::value,
"Please provide a getter-member-function with a reference as return value!");
145 static_assert(std::is_reference<arg_type>::value,
"Please provide a setter-member-function with a reference as return value!");
148 bool is_readonly()
const {
return false; }
149 bool is_static()
const {
return false; }
150 type get_type()
const {
return type::get<typename std::remove_reference<return_type>::type*>(); }
151 bool is_array()
const {
return detail::is_array<return_type>::value; }
153 bool set_value(detail::instance&
object, detail::argument& arg)
const
155 using arg_type =
typename std::remove_reference<arg_type>::type;
156 class_type* ptr =
object.try_convert<class_type>();
157 if (ptr && arg.is_type<arg_type*>())
159 (ptr->*_setter)(*arg.get_value<arg_type*>());
165 variant get_value(detail::instance&
object)
const
167 if (class_type* ptr =
object.try_convert<class_type>())
168 return variant(&(ptr->*_getter)());
183 template<
typename Getter>
184 class property_container<member_func_ptr, Getter, void, return_as_ptr, read_only> :
public property_container_base
186 using return_type =
typename function_traits<Getter>::return_type;
187 using class_type =
typename function_traits<Getter>::class_type;
190 property_container(
const std::string& name,
const type declaring_type, Getter
get)
191 : property_container_base(name, declaring_type),
194 static_assert(function_traits<Getter>::arg_count == 0,
"Invalid number of argument, please provide a getter-member-function without arguments.");
195 static_assert(std::is_reference<return_type>::value,
"Please provide a getter-member-function with a reference as return value!");
198 bool is_readonly()
const {
return true; }
199 bool is_static()
const {
return false; }
200 type get_type()
const {
return type::get<typename std::remove_reference<return_type>::type*>(); }
201 bool is_array()
const {
return detail::is_array<return_type>::value; }
203 bool set_value(detail::instance&
object, detail::argument& arg)
const
208 variant get_value(detail::instance&
object)
const
210 if (class_type* ptr =
object.try_convert<class_type>())
211 return variant(&(ptr->*_getter)());
220 #endif // __RTTR_PROPERTY_CONTAINER_MEMBER_FUNC_H__