cleanup-2008 2690: Make meta-functions work with thru morpher.

https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena/sandbox Index: ChangeLog from Alexandre Abraham <abraham@lrde.epita.fr> Make meta-functions work with thru morpher. * abraham/tests/fun/meta/red.cc: Update example. * abraham/mln/core/image/thru.hh: . * abraham/mln/core/image/shell.hh: Fix result value. * abraham/mln/core/concept/meta_fun.hh: (mln::meta::impl) : now templated by return type (necessary to typedef result). * abraham/mln/fun/meta/red.hh: . mln/core/concept/meta_fun.hh | 28 +++++++++++---------------- mln/core/image/shell.hh | 44 ++++++++++++++++++++++++++++++++++++++++--- mln/core/image/thru.hh | 2 - mln/fun/meta/red.hh | 5 +--- tests/fun/meta/red.cc | 8 +++++-- 5 files changed, 62 insertions(+), 25 deletions(-) Index: abraham/tests/fun/meta/red.cc --- abraham/tests/fun/meta/red.cc (revision 2689) +++ abraham/tests/fun/meta/red.cc (working copy) @@ -14,8 +14,10 @@ }; template <class T> - struct function< meta::red, rgb<T> > : public Function_v2w_w2v<function< meta::red, rgb<T> > > + struct function< meta::red< rgb<T> > > : public Function_v2w_w2v<function< meta::red < rgb<T> > > > { + typedef rgb<T> value; + typedef T result; T read(const rgb<T>& c) { @@ -50,7 +52,9 @@ c.r = 1; i(mln::point2d(2,1)) = c; - mln::thru<mln::meta::red, mln::image2d<C> > out(i); + mln::thru<mln::meta::red <C>, mln::image2d<C> > out(i); + + mln_piter_(mln::image2d<C>) p(i.domain()); for_all (p) std::cout << out(p) << std::endl; Index: abraham/mln/core/image/thru.hh --- abraham/mln/core/image/thru.hh (revision 2689) +++ abraham/mln/core/image/thru.hh (working copy) @@ -89,7 +89,7 @@ typedef mln_result(F) rvalue; /// Return type of read-write access. - typedef shell<F,I> lvalue; + typedef shell<F,I> lvalue; // FIXME : if I is const or F is Function_v2v, there is no shell /// Skeleton. typedef thru< tag::value_<mln_result(F)>, tag::image_<I> > skeleton; Index: abraham/mln/core/image/shell.hh --- abraham/mln/core/image/shell.hh (revision 2689) +++ abraham/mln/core/image/shell.hh (working copy) @@ -57,7 +57,7 @@ template <typename F, typename I> struct shell : shell_write<F, I, typename F::category> // FIXME : inherit of value_base or sth? { - typedef mln_value(I) value; + typedef typename F::result value; // Ctor shell(Image<I> &ima, const mln_site(I) &s); @@ -66,7 +66,14 @@ operator value (); // Write - mln_value(I) operator= (typename F::result); + value operator= (value); + + // << + // std::ostream& operator<<(std::ostream& ostr); + + // >> + // std::istream& operator>>(std::istream& istr); + protected : I &ima; @@ -92,9 +99,10 @@ // Write for everyone template <typename F, typename I> - mln_value(I) shell<F, I>::operator= (typename F::result v) + typename F::result shell<F, I>::operator= (typename F::result v) { set_(ima, s, v); + return v; } template <typename F, typename I> @@ -111,6 +119,36 @@ return ima(s); } +// template <typename F, typename I> +// std::ostream& shell<F, I>::operator<<(std::ostream& ostr) +// { +// ostr << ima(s); +// return ostr; +// } + +// template <typename F, typename I> +// std::istream& shell<F, I>::operator>>(std::istream& istr) +// { +// ima(s) >> istr; +// return istr; +// } + + template <typename F, typename I> + std::ostream& operator<<(std::ostream& ostr, shell<F, I> &s) + { + ostr << (typename shell<F, I>::value) s; + return ostr; + } + + template <typename F, typename I> + std::istream& operator>>(std::istream& istr, shell<F, I> &s) + { + (typename shell<F, I>::value) s >> istr; + return istr; + } + + + # endif // MLN_INCLUDE_ONLY }; // end of namespace mln Index: abraham/mln/core/concept/meta_fun.hh --- abraham/mln/core/concept/meta_fun.hh (revision 2689) +++ abraham/mln/core/concept/meta_fun.hh (working copy) @@ -39,7 +39,7 @@ namespace mln { - template <class M, class T> + template <class M> struct function; namespace meta @@ -49,27 +49,23 @@ struct impl { - template <class T> - struct info - { - typedef function<M, T> F; + typedef function<M> F; + typedef typename F::value value; typedef typename F::result result; typedef typename F::lresult lresult; - }; + typedef typename F::category category; - template <class T> - typename info<T>::result - operator()(const T& t) const + result + operator()(const value& t) const { - function<M,T> f; + F f; return f.read(t); } - template <class T> - T& - f_1(typename info<T>::result v, T& t) + value& + f_1(result v, value& t) { - function<M,T> f; + F f; f.write(t) = v; return t; } Index: abraham/mln/fun/meta/red.hh --- abraham/mln/fun/meta/red.hh (revision 2689) +++ abraham/mln/fun/meta/red.hh (working copy) @@ -34,12 +34,11 @@ namespace meta { - struct red : impl<red> { }; + template <class T> + struct red : impl< red<T> > { typedef T value; }; }; - meta::red red; // fun obj - }; #endif // MLN_FUN_META_RED_HH
participants (1)
-
Alexandre Abraham