
oln::ch_value_type a été introduit avec ce patch, mais je ne suis absolument pas sûr de la façon dont je l'ai écrite ; apparemment, oln/core/properties.hh ne fournit pas autant de sucre pour les propriétés-fonctions (ch_value_type, par ex.) que pour les propriétés « usuelles ». Je suis preneur d'aides/explications ! :) https://svn.lrde.epita.fr/svn/oln/prototypes/proto-1.0 ChangeLog | 17 +++++ oln/core/abstract/image.hh | 1 oln/core/abstract/image_dimension.hh | 12 +++- oln/core/apply.hh | 102 +++++++++++++++++++++++++++++++++++ oln/core/ch_value_type.hh | 47 ++++++++++++++++ oln/makefile.src | 25 +++++--- tests/core/tests/apply | 22 +++++++ 7 files changed, 213 insertions(+), 13 deletions(-) Index: olena/ChangeLog from Roland Levillain <roland@lrde.epita.fr> First version of oln::apply, for Adapatble Unary Functions. * oln/core/apply.hh: New file. * oln/core/ch_value_type.hh: New file. * oln/makefile.src (OLN_DEP): Add core/apply.hh and core/ch_value_type.hh. * tests/core/tests/apply: New test. * oln/makefile.src (OLN_DEP): Add core/abstract/image_by_delegation.hh, core/abstract/image_like_.hh, core/abstract/image_operator.hh and core/gen/identity.hh. Remove core/abstract/image_identity.hh. * oln/core/abstract/image.hh (echo): Print concrete_type. * oln/core/abstract/image_dimension.hh: Add missing comments. Index: olena/tests/core/tests/apply --- olena/tests/core/tests/apply (revision 0) +++ olena/tests/core/tests/apply (revision 0) @@ -0,0 +1,22 @@ + // -*- C++ -*- +#include <functional> +#include <oln/basics2d.hh> +#include <oln/core/apply.hh> +#include <oln/level/fill.hh> +#include <oln/level/compare.hh> +#include <ntg/int.hh> + + +bool check() +{ + oln::image2d<ntg::int_u8> ima1(10, 10); + oln::level::fill(ima1, 10); + oln::image2d<ntg::int_u8> ima2(10, 10); + oln::level::fill(ima2, 30); + oln::image2d<ntg::int_u8> ima; + ima = oln::apply (std::bind2nd(std::multiplies<ntg::int_u8>(), 3), ima1); + + if (oln::level::is_equal(ima, ima2)) + return false; + return true; +} Index: olena/oln/core/abstract/image.hh --- olena/oln/core/abstract/image.hh (revision 100) +++ olena/oln/core/abstract/image.hh (working copy) @@ -79,6 +79,7 @@ { ostr << "props_of(" // FIXME: << typeid(oln::category::image).name() << ", " << typeid(type).name() << ") = {" + << " concrete_type = " << typeid(concrete_type).name() << " value_type = " << typeid(value_type).name() << " point_type = " << typeid(point_type).name() << " size_type = " << typeid(size_type).name() Index: olena/oln/core/abstract/image_dimension.hh --- olena/oln/core/abstract/image_dimension.hh (revision 100) +++ olena/oln/core/abstract/image_dimension.hh (working copy) @@ -40,12 +40,10 @@ */ namespace abstract { - /*! \class abstract::image2d<E> + /*! \class abstract::image1d<E> ** ** Class of 1d images. */ - - template <typename E> struct image1d : public virtual image<E> { @@ -56,6 +54,10 @@ image1d() {} }; + /*! \class abstract::image2d<E> + ** + ** Class of 2d images. + */ template <typename E> struct image2d : public virtual image<E> { @@ -66,6 +68,10 @@ image2d() {} }; + /*! \class abstract::image3d<E> + ** + ** Class of 3d images. + */ template <typename E> struct image3d : public virtual image<E> { Index: olena/oln/core/apply.hh --- olena/oln/core/apply.hh (revision 0) +++ olena/oln/core/apply.hh (revision 0) @@ -0,0 +1,102 @@ +// Copyright (C) 2001, 2002, 2003, 2004, 2005 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 +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLENA_CORE_APPLY_HH +# define OLENA_CORE_APPLY_HH + +# include <oln/basics.hh> +# include <oln/core/abstract/op.hh> +# include <oln/core/ch_value_type.hh> + +namespace oln { + + // fwd decl + namespace impl { + template <typename AdaptableUnaryFun, typename I> struct apply_type; + } + + // category + template <typename AdaptableUnaryFun, typename I> + struct set_category< impl::apply_type<AdaptableUnaryFun, I> > + { + typedef category::image ret; + }; + + // super_type + template <typename AdaptableUnaryFun, typename I> + struct set_super_type< impl::apply_type<AdaptableUnaryFun, I> > + { + typedef typename abstract::op<I, impl::apply_type<AdaptableUnaryFun, I> > + ret; + }; + + namespace impl { + + template <typename AdaptableUnaryFun, typename I> + struct apply_type : + public abstract::op< + typename ch_value_type< + I, typename AdaptableUnaryFun::result_type>::ret, + apply_type<AdaptableUnaryFun, I> > + { + typedef typename + ch_value_type<I, typename AdaptableUnaryFun::result_type>::ret + output_type; + + const AdaptableUnaryFun& f_; + box<const I> input_; + + apply_type(const AdaptableUnaryFun& f, const abstract::image<I>& input) : + f_ (f), + input_ (input.exact ()) + { + } + + void impl_run() + { + output_type output(input_.size()); + oln_type_of(I, fwd_piter) p(input_.size()); + for_all(p) + output[p] = f_(input_[p]); + this->image_ = output; + } + }; + + } // end of namespace impl + + template <class AdaptableUnaryFun, typename I> + impl::apply_type<AdaptableUnaryFun, I> + apply (const AdaptableUnaryFun& f, const abstract::image<I>& input) + { + impl::apply_type<AdaptableUnaryFun, I> tmp (f, input); + tmp.run (); + return tmp; + } + +} // end of namespace oln + +#endif // ! OLENA_CORE_APPLY_HH Index: olena/oln/core/ch_value_type.hh --- olena/oln/core/ch_value_type.hh (revision 0) +++ olena/oln/core/ch_value_type.hh (revision 0) @@ -0,0 +1,47 @@ +// Copyright (C) 2005 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 +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLENA_CORE_CH_VALUE_TYPE_HH +# define OLENA_CORE_CH_VALUE_TYPE_HH + +# include <oln/core/properties.hh> + +namespace oln { + + template<class I, class T = oln_type_of(I, value)> + struct ch_value_type + { + // FIXME: Use/extend oln/core/properties.hh mechanisms, instead of + // using mlc/properties.hh directly. + typedef typename + internal::get_props<category::image, I>::template ch_value_type<T>::ret + ret; + }; + +} // end of namespace oln + +#endif // ! OLENA_CORE_CH_VALUE_TYPE_HH Index: olena/oln/makefile.src --- olena/oln/makefile.src (revision 100) +++ olena/oln/makefile.src (working copy) @@ -1,4 +1,4 @@ -## +## -*- Makefile -*- ## List of headers in olena ## Include this file to have access to their name. ## @@ -14,8 +14,6 @@ config/pconf.hh \ config/system.hh \ convert/value_to_point.hh \ - morpho/stat.hh \ - morpho/erosion.hh \ core/1d/array1d.hh \ core/1d/dpoint1d.hh \ core/1d/fwd_piter1d.hh \ @@ -26,39 +24,44 @@ core/2d/bkd_piter2d.hh \ core/2d/dpoint2d.hh \ core/2d/fwd_piter2d.hh \ + core/2d/fwd_witer2d.hh \ core/2d/image2d.hh \ + core/2d/neighborhood2d.hh \ core/2d/point2d.hh \ core/2d/size2d.hh \ - core/2d/neighborhood2d.hh \ - core/2d/fwd_witer2d.hh \ core/2d/window2d.hh \ core/3d/array3d.hh \ + core/3d/dpoint3d.hh \ core/3d/fwd_piter3d.hh \ core/3d/image3d.hh \ core/3d/point3d.hh \ - core/3d/dpoint3d.hh \ core/3d/size3d.hh \ core/abstract/data_storage.hh \ core/abstract/dpoint.hh \ core/abstract/entry.hh \ core/abstract/image.hh \ + core/abstract/image_by_delegation.hh \ core/abstract/image_constness.hh \ core/abstract/image_dimension.hh \ + core/abstract/image_like_.hh \ + core/abstract/image_operator.hh \ core/abstract/image_vectorialness.hh \ - core/abstract/image_identity.hh \ core/abstract/image_with_data.hh \ core/abstract/images.hh \ core/abstract/internal/image_impl.hh \ + core/abstract/neighborhood.hh \ core/abstract/op.hh \ core/abstract/piter.hh \ - core/abstract/witer.hh \ core/abstract/point.hh \ core/abstract/size.hh \ - core/abstract/neighborhood.hh \ core/abstract/struct_elt.hh \ + core/abstract/witer.hh \ core/accum.hh \ - core/coord.hh \ + core/apply.hh \ + core/ch_value_type.hh \ core/compose.hh \ + core/coord.hh \ + core/gen/identity.hh \ core/properties.hh \ core/value_box.hh \ fancy/iota.hh \ @@ -71,4 +74,6 @@ io/write_image_2d_pnm.hh \ level/compare.hh \ level/fill.hh \ + morpho/erosion.hh \ + morpho/stat.hh \ utils/clone.hh Property changes on: olena/img ___________________________________________________________________ Name: svn:ignore + Makefile Makefile.in Property changes on: metalic/tests/array ___________________________________________________________________ Name: svn:ignore + Makefile Makefile.in