
https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Introduce the notion of literals. Introduce literal zero. * mln/core/concept/literal.hh: New. * mln/literal: New directory. * mln/literal/zero.hh: New. * tests/literal_zero.cc: New. * mln/accu/sum.hh: Update. * mln/core/concept/object.hh: Include zero. * mln/metal/vec.hh (vec): Split ctor. (vec): Overload ctor for literal zero. Minor update for traits. * mln/trait/images.hh: Precise includes. * mln/trait/ch_value.hh: Prefer fwd decl for vec. * mln/trait/op_minus.hh, * mln/trait/op_times.hh (set_binary_): Use category. * mln/core/trait/op_minus.hh: Remove; obsolete. * mln/core/trait/op_uminus.hh: Remove. * mln/core/trait/all.hh: Update. Misc. * mln/core/dpoint1d.hh: Layout. * mln/core/point.hh: Sort includes. * mln/core/h_vec.hh (FIXME): New. * mln/core/image2d_b.hh: Sort includes. * mln/trace/exiting.hh, * mln/trace/entering.hh: Fix missing include. * tests/t_image.cc: Rename as... * tests/t_image.cxx: ...this; deactivate. * TODO: Update. TODO | 54 ++++++++++++++++---------- mln/accu/sum.hh | 3 - mln/core/concept/literal.hh | 91 ++++++++++++++++++++++++++++++++++++++++++++ mln/core/concept/object.hh | 3 - mln/core/h_vec.hh | 3 - mln/core/image2d_b.hh | 2 mln/core/point.hh | 4 - mln/core/trait/all.hh | 5 -- mln/literal/zero.hh | 77 +++++++++++++++++++++++++++++++++++++ mln/metal/vec.hh | 18 +++++++- mln/trace/entering.hh | 2 mln/trace/exiting.hh | 2 mln/trait/ch_value.hh | 7 ++- mln/trait/images.hh | 6 ++ mln/trait/op_minus.hh | 5 -- mln/trait/op_times.hh | 5 -- tests/literal_zero.cc | 46 ++++++++++++++++++++++ 17 files changed, 291 insertions(+), 42 deletions(-) Index: tests/literal_zero.cc --- tests/literal_zero.cc (revision 0) +++ tests/literal_zero.cc (revision 0) @@ -0,0 +1,46 @@ +// Copyright (C) 2007 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, 51 Franklin Street, Fifth Floor, +// 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. + +/*! \file tests/literal_zero.cc + * + * \brief Tests on mln::literal::zero. + */ + +#include <mln/literal/zero.hh> +// #include <mln/core/concept/object.hh> + + +int main() +{ + using namespace mln; + + unsigned char c; + c = literal::zero; + + double d; + d = literal::zero; +} Index: TODO --- TODO (revision 1235) +++ TODO (working copy) @@ -1,7 +1,8 @@ -*- outline -*- -* URGENT + +* mathieu ** accu @@ -17,46 +18,61 @@ tests ? +* guillaume + +** chamfer + +Cf. vieilles versions +algo avec front + + +* simon + +** lines + +ajouter win::line<Mesh, dir> +hline2d et vline2d deviennent des aliases +retoucher les routines avec {h,v}line en argument + -* large changes +* theo -introduce grids +hiérarchie de concepts sous Value +maj trait solver +virer is_fast -> changer le meta-plug +virer core/trait -* adds-on -** abstractions +* misc -Function_i2i -Weighted_Window +** big change -** types +** add + +*** abstraction + +*** type value::proxy to dispatch read/write + the corresponding image type a mean_value object { sum; count } and operator+ -** extensions +*** other in Fast_Image: memcpy and memset-like methods (?) .offset() into GenPixel built-in op objects -> reverse lhs/rhs +** rename -* renaming - - +value::cast(something) -> mln::cast_image or mln::fun::casted<F> etc. -* clean-up +** clean-up select_function in fun::internal::selector_p2? etc. -value::cast(something) -> mln::cast_image or mln::fun::casted<F> etc. - -* processing routines +** processing routines reconstructions + their canvases -fast versions of level::fill and level::paste sorting points w.r.t. their value (array of offsets, psites, points) -arith::inplace_plus et al. -linear:: for convolutions Index: mln/trait/images.hh --- mln/trait/images.hh (revision 1235) +++ mln/trait/images.hh (working copy) @@ -39,7 +39,11 @@ # include <string> # include <mln/value/props.hh> -# include <mln/metal/all.hh> + +# include <mln/metal/bexpr.hh> +# include <mln/metal/equal.hh> +# include <mln/metal/if.hh> +# include <mln/metal/is_const.hh> # define mln_trait_image_category(I) typename mln::trait::image_< I >::category Index: mln/trait/ch_value.hh --- mln/trait/ch_value.hh (revision 1235) +++ mln/trait/ch_value.hh (working copy) @@ -35,7 +35,6 @@ # include <mln/tag/skeleton.hh> # include <mln/trait/image_from_mesh.hh> -# include <mln/metal/vec.hh> # define mln_ch_value(I, V) typename mln::trait::ch_value< I, V >::ret @@ -45,6 +44,12 @@ namespace mln { + // Fwd decl. + namespace metal { template <unsigned n, typename T> class vec; } + + + + namespace trait { Index: mln/trait/op_minus.hh --- mln/trait/op_minus.hh (revision 1235) +++ mln/trait/op_minus.hh (working copy) @@ -50,9 +50,8 @@ /// Default definition of op_minus is given by the promote trait. - template <template <class> class Category_L, typename L, - template <class> class Category_R, typename R> - struct set_binary_< op_minus, Category_L, L, Category_R, R > + template <typename L, typename R> + struct set_binary_< op_minus, Object, L, Object, R > : public promote< L, R > { Index: mln/trait/op_times.hh --- mln/trait/op_times.hh (revision 1235) +++ mln/trait/op_times.hh (working copy) @@ -50,9 +50,8 @@ /// Default definition of op_times is given by the promote trait. - template <template <class> class Category_L, typename L, - template <class> class Category_R, typename R> - struct set_binary_< op_times, Category_L, L, Category_R, R > + template <typename L, typename R> + struct set_binary_< op_times, Object, L, Object, R > : public promote< L, R > { Index: mln/core/dpoint1d.hh Index: mln/core/point.hh --- mln/core/point.hh (revision 1235) +++ mln/core/point.hh (working copy) @@ -35,8 +35,8 @@ # include <mln/core/concept/point.hh> # include <mln/core/internal/coord_impl.hh> -# include <mln/core/h_vec.hh> # include <mln/fun/i2v/all.hh> + # include <mln/metal/vec.hh> # include <mln/core/h_vec.hh> @@ -207,8 +207,6 @@ return coord_; } - - # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln Index: mln/core/h_vec.hh --- mln/core/h_vec.hh (revision 1235) +++ mln/core/h_vec.hh (working copy) @@ -46,7 +46,7 @@ { h_vec() : metal::vec<dim + 1, T>(make::vec<dim + 1, T>(0)) - { + { // FIXME: Move in MLN_INCLUDE_ONLY this->data_[dim] = 1; } @@ -55,6 +55,7 @@ operator metal::vec<dim, T>() const; }; + # ifndef MLN_INCLUDE_ONLY template <unsigned dim, typename T> Index: mln/core/image2d_b.hh --- mln/core/image2d_b.hh (revision 1235) +++ mln/core/image2d_b.hh (working copy) @@ -33,8 +33,8 @@ * \brief Definition of the basic mln::image2d_b class. */ -# include <mln/core/internal/fixme.hh> # include <mln/core/internal/image_primary.hh> +# include <mln/core/internal/fixme.hh> # include <mln/core/box2d.hh> # include <mln/border/thickness.hh> Index: mln/core/trait/all.hh --- mln/core/trait/all.hh (revision 1235) +++ mln/core/trait/all.hh (working copy) @@ -46,11 +46,6 @@ # include <mln/core/trait/is_fast.hh> # include <mln/core/trait/pixter.hh> -# include <mln/core/trait/op_mult.hh> -// FIXME # include <mln/core/trait/op_plus.hh> -# include <mln/core/trait/op_minus.hh> -# include <mln/core/trait/op_uminus.hh> -// FIXME # include <mln/core/trait/promote.hh> #endif // ! MLN_CORE_TRAIT_ALL_HH Index: mln/core/concept/literal.hh --- mln/core/concept/literal.hh (revision 0) +++ mln/core/concept/literal.hh (revision 0) @@ -0,0 +1,91 @@ +// Copyright (C) 2007 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, 51 Franklin Street, Fifth Floor, +// 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 MLN_CORE_CONCEPT_LITERAL_HH +# define MLN_CORE_CONCEPT_LITERAL_HH + +/*! \file mln/core/concept/literal.hh + * \brief Definition of the concept of mln::literal. + */ + +# include <mln/core/concept/object.hh> + + +namespace mln +{ + + // Fwd decl. + template <typename E> struct Literal; + + // Literal category flag type. + template <> + struct Literal<void> + { + typedef Object<void> super; + }; + + + /*! \brief Base class for implementation classes of literals. + * + * \see mln::doc::Literal for a complete documentation of this class + * contents. + */ + template <typename E> + struct Literal : public Object<E> + { + typedef Literal<void> category; + + static const E& the(); + + protected: + Literal(); + }; + + + +# ifndef MLN_INCLUDE_ONLY + + template <typename E> + Literal<E>::Literal() + { + } + + template <typename E> + const E& + Literal<E>::the() + { + static E the_; + return the_; + } + +# endif // ! MLN_INCLUDE_ONLY + + +} // end of namespace mln + + +#endif // ! MLN_CORE_CONCEPT_LITERAL_HH Index: mln/core/concept/object.hh --- mln/core/concept/object.hh (revision 1235) +++ mln/core/concept/object.hh (working copy) @@ -42,6 +42,7 @@ # include <mln/core/internal/fixme.hh> # include <mln/trace/all.hh> # include <mln/metal/is_a.hh> +# include <mln/metal/is.hh> /*! \namespace mln @@ -98,7 +99,7 @@ # include <mln/core/exact.hh> -# include <mln/metal/all.hh> +# include <mln/literal/zero.hh> # include <mln/core/ops.hh> // FIXME: Read FIXME in mln/metal/binary_arith_trait.hh! Index: mln/literal/zero.hh --- mln/literal/zero.hh (revision 0) +++ mln/literal/zero.hh (revision 0) @@ -0,0 +1,77 @@ +// Copyright (C) 2007 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, 51 Franklin Street, Fifth Floor, +// 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 MLN_LITERAL_ZERO_HH +# define MLN_LITERAL_ZERO_HH + +/*! \file mln/literal/zero.hh + * \brief Definition of the literal of mln::zero. + * + * \todo Macro-ification of similar code (when no trivial conversion ops are involved). + */ + +# include <mln/core/concept/literal.hh> +# include <mln/metal/converts_to.hh> + + +namespace mln +{ + + namespace literal + { + + /// Type of literal zero. + struct zero_t : public Literal<zero_t> + { + // FIXME: (for the record) Add "friend class Literal<zero_t>;" and a protected ctor. + + template <typename T> + operator T () const; + }; + + + /// Literal zero. + static zero_t zero = zero_t(); + + +# ifndef MLN_INCLUDE_ONLY + + template <typename T> + zero_t::operator T () const + { + mlc_converts_to(int, T)::check(); + return 0; + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::literal + +} // end of namespace mln + + +#endif // ! MLN_LITERAL_ZERO_HH Index: mln/metal/vec.hh --- mln/metal/vec.hh (revision 1235) +++ mln/metal/vec.hh (working copy) @@ -35,6 +35,7 @@ # include <mln/trait/all.hh> # include <mln/value/props.hh> # include <mln/fun/i2v/all.hh> +# include <mln/literal/zero.hh> // FIXME: Document. @@ -132,9 +133,9 @@ typedef T value_type; enum { dim = n }; - vec() - { - } + vec(); + + vec(mln::literal::zero_t); vec(const vec<n, T>& rhs); @@ -313,6 +314,17 @@ # ifndef MLN_INCLUDE_ONLY template <unsigned n, typename T> + vec<n,T>::vec() + { + } + + template <unsigned n, typename T> + vec<n,T>::vec(mln::literal::zero_t) + { + this->set_all( mln::literal::zero ); + } + + template <unsigned n, typename T> vec<n,T>::vec(const vec<n,T>& rhs) : super_() { Index: mln/accu/sum.hh --- mln/accu/sum.hh (revision 1235) +++ mln/accu/sum.hh (working copy) @@ -36,6 +36,7 @@ # include <mln/core/concept/meta_accumulator.hh> # include <mln/value/props.hh> # include <mln/util/pix.hh> +# include <mln/literal/zero.hh> namespace mln @@ -99,7 +100,7 @@ void sum_<V,S>::init() { - s_ = S::zero; // FIXME + s_ = literal::zero; } template <typename V, typename S> Index: mln/trace/exiting.hh --- mln/trace/exiting.hh (revision 1235) +++ mln/trace/exiting.hh (working copy) @@ -34,6 +34,8 @@ */ # include <string> +# include <iostream> + # include <mln/trace/quiet.hh> Index: mln/trace/entering.hh --- mln/trace/entering.hh (revision 1235) +++ mln/trace/entering.hh (working copy) @@ -34,6 +34,8 @@ */ # include <string> +# include <iostream> + # include <mln/trace/quiet.hh>