27 #ifndef MLN_CORE_CONCEPT_PROXY_HH
28 # define MLN_CORE_CONCEPT_PROXY_HH
40 # include <mln/core/concept/object.hh>
41 # include <mln/value/ops.hh>
43 # include <mln/convert/from_to.hxx>
44 # include <mln/core/concept/proxy.hxx>
47 # define mln_decl_unop_proxy(Name, Symb) \
49 template <typename P> \
50 mln_trait_op_##Name(P) \
51 operator Symb (const Proxy<P>& rhs); \
53 struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_u_m_n
56 # define mln_def_unop_proxy(Name, Symb) \
58 template <typename P> \
60 mln_trait_op_##Name(P) \
61 operator Symb (const mln::Proxy<P>& rhs) \
63 return Symb exact(rhs).unproxy_(); \
66 struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_u_m_n
72 # define mln_decl_binop_proxy(Name, Symb) \
74 template <typename L, typename R> \
75 mln_trait_op_##Name(L, R) \
76 operator Symb (const Proxy<L>& lhs, const Proxy<R>& rhs); \
78 template <typename P, typename O> \
79 mln_trait_op_##Name(P, O) \
80 operator Symb (const Proxy<P>& p, const Object<O>& o); \
82 template <typename O, typename P> \
83 mln_trait_op_##Name(O, P) \
84 operator Symb (const Object<O>& o, const Proxy<P>& p); \
86 struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_u_m_n
90 # define mln_def_binop_proxy(Name, Symb) \
92 template <typename L, typename R> \
94 mln_trait_op_##Name(L, R) \
95 operator Symb (const mln::Proxy<L>& lhs, const mln::Proxy<R>& rhs) \
97 typedef typename internal::helper_unprox_binop<L, R>::L_helper L_helper; \
98 typedef typename internal::helper_unprox_binop<L, R>::R_helper R_helper; \
99 return L_helper::on(lhs) Symb R_helper::on(rhs); \
102 template <typename P, typename O> \
104 mln_trait_op_##Name(P, O) \
105 operator Symb (const Proxy<P>& p, const Object<O>& o) \
107 return exact(p).unproxy_() Symb exact(o); \
110 template <typename O, typename P> \
112 mln_trait_op_##Name(O, P) \
113 operator Symb (const Object<O>& o, const Proxy<P>& p) \
115 return exact(o) Symb exact(p).unproxy_(); \
118 template <typename P, typename L> \
120 mln_trait_op_##Name(P, L) \
121 operator Symb (const Proxy<P>& p, const Literal<L>& l) \
123 return exact(p).unproxy_() Symb exact(l); \
126 template <typename L, typename P> \
128 mln_trait_op_##Name(L, P) \
129 operator Symb (const Literal<L>& l, const Proxy<P>& p) \
131 return exact(l) Symb exact(p).unproxy_(); \
134 struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_u_m_n
143 template <
typename E>
struct Proxy;
144 template <
typename E>
struct Literal;
152 template <
template <
class>
class Op,
typename P >
153 struct set_unary_< Op, mln::Proxy, P >
155 typedef mlc_unqualif(mln_q_subject(P)) S;
156 typedef mln_trait_unary(Op, S)
ret;
161 template < template <class, class> class Op,
162 typename L, typename R >
163 struct set_binary_< Op, mln::Proxy, L, mln::Proxy, R >
165 typedef mln::internal::helper_unprox_binop<L, R> helper;
166 typedef mln_trait_binary(Op,
167 typename helper::L_ret,
168 typename helper::R_ret) ret;
171 template < template <class, class> class Op,
172 typename P, typename O >
173 struct set_binary_< Op, mln::Proxy, P, mln::Object, O >
175 typedef mlc_unqualif(mln_q_subject(P)) S;
176 typedef mln_trait_binary(Op, S, O) ret;
179 template < template <class, class> class Op,
180 typename O, typename P >
181 struct set_binary_< Op, mln::Object, O, mln::Proxy, P >
183 typedef mlc_unqualif(mln_q_subject(P)) S;
184 typedef mln_trait_binary(Op, O, S) ret;
190 template < template <class, class> class Op,
191 typename P, typename L >
192 struct set_binary_< Op, mln::Proxy, P, mln::Literal, L >
194 typedef mlc_unqualif(mln_q_subject(P)) S;
195 typedef mln_trait_binary(Op, S, L) ret;
198 template < template <class, class> class Op,
199 typename L, typename P >
200 struct set_binary_< Op, mln::Literal, L, mln::Proxy, P >
202 typedef mlc_unqualif(mln_q_subject(P)) S;
203 typedef mln_trait_binary(Op, L, S) ret;
226 template <
typename E>
227 struct Proxy : Object<E>
246 template <
typename P,
typename T>
254 template <
typename T>
257 typedef typename mln::internal::unproxy_rec_<T>::ret
q_ret;
264 template <typename
T>
265 typename mln::internal::unproxy_rec_<
T>::ret
268 template <typename
T>
269 typename mln::internal::unproxy_rec_<const
T>::ret
275 template <typename P>
276 std::ostream& operator<<(std::ostream& ostr, const Proxy<P>&
p);
281 mln_decl_unop_proxy(uplus, + );
282 mln_decl_unop_proxy(uminus, - );
283 mln_decl_unop_proxy(preinc, ++ );
284 mln_decl_unop_proxy(predec, -- );
285 mln_decl_unop_proxy(not, ! );
287 mln_decl_binop_proxy(
plus, + );
288 mln_decl_binop_proxy(
minus, - );
289 mln_decl_binop_proxy(times, * );
290 mln_decl_binop_proxy(div, / );
291 mln_decl_binop_proxy(mod, % );
293 mln_decl_binop_proxy(eq, == );
294 mln_decl_binop_proxy(neq, != );
296 mln_decl_binop_proxy(less, < );
297 mln_decl_binop_proxy(leq, <= );
298 mln_decl_binop_proxy(geq, >= );
299 mln_decl_binop_proxy(greater, > );
301 mln_decl_binop_proxy(and, && );
302 mln_decl_binop_proxy(or, || );
303 mln_decl_binop_proxy(xor, ^ );
307 # ifndef MLN_INCLUDE_ONLY
312 template <
typename E>
316 enum { proxy_level = E::proxy_level };
318 typedef typename E::q_subject q_subject;
320 q_subject (E::*m_)() = & E::subj_;
328 template <
typename P,
typename T>
338 template <
typename T>
340 typename mln::internal::unproxy_rec_<T>::ret
343 return mln::internal::unproxy_rec_<T>::on(t);
346 template <
typename T>
348 typename mln::internal::unproxy_rec_<const T>::ret
351 return mln::internal::unproxy_rec_<const T>::on(t);
357 template <
typename P>
359 std::ostream& operator<<(std::ostream& ostr, const Proxy<P>&
p)
367 mln_def_unop_proxy(uplus, + );
368 mln_def_unop_proxy(uminus, - );
369 mln_def_unop_proxy(preinc, ++ );
370 mln_def_unop_proxy(predec, -- );
371 mln_def_unop_proxy(not, ! );
376 mln_def_binop_proxy(plus, + );
377 mln_def_binop_proxy(minus, - );
378 mln_def_binop_proxy(times, * );
379 mln_def_binop_proxy(div, / );
380 mln_def_binop_proxy(mod, % );
382 mln_def_binop_proxy(eq, == );
383 mln_def_binop_proxy(neq, != );
385 mln_def_binop_proxy(less, < );
386 mln_def_binop_proxy(leq, <= );
387 mln_def_binop_proxy(geq, >= );
388 mln_def_binop_proxy(greater, > );
390 mln_def_binop_proxy(and, && );
391 mln_def_binop_proxy(or, || );
392 mln_def_binop_proxy(xor, ^ );
395 # endif // ! MLN_INCLUDE_ONLY
400 #endif // ! MLN_CORE_CONCEPT_PROXY_HH