1184: Fix init, init_, and clone.

https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Fix init, init_, and clone. * tests/core_clone.cc: Acticate code. * mln/core/image_if.hh (operator): Fix overload. * mln/core/internal/image_base.hh: Typo. * mln/core/internal/image_morpher.hh, * mln/core/image2d_b.hh, * mln/core/sub_image.hh, * mln/core/init.hh (init_): Move out of impl. (init): Move... * mln/core/concept/image.hh: ...here. * tests/core_init.cc: New. mln/core/concept/image.hh | 29 ++++++++++++++ mln/core/image2d_b.hh | 21 ++++------ mln/core/image_if.hh | 2 - mln/core/init.hh | 35 ----------------- mln/core/internal/image_base.hh | 2 - mln/core/internal/image_morpher.hh | 11 ++--- mln/core/sub_image.hh | 10 ----- tests/core_clone.cc | 22 +++++------ tests/core_init.cc | 74 +++++++++++++++++++++++++++++++++++++ 9 files changed, 128 insertions(+), 78 deletions(-) Index: tests/core_clone.cc --- tests/core_clone.cc (revision 1183) +++ tests/core_clone.cc (working copy) @@ -54,17 +54,17 @@ debug::println(clone(ima | b)); } -// { -// image2d_b<int> ima_ = clone(ima); -// std::cout << ima_.border() << std::endl; -// ima_(make::point2d(1,1)) = 51; -// debug::println(ima); -// } + { + image2d_b<int> ima_ = clone(ima); + std::cout << ima_.border() << std::endl; + ima_(make::point2d(1,1)) = 51; + debug::println(ima); + } -// { -// image2d_b<int> ima_( ima ); -// ima_(make::point2d(1,1)) = 51; -// debug::println(ima); -// } + { + image2d_b<int> ima_( ima ); + ima_(make::point2d(1,1)) = 51; + debug::println(ima); + } } Index: tests/core_init.cc --- tests/core_init.cc (revision 0) +++ tests/core_init.cc (revision 0) @@ -0,0 +1,74 @@ +// 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/core_init.cc + * + * \brief Tests on mln::init. + */ + +#include <mln/core/image2d_b.hh> +#include <mln/core/sub_image.hh> +#include <mln/debug/println.hh> + + + +int main() +{ + using namespace mln; + + typedef image2d_b<int> I; + + I ref( make::box2d(3,3) ); + box2d b = make::box2d(2,2); + + { + I ima; + init(ima, ref); + debug::println(ima); + mln_assertion(ima.border() = ref.border()); + } + + { + I ima_; // to init'd + sub_image<I, box2d> ima = ref | b; + init(ima_, ima); + debug::println(ima); + } + + { + sub_image<I, box2d> ima; + init(ima, ref); + debug::println(ima); + } + + { + sub_image<I, box2d> ima; + init(ima, ref | b); + debug::println(ima); + } + +} Index: mln/core/image_if.hh --- mln/core/image_if.hh (revision 1183) +++ mln/core/image_if.hh (working copy) @@ -115,7 +115,7 @@ image_if< const I, fun::equal_p2b_expr_< pw::value_<I>, pw::cst_<mln_value(I)> > > - operator | (Image<I>& ima, const mln_value(I)& v); + operator | (const Image<I>& ima, const mln_value(I)& v); // FIXME: Add the notion of "interval of values"... // FIXME: so we can write: ima | from_to(v1, v2) Index: mln/core/internal/image_base.hh --- mln/core/internal/image_base.hh (revision 1183) +++ mln/core/internal/image_base.hh (working copy) @@ -38,11 +38,11 @@ # include <mln/util/tracked_ptr.hh> + namespace mln { - namespace internal { Index: mln/core/internal/image_morpher.hh --- mln/core/internal/image_morpher.hh (revision 1183) +++ mln/core/internal/image_morpher.hh (working copy) @@ -144,32 +144,29 @@ } // end of namespace mln::internal - namespace impl - { + // template <typename Subject, typename T, // typename I, typename S, typename E> // void init_(Subject s, T& target, // const internal::image_morpher_<I,S,E>& model) // { +// std::cout << "deleg... "; // // FIXME: Precondition. // init_(s, target, * model.delegatee_()); // } template <typename Subject, typename T, typename J> - void init_(Subject s, T& target, - const Image<J>& model_) + void init_(Subject s, T& target, const Image<J>& model_) { + std::cout << "deleg... "; // FIXME: Precondition. // FIXME: Properly check that J is an internal::image_morpher_. const J& model = exact(model_); init_(s, target, * model.delegatee_()); } - } // end of namespace mln::impl - - # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln Index: mln/core/init.hh --- mln/core/init.hh (revision 1183) +++ mln/core/init.hh (working copy) @@ -34,8 +34,6 @@ */ # include <mln/tag/init.hh> - -# include <mln/core/concept/image.hh> # include <mln/geom/bbox.hh> # include <mln/border/get.hh> @@ -44,23 +42,9 @@ namespace mln { - /*! Initialize the image \p target with data extracted from image \p model. - * - * \param[in, out] target The image to be initialized. - * \param[in] model The image to provide data for the initialization. - * - * \pre (not target.has_data) and model.has_data - */ - template <typename I, typename J> - void init(Image<I>& target, const Image<J>& model); - - // Fwd decl. - namespace impl - { - template <typename Subject, typename T, typename M> void init_(Subject, T& target, const Object<M>& model); @@ -75,14 +59,10 @@ template <typename I> void init_(tag::domain_t, mln_pset(I)& pset, const Image<I>& ima); - } // end of namespace mln::impl - # ifndef MLN_INCLUDE_ONLY - namespace impl - { template <typename Subject, typename T, typename M> void init_(Subject, T&, const Object<M>&) @@ -110,21 +90,6 @@ pset = exact(ima).domain(); } - } // end of namespace mln::impl - - - // Facade. - - template <typename I, typename J> - void init(Image<I>& target, const Image<J>& model) - { - mln_precondition(! exact(target).has_data()); - mln_precondition(exact(model).has_data()); - - impl::init_(tag::image, exact(target), exact(model)); - - mln_postcondition(exact(target).has_data()); - } # endif // ! MLN_INCLUDE_ONLY Index: mln/core/image2d_b.hh --- mln/core/image2d_b.hh (revision 1183) +++ mln/core/image2d_b.hh (working copy) @@ -198,28 +198,25 @@ }; - namespace impl - { + + // Fwd decl. + + template <typename T> + void init_(tag::border_t, unsigned& bdr, const image2d_b<T>& model); template <typename T, typename J> void init_(tag::image_t, mln::image2d_b<T>& target, const J& model); - } // end of namespace mln::impl - # ifndef MLN_INCLUDE_ONLY - - // impl::init_ - - namespace impl - { + // init_ template <typename T> - void init_(tag::border_t, unsigned& b, const image2d_b<T>& model) + void init_(tag::border_t, unsigned& bdr, const image2d_b<T>& model) { - b = model.border(); + bdr = model.border(); } template <typename T, typename J> @@ -232,8 +229,6 @@ target.init_(b, bdr); } - } // end of namespace mln::impl - // internal::data_< image2d_b<T> > Index: mln/core/sub_image.hh --- mln/core/sub_image.hh (revision 1183) +++ mln/core/sub_image.hh (working copy) @@ -91,23 +91,15 @@ - namespace impl - { - template <typename I, typename S, typename J> void init_(tag::image_t, sub_image<I,S>& target, const J& model); - } // end of namespace mln::impl - # ifndef MLN_INCLUDE_ONLY // impl::init_ - namespace impl - { - template <typename I, typename S, typename J> void init_(tag::image_t, sub_image<I,S>& target, const J& model) { @@ -118,8 +110,6 @@ target.init_(ima, pset); } - } // end of namespace mln::impl - // internal::data_< sub_image<I,S> > Index: mln/core/concept/image.hh --- mln/core/concept/image.hh (revision 1183) +++ mln/core/concept/image.hh (working copy) @@ -39,11 +39,15 @@ # include <mln/trait/concrete.hh> // FIXME: Should be in all.hh! # include <mln/metal/is_a.hh> +# include <mln/tag/init.hh> + namespace mln { + + /*! \brief Base class for implementation of image classes. * * \see mln::doc::Image for a complete documentation of this class @@ -96,6 +100,19 @@ }; + + /*! Initialize the image \p target with data extracted from image \p model. + * + * \param[in, out] target The image to be initialized. + * \param[in] model The image to provide data for the initialization. + * + * \pre (not target.has_data) and model.has_data + */ + template <typename I, typename J> + void init(Image<I>& target, const Image<J>& model); + + + # ifndef MLN_INCLUDE_ONLY template <typename E> @@ -146,6 +163,18 @@ m8 = 0; } + template <typename I, typename J> + void init(Image<I>& target, const Image<J>& model) + { + mln_precondition(! exact(target).has_data()); + mln_precondition(exact(model).has_data()); + + init_(tag::image, exact(target), exact(model)); + + mln_postcondition(exact(target).has_data()); + } + + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln
participants (1)
-
Thierry Geraud