26 #ifndef MLN_CORE_CONCEPT_PROXY_HH
27 # define MLN_CORE_CONCEPT_PROXY_HH
39 # include <mln/core/concept/object.hh>
40 # include <mln/value/ops.hh>
42 # include <mln/convert/from_to.hxx>
43 # include <mln/core/concept/proxy.hxx>
46 # define mln_decl_unop_proxy(Name, Symb) \
48 template <typename P> \
49 mln_trait_op_##Name(P) \
50 operator Symb (const Proxy<P>& rhs); \
52 struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_u_m_n
55 # define mln_def_unop_proxy(Name, Symb) \
57 template <typename P> \
59 mln_trait_op_##Name(P) \
60 operator Symb (const mln::Proxy<P>& rhs) \
62 return Symb exact(rhs).unproxy_(); \
65 struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_u_m_n
71 # define mln_decl_binop_proxy(Name, Symb) \
73 template <typename L, typename R> \
74 mln_trait_op_##Name(L, R) \
75 operator Symb (const Proxy<L>& lhs, const Proxy<R>& rhs); \
77 template <typename P, typename O> \
78 mln_trait_op_##Name(P, O) \
79 operator Symb (const Proxy<P>& p, const Object<O>& o); \
81 template <typename O, typename P> \
82 mln_trait_op_##Name(O, P) \
83 operator Symb (const Object<O>& o, const Proxy<P>& p); \
85 struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_u_m_n
89 # define mln_def_binop_proxy(Name, Symb) \
91 template <typename L, typename R> \
93 mln_trait_op_##Name(L, R) \
94 operator Symb (const mln::Proxy<L>& lhs, const mln::Proxy<R>& rhs) \
96 typedef typename internal::helper_unprox_binop<L, R>::L_helper L_helper; \
97 typedef typename internal::helper_unprox_binop<L, R>::R_helper R_helper; \
98 return L_helper::on(lhs) Symb R_helper::on(rhs); \
101 template <typename P, typename O> \
103 mln_trait_op_##Name(P, O) \
104 operator Symb (const Proxy<P>& p, const Object<O>& o) \
106 return exact(p).unproxy_() Symb exact(o); \
109 template <typename O, typename P> \
111 mln_trait_op_##Name(O, P) \
112 operator Symb (const Object<O>& o, const Proxy<P>& p) \
114 return exact(o) Symb exact(p).unproxy_(); \
117 template <typename P, typename L> \
119 mln_trait_op_##Name(P, L) \
120 operator Symb (const Proxy<P>& p, const Literal<L>& l) \
122 return exact(p).unproxy_() Symb exact(l); \
125 template <typename L, typename P> \
127 mln_trait_op_##Name(L, P) \
128 operator Symb (const Literal<L>& l, const Proxy<P>& p) \
130 return exact(l) Symb exact(p).unproxy_(); \
133 struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_u_m_n
142 template <
typename E>
struct Proxy;
143 template <
typename E>
struct Literal;
149 template <
typename F,
typename T>
150 void from_to(
const F& from, T&
to);
161 template <
template <
class>
class Op,
typename P >
162 struct set_unary_< Op, mln::Proxy, P >
164 typedef mlc_unqualif(mln_q_subject(P)) S;
165 typedef mln_trait_unary(Op, S) ret;
170 template < template <class, class> class Op,
171 typename L, typename R >
172 struct set_binary_< Op, mln::Proxy, L, mln::Proxy, R >
174 typedef mln::internal::helper_unprox_binop<L, R> helper;
175 typedef mln_trait_binary(Op,
176 typename helper::L_ret,
177 typename helper::R_ret) ret;
180 template < template <class, class> class Op,
181 typename P, typename O >
182 struct set_binary_< Op, mln::Proxy, P, mln::Object, O >
184 typedef mlc_unqualif(mln_q_subject(P)) S;
185 typedef mln_trait_binary(Op, S, O) ret;
188 template < template <class, class> class Op,
189 typename O, typename P >
190 struct set_binary_< Op, mln::Object, O, mln::Proxy, P >
192 typedef mlc_unqualif(mln_q_subject(P)) S;
193 typedef mln_trait_binary(Op, O, S) ret;
199 template < template <class, class> class Op,
200 typename P, typename L >
201 struct set_binary_< Op, mln::Proxy, P, mln::Literal, L >
203 typedef mlc_unqualif(mln_q_subject(P)) S;
204 typedef mln_trait_binary(Op, S, L) ret;
207 template < template <class, class> class Op,
208 typename L, typename P >
209 struct set_binary_< Op, mln::Literal, L, mln::Proxy, P >
211 typedef mlc_unqualif(mln_q_subject(P)) S;
212 typedef mln_trait_binary(Op, L, S) ret;
231 template <
typename E>
232 struct Proxy : Object<E>
255 template <
typename P,
typename T>
257 from_to_(
const Proxy<P>& from, T& to);
267 template <
typename T>
270 typedef typename mln::internal::unproxy_rec_<T>::ret q_ret;
271 typedef mlc_unqualif(q_ret) ret;
277 template <typename T>
278 typename mln::internal::unproxy_rec_<T>::ret
281 template <typename T>
282 typename mln::internal::unproxy_rec_<const T>::ret
283 unproxy_rec(const T& t);
288 template <typename P>
289 std::ostream& operator<<(std::ostream& ostr, const Proxy<P>& p);
294 mln_decl_unop_proxy(uplus, + );
295 mln_decl_unop_proxy(uminus, - );
296 mln_decl_unop_proxy(preinc, ++ );
297 mln_decl_unop_proxy(predec, -- );
298 mln_decl_unop_proxy(not, ! );
300 mln_decl_binop_proxy(plus, + );
301 mln_decl_binop_proxy(minus, - );
302 mln_decl_binop_proxy(times, * );
303 mln_decl_binop_proxy(div, / );
304 mln_decl_binop_proxy(mod, % );
306 mln_decl_binop_proxy(eq, == );
307 mln_decl_binop_proxy(neq, != );
309 mln_decl_binop_proxy(less, < );
310 mln_decl_binop_proxy(leq, <= );
311 mln_decl_binop_proxy(geq, >= );
312 mln_decl_binop_proxy(greater, > );
314 mln_decl_binop_proxy(and, && );
315 mln_decl_binop_proxy(or, || );
316 mln_decl_binop_proxy(xor, ^ );
320 # ifndef MLN_INCLUDE_ONLY
325 template <
typename E>
329 enum { proxy_level = E::proxy_level };
331 typedef typename E::q_subject q_subject;
333 q_subject (E::*m_)() = & E::subj_;
347 template <
typename P,
typename T>
349 from_to_(
const Proxy<P>& from, T& to)
351 convert::from_to(exact(from).unproxy_(), to);
361 template <
typename T>
363 typename mln::internal::unproxy_rec_<T>::ret
366 return mln::internal::unproxy_rec_<T>::on(t);
369 template <
typename T>
371 typename mln::internal::unproxy_rec_<const T>::ret
372 unproxy_rec(
const T& t)
374 return mln::internal::unproxy_rec_<const T>::on(t);
380 template <
typename P>
382 std::ostream& operator<<(std::ostream& ostr, const Proxy<P>& p)
384 return ostr << unproxy_rec(p);
390 mln_def_unop_proxy(uplus, + );
391 mln_def_unop_proxy(uminus, - );
392 mln_def_unop_proxy(preinc, ++ );
393 mln_def_unop_proxy(predec, -- );
394 mln_def_unop_proxy(not, ! );
399 mln_def_binop_proxy(plus, + );
400 mln_def_binop_proxy(minus, - );
401 mln_def_binop_proxy(times, * );
402 mln_def_binop_proxy(div, / );
403 mln_def_binop_proxy(mod, % );
405 mln_def_binop_proxy(eq, == );
406 mln_def_binop_proxy(neq, != );
408 mln_def_binop_proxy(less, < );
409 mln_def_binop_proxy(leq, <= );
410 mln_def_binop_proxy(geq, >= );
411 mln_def_binop_proxy(greater, > );
413 mln_def_binop_proxy(and, && );
414 mln_def_binop_proxy(or, || );
415 mln_def_binop_proxy(xor, ^ );
418 # endif // ! MLN_INCLUDE_ONLY
423 #endif // ! MLN_CORE_CONCEPT_PROXY_HH