1#ifndef CPP_PROPERTY_HPP
2#define CPP_PROPERTY_HPP
19 struct remove_reference
25 struct remove_reference<T&>
37 struct remove_const<const T>
43 template <
typename ValueT,
typename CValueT>
44 struct flag_chooser_helper
46 static const property_flag::e_property_flag flag = property_flag::rw;
49 template <
typename ValueT>
50 struct flag_chooser_helper<ValueT, ValueT>
52 static const property_flag::e_property_flag flag = property_flag::ro;
55 template <
typename ValueT>
56 struct flag_chooser_helper<ValueT, void>
58 static const property_flag::e_property_flag flag = property_flag::wo;
62 struct flag_chooser_helper<void, void>
68 public flag_chooser_helper<T1, const T1>
73 struct flag_chooser<T1&> :
74 public flag_chooser_helper<T1, const T1>
80 template<
typename ValueT,
typename ParentT>
81 struct get_parent_func
83 typedef ValueT value_t;
84 typedef ParentT parent_t;
85 typedef value_t(parent_t::* getter_t)()
const;
86 typedef void(parent_t::* setter_t)(value_t);
88 static const getter_t &default_getter() {
static getter_t getter = getter_t(0);
return getter;}
89 static const setter_t &default_setter() {
static setter_t setter = setter_t(0);
return setter;}
93 struct get_parent_func<void, void>
96 typedef Void parent_t;
97 typedef const int getter_t;
98 typedef const int setter_t;
100 static const getter_t &default_getter() {
static getter_t getter = 0;
return getter;}
101 static const setter_t &default_setter() {
static setter_t setter = 0;
return setter;}
104 template<
typename ValueT>
105 struct get_parent_func<ValueT, void>:
106 public get_parent_func<void, void>
110 template<
typename ParentT>
111 struct get_parent_func<void, ParentT> :
112 public get_parent_func<void, void>
118 template<
class ValueT = void,
119 const detail::property_flag::e_property_flag Flag = (
const detail::property_flag::e_property_flag)(detail::flag_chooser<ValueT>::flag)>
124 class property<void, detail::property_flag::ro>:
125 public detail::property_flag
128 typedef detail::property_flag flags;
132 class property<void, detail::property_flag::wo>:
133 public detail::property_flag
136 typedef detail::property_flag flags;
140 class property<void, detail::property_flag::rw>:
141 public detail::property_flag
144 typedef detail::property_flag flags;
148 template<
typename ValueT>
149 class property<ValueT, detail::property_flag::ro>
151 typedef typename detail::remove_const<typename detail::remove_reference<ValueT>::type>::type value_t;
154 template<class ParentT, typename detail::get_parent_func<ValueT, ParentT>::getter_t Getter>
157 typedef typename detail::get_parent_func<ValueT, ParentT>::value_t value_t;
160 bind(ParentT *parent) :
164 inline value_t get()
const
166 return (_obj->*Getter)();
169 inline operator value_t()
const {
return get(); }
171 inline value_t operator()(
void)
const {
return get(); }
176 bind(
const bind &rhs);
178 inline bind &operator=(
typename detail::remove_const<
typename detail::remove_reference<ValueT>::type>::type
const &);
179 inline bind &operator=(bind
const &);
182 property(value_t
const &value) :
186 inline const value_t &get()
const
191 inline operator const value_t&()
const {
return get(); }
193 inline const value_t& operator()(
void)
const {
return get(); }
201 inline property &operator=(value_t
const &);
202 inline property &operator=(property
const &);
206 template<
typename ValueT>
207 class property<ValueT, detail::property_flag::rw>
209 typedef typename detail::remove_reference<ValueT>::type value_t;
213 template<class ParentT, typename detail::get_parent_func<ValueT, ParentT>::getter_t Getter,
typename detail::get_parent_func<ValueT, ParentT>::setter_t Setter>
216 typedef typename detail::get_parent_func<ValueT, ParentT>::value_t value_t;
219 bind(ParentT *parent) :
223 inline void set(value_t value)
225 (_obj->*Setter)(value);
228 inline value_t get()
const
230 return (_obj->*Getter)();
233 inline operator value_t()
const {
return get(); }
235 inline bind &operator=(bind
const &) {
return *
this;}
236 inline bind &operator=(value_t value) { set(value);
return *
this; }
238 inline value_t operator()(
void)
const {
return get(); }
240 inline void operator()(value_t value) { set(value);
return *
this; }
246 bind(
const bind &rhs);
252 property(ValueT value) :
256 inline void set(value_t
const &value)
261 inline value_t &get()
const
266 inline property &operator=(value_t
const &value) { set(value);
return *
this; }
268 inline operator value_t&()
const {
return get(); }
270 inline value_t operator()(
void)
const {
return get(); }
272 inline void operator()(value_t
const &value) { set(value); }
280 template<
typename ValueT>
281 class property<ValueT, detail::property_flag::wo>
283 typedef typename detail::remove_reference<ValueT>::type value_t;
287 template<class ParentT, typename detail::get_parent_func<ValueT, ParentT>::setter_t Setter>
290 typedef typename detail::get_parent_func<ValueT, ParentT>::value_t value_t;
293 bind(ParentT *parent) :
297 inline void set(value_t value)
299 (_obj->*Setter)(value);
302 inline bind &operator=(bind
const &) {
return *
this;}
303 inline bind &operator=(value_t value) { set(value);
return *
this; }
305 inline void operator()(value_t value) { set(value);
return *
this; }
309 bind(
const bind &rhs);
315 property(ValueT value) :
319 inline void set(value_t
const &value)
324 inline property &operator=(value_t
const &value) { set(value);
return *
this; }
326 inline void operator()(value_t
const &value) { set(value); }