5#include "system/shared_ptr.h"
17template<
typename S,
typename T>
31template <
typename G,
typename S>
46template <
typename G,
typename S>
61template <
typename G,
typename S>
76template <
typename G,
typename S>
87#define PROP_ASSIGN_LAMBDA_WRAP(name, op) \
88 template <typename G, typename S, typename T> \
89 auto setter_##name##_wrap(G&& getter, S&& setter, T value) \
91 auto tmp = getter(); \
97PROP_ASSIGN_LAMBDA_WRAP(add, + )
98PROP_ASSIGN_LAMBDA_WRAP(sub, - )
99PROP_ASSIGN_LAMBDA_WRAP(mul, * )
100PROP_ASSIGN_LAMBDA_WRAP(div, / )
101PROP_ASSIGN_LAMBDA_WRAP(mod, % )
102PROP_ASSIGN_LAMBDA_WRAP(shl, << )
103PROP_ASSIGN_LAMBDA_WRAP(shr, >> )
104PROP_ASSIGN_LAMBDA_WRAP(and, & )
105PROP_ASSIGN_LAMBDA_WRAP(or, | )
106PROP_ASSIGN_LAMBDA_WRAP(exor, ^ )
111#define SETTER_LVAL_LAMBDA(capture, prop) \
112 [obj = capture](const auto& v){ obj->set_##prop(v); }
116#define GETTER_LVAL_LAMBDA(capture, prop) \
117 [obj = capture]{ return obj->get_##prop(); }
121#if __GNUC__ > 5 && __GNUC__ < 7
122#define SETTER_LAMBDA(capture, prop) \
123 SETTER_LVAL_LAMBDA(capture, prop)
125#define SETTER_LAMBDA(capture, prop) \
126 [&obj = capture](const auto& v){ obj->set_##prop(v); }
131#if __GNUC__ > 5 && __GNUC__ < 7
132#define GETTER_LAMBDA(capture, prop) \
133 GETTER_LVAL_LAMBDA(capture, prop)
135#define GETTER_LAMBDA(capture, prop) \
136 [&obj = capture]{ return obj->get_##prop(); }
141#define SETTER_REF_LAMBDA(capture, prop) \
142 [&obj = capture](const auto& v){ obj.set_##prop(v); }
146#define GETTER_REF_LAMBDA(capture, prop) \
147 [&obj = capture]{ return obj.get_##prop(); }
150#define SETTER_THIS_LAMBDA(prop) \
151 [this](const auto& v){ this->set_##prop(v); }
154#define GETTER_THIS_LAMBDA(prop) \
155 [this]{ return this->get_##prop(); }
159#define STATIC_SETTER_LAMBDA(T, prop) \
160 [](const auto& v){ T::set_##prop(v); }
164#define STATIC_GETTER_LAMBDA(T, prop) \
165 []{ return T::get_##prop(); }
169#define GETTER_SETTER_LAMBDA_ARGS(capture, prop) \
170 GETTER_LAMBDA(capture, prop), SETTER_LAMBDA(capture, prop)
173#define GETTER_SETTER_THIS_LAMBDA_ARGS(prop) \
174 GETTER_THIS_LAMBDA(prop), SETTER_THIS_LAMBDA(prop)
178#define GETTER_SETTER_REF_LAMBDA_ARGS(capture, prop) \
179 GETTER_REF_LAMBDA(capture, prop), SETTER_REF_LAMBDA(capture, prop)
183#define GETTER_SETTER_LVAL_LAMBDA_ARGS(capture, prop) \
184 GETTER_LVAL_LAMBDA(capture, prop), SETTER_LVAL_LAMBDA(capture, prop)
188#define STATIC_GETTER_SETTER_LAMBDA_ARGS(T, prop) \
189 STATIC_GETTER_LAMBDA(T, prop), STATIC_SETTER_LAMBDA(T, prop)
196#define SETTER_LAMBDA_OP_WRAP(T, obj, prop, op, val) \
197 setter_##op##_wrap(GETTER_SETTER_LAMBDA_ARGS(obj, prop), val)
201#define INDEXED_SETTER_LAMBDA(capture) \
202 [&obj = capture](auto&& index, auto&& value){ obj->idx_set(index, value); }
205#define INDEXED_GETTER_LAMBDA(capture) \
206 [&obj = capture](auto&& index){ return obj->idx_get(index); }
210#define INDEXED_GETTER_SETTER_ARGS(capture, arg) \
211 INDEXED_GETTER_LAMBDA(capture), INDEXED_SETTER_LAMBDA(capture), [&](){ return arg; }
215#define INDEXED_ASSIGN_LAMBDA_WRAP(name, op) \
216 template <typename G, typename S, typename I, typename T> \
217 void indexed_##name##_wrap(G&& getter, S&& setter, I&& indexer, T&& value) \
219 const auto index = indexer(); \
220 auto tmp = getter(index); \
222 setter(index, tmp); \
225INDEXED_ASSIGN_LAMBDA_WRAP(add, +=)
226INDEXED_ASSIGN_LAMBDA_WRAP(sub, -=)
227INDEXED_ASSIGN_LAMBDA_WRAP(mul, *=)
228INDEXED_ASSIGN_LAMBDA_WRAP(div, /=)
229INDEXED_ASSIGN_LAMBDA_WRAP(mod, %=)
230INDEXED_ASSIGN_LAMBDA_WRAP(shl, <<=)
231INDEXED_ASSIGN_LAMBDA_WRAP(shr, >>=)
232INDEXED_ASSIGN_LAMBDA_WRAP(and, &=)
233INDEXED_ASSIGN_LAMBDA_WRAP(or , |=)
234INDEXED_ASSIGN_LAMBDA_WRAP(exor, ^=)
243template <typename T, typename T2>
259template <
typename T,
typename T2,
typename Host,
typename HostSet>
260inline typename std::enable_if<std::is_base_of<HostSet, Host>::value, T>::type
261 setter_wrap(Host*
const host,
void (HostSet::*pSetter)(T2), T value)
263 (host->*pSetter)(value);
292template <
typename T,
typename Host,
typename HostGet,
typename HostSet>
293inline typename std::enable_if<std::is_base_of<HostGet, Host>::value && std::is_base_of<HostSet, Host>::value, T>::type
296 T tmp = (host->*pGetter)();
297 (host->*pSetter)(++tmp);
311template <
typename T,
typename Host,
typename HostGet,
typename HostSet>
312inline typename std::enable_if<std::is_base_of<HostGet, Host>::value && std::is_base_of<HostSet, Host>::value, T>::type
315 T tmp = (host->*pGetter)();
316 (host->*pSetter)(++tmp);
330 T tmp = pGetter(), rv = tmp;
346template <
typename T,
typename Host,
typename HostGet,
typename HostSet>
347inline typename std::enable_if<std::is_base_of<HostGet, Host>::value && std::is_base_of<HostSet, Host>::value, T>::type
350 T tmp = (host->*pGetter)(), rv = tmp;
352 (host->*pSetter)(tmp);
366template <
typename T,
typename Host,
typename HostConstGet,
typename HostSet>
367inline typename std::enable_if<std::is_base_of<HostConstGet, Host>::value && std::is_base_of<HostSet, Host>::value, T>::type
370 T tmp = (host->*pGetter)(), rv = tmp;
372 (host->*pSetter)(tmp);
400template <
typename T,
typename Host,
typename HostGet,
typename HostSet>
401inline typename std::enable_if<std::is_base_of<HostGet, Host>::value && std::is_base_of<HostSet, Host>::value, T>::type
404 T tmp = (host->*pGetter)();
405 (host->*pSetter)(--tmp);
418template <
typename T,
typename Host,
typename HostConstGet,
typename HostSet>
419inline typename std::enable_if<std::is_base_of<HostConstGet, Host>::value && std::is_base_of<HostSet, Host>::value, T>::type
422 T tmp = (host->*pGetter)();
423 (host->*pSetter)(--tmp);
437 T tmp = pGetter(), rv = tmp;
452template <
typename T,
typename Host,
typename HostGet,
typename HostSet>
453inline typename std::enable_if<std::is_base_of<HostGet, Host>::value && std::is_base_of<HostSet, Host>::value, T>::type
456 T tmp = (host->*pGetter)(), rv = tmp;
458 (host->*pSetter)(tmp);
471template <
typename T,
typename Host,
typename HostConstGet,
typename HostSet>
472inline typename std::enable_if<std::is_base_of<HostConstGet, Host>::value && std::is_base_of<HostSet, Host>::value, T>::type
475 T tmp = (host->*pGetter)(), rv = tmp;
477 (host->*pSetter)(tmp);
485#define PROP_ASSIGN_WRAP(name, op) \
486 template <typename PropT, typename PropValT> \
487 inline PropT setter_##name##_wrap(PropT (*pGetter)(), void (*pSetter)(PropT), PropValT value) \
489 PropT tmp = pGetter(); \
490 tmp = tmp op value; \
494 template <typename PropT, typename PropValT> \
495 inline PropT setter_##name##_wrap(PropT (*pGetter)(), void (*pSetter)(const PropT&), PropValT value) \
497 PropT tmp = pGetter(); \
498 tmp = tmp op value; \
502 template <typename PropT, typename HostT, typename HostGetT, typename HostSetT, typename PropValT> \
503 inline typename std::enable_if<std::is_base_of<HostGetT, HostT>::value && std::is_base_of<HostSetT, HostT>::value, PropT>::type \
504 setter_##name##_wrap(HostT* const host, PropT (HostGetT::*pGetter)(), void (HostSetT::*pSetter)(PropT), PropValT value) \
506 PropT tmp = (host->*pGetter)(); \
507 tmp = tmp op value; \
508 (host->*pSetter)(tmp); \
511 template <typename PropT, typename HostT, typename HostGetT, typename HostSetT, typename PropValT> \
512 inline typename std::enable_if<std::is_base_of<HostGetT, HostT>::value && std::is_base_of<HostSetT, HostT>::value, PropT>::type \
513 setter_##name##_wrap(HostT* const host, PropT (HostGetT::*pGetter)(), void (HostSetT::*pSetter)(const PropT &), PropValT value) \
515 PropT tmp = (host->*pGetter)(); \
516 tmp = tmp op value; \
517 (host->*pSetter)(tmp); \
520 template <typename PropT, typename HostT, typename HostGetT, typename HostSetT, typename PropValT> \
521 inline typename std::enable_if<std::is_base_of<HostGetT, HostT>::value && std::is_base_of<HostSetT, HostT>::value, PropT>::type \
522 setter_##name##_wrap(HostT* const host, PropT (HostGetT::*pGetter)() const, void (HostSetT::*pSetter)(PropT), PropValT value) \
524 PropT tmp = (host->*pGetter)(); \
525 tmp = tmp op value; \
526 (host->*pSetter)(tmp); \
529 template <typename PropT, typename HostT, typename HostGetT, typename HostSetT, typename PropValT> \
530 inline typename std::enable_if<std::is_base_of<HostGetT, HostT>::value && std::is_base_of<HostSetT, HostT>::value, PropT>::type \
531 setter_##name##_wrap(HostT* const host, PropT (HostGetT::*pGetter)() const, void (HostSetT::*pSetter)(const PropT &), PropValT value) \
533 PropT tmp = (host->*pGetter)(); \
534 tmp = tmp op value; \
535 (host->*pSetter)(tmp); \
539PROP_ASSIGN_WRAP(add, + )
540PROP_ASSIGN_WRAP(sub, - )
541PROP_ASSIGN_WRAP(mul, * )
542PROP_ASSIGN_WRAP(div, / )
543PROP_ASSIGN_WRAP(mod, % )
544PROP_ASSIGN_WRAP(shl, << )
545PROP_ASSIGN_WRAP(shr, >> )
546PROP_ASSIGN_WRAP(and, & )
547PROP_ASSIGN_WRAP(or, | )
548PROP_ASSIGN_WRAP(exor, ^ )
556#define SETTER_OP_WRAP(T, obj, prop, op, val) \
557 setter_##op##_wrap(obj, &T::get_##prop, &T::set_##prop, val)
auto setter_decrement_wrap(G &&getter, S &&setter)
Translator translates C#'s decrement expressions targeting class' property that has setter and getter...
Definition: setters_wrap.h:62
T setter_wrap(S &&setter, T value)
Wrapper function to wrap calling setter method and returning set value (normally, set methods do not ...
Definition: setters_wrap.h:18
auto setter_post_decrement_wrap(G &&getter, S &&setter)
Translator translates C#'s post-decrement expressions targeting a class' property that has a setter a...
Definition: setters_wrap.h:77
auto setter_increment_wrap(G &&getter, S &&setter)
Translator translates C#'s increment expressions targeting class' property that has setter and getter...
Definition: setters_wrap.h:32
auto setter_post_increment_wrap(G &&getter, S &&setter)
Translator translates C#'s post-increment expressions targeting class' property that has setter and g...
Definition: setters_wrap.h:47
Definition: db_command.h:9