3046: Add functors.

https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Alexandre Abraham <abraham@lrde.epita.fr> Add functors. * mln/fun/meta: New. * mln/fun/meta/red.hh: red meta accessor. * mln/fun/v2w2v: New. * mln/fun/v2w_w2v: New. core/image/fun_image.hh | 56 +++++++++++++++++++++++++----------------------- fun/meta/red.hh | 20 +++++++++++++++++ 2 files changed, 50 insertions(+), 26 deletions(-) Index: mln/core/image/fun_image.hh --- mln/core/image/fun_image.hh (revision 3045) +++ mln/core/image/fun_image.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -25,13 +25,13 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef MLN_CORE_IMAGE_THRU_HH -# define MLN_CORE_IMAGE_THRU_HH +#ifndef MLN_CORE_IMAGE_FUN_IMAGE_HH +# define MLN_CORE_IMAGE_FUN_IMAGE_HH -/*! \file mln/core/image/thru.hh +/*! \file mln/core/image/fun_image.hh * * \brief Definition of an image morpher that make the user see the - * image thru a function + * image through a function * */ @@ -46,13 +46,13 @@ { // Fwd decl. - template <typename F, typename I> class thru; + template <typename F, typename I> class fun_image; namespace internal { - /// Data structure for \c mln::thru<T,I>. + /// Data structure for \c mln::fun_image<T,I>. template <typename F, typename I> - struct data< thru<F,I> > + struct data< fun_image<F,I> > { data( I& ima); I& ima_; @@ -66,8 +66,10 @@ { template <typename F, typename I> - struct image_< thru<F,I> > : default_image_morpher< I, mln_result(F), thru<F,I> > + struct image_< fun_image<F,I> > : default_image_morpher< I, mln_result(F), fun_image<F,I> > { + // typedef trait::image::category::value_morpher category; + typedef trait::image::category::primary category; // does not work either typedef trait::image::value_io::read_write value_io; typedef trait::image::value_access::computed value_access; typedef trait::image::value_storage::disrupted value_storage; @@ -89,11 +91,13 @@ + + /*! \brief Class of image morpher which takes allow to view an image throught a morpher */ template <typename F, typename I> - struct thru : - public internal::image_value_morpher< I, mln_result(F), thru<F,I> > + struct fun_image : + public internal::image_value_morpher< I, mln_result(F), fun_image<F,I> > { /// Value associated type. typedef mln_result(F) value; @@ -102,13 +106,13 @@ typedef mln_result(F) rvalue; /// Return type of read-write access. - typedef mln::value::shell<F,I> lvalue; // FIXME : if I is const or F is Function_v2v, there is no shell + typedef mln::value::shell<F,I> lvalue; /// Skeleton. - typedef thru< tag::value_<mln_result(F)>, tag::image_<I> > skeleton; + typedef fun_image< tag::value_<mln_result(F)>, tag::image_<I> > skeleton; /// Constructor. - thru(Image<I>& ima); + fun_image(Image<I>& ima); /// Initialize an empty image. void init_(Image<I>& ima); @@ -125,45 +129,45 @@ # ifndef MLN_INCLUDE_ONLY - // internal::data< thru<T,I> > + // internal::data< fun_image<T,I> > namespace internal { template <typename F, typename I> inline - data< thru<F,I> >::data(I& ima) + data< fun_image<F,I> >::data(I& ima) : ima_(ima) { } } // end of namespace mln::internal - // thru<F,I> + // fun_image<F,I> template <typename F, typename I> inline - thru<F,I>::thru(Image<I>& ima) + fun_image<F,I>::fun_image(Image<I>& ima) { mln_precondition(exact(ima).has_data()); - this->data_ = new internal::data< thru<F,I> >(exact(ima)); + this->data_ = new internal::data< fun_image<F,I> >(exact(ima)); } template <typename F, typename I> inline void - thru<F,I>::init_(Image<I>& ima) + fun_image<F,I>::init_(Image<I>& ima) { mln_precondition(exact(ima).has_data()); - this->data_ = new internal::data<thru<F,I> >(exact(ima)); + this->data_ = new internal::data<fun_image<F,I> >(exact(ima)); } template <typename F, typename I> inline mln_result(F) - thru<F,I>::operator()(const mln_psite(I)& p) const + fun_image<F,I>::operator()(const mln_psite(I)& p) const { mln_precondition(this->data_->ima_.has(p)); return f( this->data_->ima_(p) ); @@ -172,16 +176,16 @@ template <typename F, typename I> inline value::shell<F, I> - thru<F,I>::operator()(const mln_psite(I)& p) + fun_image<F,I>::operator()(const mln_psite(I)& p) { return mln::value::shell<F, I>( this->data_->ima_, p ); } // template <typename F, typename I> - // thru<F, I> thru(Function<F> &f, Image<I> &i) + // fun_image<F, I> fun_image(Function<F> &f, Image<I> &i) // { - // return thru<F, I> (f, i); + // return fun_image<F, I> (f, i); // } @@ -190,4 +194,4 @@ } // end of namespace mln -#endif // ! MLN_CORE_IMAGE_THRU_HH +#endif // ! MLN_CORE_IMAGE_FUN_IMAGE_HH Property changes on: mln/core/image/fun_image.hh ___________________________________________________________________ Added: svn:mergeinfo Index: mln/fun/meta/red.hh --- mln/fun/meta/red.hh (revision 3045) +++ mln/fun/meta/red.hh (working copy) @@ -29,6 +29,7 @@ # define MLN_FUN_META_RED_HH # include <mln/core/concept/meta_fun.hh> +# include <mln/value/rgb.hh> namespace mln { @@ -39,6 +40,25 @@ }; + template <unsigned n> + struct function< meta::red< value::rgb<n> > > : public Function_v2w_w2v<function< meta::red < value::rgb<n> > > > + { + typedef value::rgb<n> value; + + typedef typename value::red_t result; + result read(const value& c) + { + return c.red(); + } + + typedef result& lresult; + lresult write(value& c) + { + return c.red(); + } + }; + + }; #endif // MLN_FUN_META_RED_HH
participants (1)
-
Alexandre Abraham