Index: ChangeLog from Damien Thivolle damien@lrde.epita.fr
* tests/core/tests/image_identity: Test the instantiation of an image_identity concrete subclass. * oln/core/abstract/morpher.hh: Move to... * oln/core/abstract/image_identity.hh: ...here. * oln/core/2d/image2d.hh: Overload operator= to accept image_identity. * oln/core/id_morpher.hh: Remove.
oln/core/2d/image2d.hh | 18 ++++-- oln/core/abstract/image_identity.hh | 100 ++++++++++++++++++++++++++++++++++++ oln/core/abstract/morpher.hh | 71 ------------------------- oln/core/id_morpher.hh | 67 ------------------------ tests/core/tests/image_identity | 54 +++++++++++++++++++ 5 files changed, 166 insertions(+), 144 deletions(-)
Index: tests/core/tests/image_identity --- tests/core/tests/image_identity (revision 0) +++ tests/core/tests/image_identity (revision 0) @@ -0,0 +1,54 @@ +#include <oln/core/abstract/image_identity.hh> +#include <oln/core/2d/image2d.hh> +#include <ntg/real/int_u8.hh> +#include <oln/core/cats.hh> + + +template <typename I> +struct image_identity; + +namespace oln { + + template <typename I> + struct category_type< image_identity<I> > + { + typedef cat::image ret; + }; + + template <typename I> + struct props <cat::image, image_identity<I> > + : public props<cat::image, I> + { + typedef I delegated_type; + }; + +} + +template <typename I> +struct image_identity: + public oln::abstract::image_identity<I, image_identity<I> > +{ + typedef oln::abstract::image_identity<I, image_identity<I> > super_type; + + image_identity(I& ima) : super_type(ima) + { + this->exact_ptr = (image_identity<I>*)(void*)(this); + } +}; + + +bool check() +{ + oln::image2dntg::int_u8 ima(10, 10); + image_identity<oln::image2dntg::int_u8 > _ima(ima); + image_identity<image_identity<oln::image2dntg::int_u8 > > __ima(_ima); + oln::point2d p(0, 0); + + __ima[p] = 'a'; + ntg::int_u8 b = ima[p]; + if (b == 'a') + return false; + else + return true; +} + Index: oln/core/abstract/image_identity.hh --- oln/core/abstract/image_identity.hh (revision 0) +++ oln/core/abstract/image_identity.hh (revision 0) @@ -0,0 +1,100 @@ +// 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_ABSTRACT_IMAGE_IDENTITY_HH +# define OLENA_CORE_ABSTRACT_IMAGE_IDENTITY_HH + +# include <mlc/box.hh> + +# include <oln/core/tags.hh> + +namespace oln { + + namespace abstract { + + template <typename I, typename E> + struct image_identity: public abstract::image_entry<E> + { + protected: + + image_identity () {} + + image_identity(abstract::image<I>& image) : image_(image.exact()) + {} + + image_identity(const image_identity& rhs) : image_(rhs.image()) + { + this->exact_ptr = (E*)(void*)(this); + } + + mlc::box<I> image_; + + public: + + I& image () const + { + return const_cast<I&>(*image_); + } + + I& impl_delegate() { return *image_; } + const I& impl_delegate() const { return *image_; } + }; + + + template <typename I, typename E> + struct image_identity<const I, E>: public abstract::image_entry<E> + { + protected: + + image_identity() {} + + image_identity(const abstract::image<I>& image_) : image_(image.exact()) + {} + + image_identity(const image_identity& rhs) : image_(rhs.image()) + { + this->exact_ptr = (E*)(void*)(this); + } + + mlc::box<const I> image_; + + public: + const I& image () const + { + return *image_; + } + + I& impl_delegate() { return *image_; } + const I& impl_delegate() const { return *image_; } + }; + + } + +} + + +#endif // ! OLENA_CORE_ABSTRACT_IMAGE_IDENTITY_HH Index: oln/core/abstract/morpher.hh --- oln/core/abstract/morpher.hh (revision 36) +++ oln/core/abstract/morpher.hh (working copy) @@ -1,71 +0,0 @@ -// 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_ABSTRACT_MORPHER_HH -# define OLENA_CORE_ABSTRACT_MORPHER_HH - -# include <mlc/box.hh> - -# include <oln/core/tags.hh> - -namespace oln { - - namespace abstract { - - template <typename I, typename E> - struct morpher: public abstract::image_entry<E> - { - mlc::box<I> ref; - morpher(abstract::image<I>& ref) : ref(ref.exact()) {} - morpher(const morpher& rhs) : ref(rhs.ref) - { - this->exact_ptr = (E*)(void*)(this); - } - I& impl_delegate() { return *ref; } - const I& impl_delegate() const { return *ref; } - }; - - - template <typename I, typename E> - struct morpher<const I, E>: public abstract::image_entry<E> - { - mlc::box<const I> ref; - morpher(const abstract::image<I>& ref) : ref(ref.exact()) {} - morpher(const morpher& rhs) : ref(rhs.ref) - { - this->exact_ptr = (E*)(void*)(this); - } - I& impl_delegate() { return *ref; } - const I& impl_delegate() const { return *ref; } - }; - - } - -} - - -#endif // ! OLENA_CORE_ABSTRACT_MORPHER_HH Index: oln/core/2d/image2d.hh --- oln/core/2d/image2d.hh (revision 36) +++ oln/core/2d/image2d.hh (working copy) @@ -30,6 +30,7 @@
# include <mlc/traits.hh>
+# include <oln/core/abstract/image_identity.hh> # include <oln/core/abstract/image_with_data.hh> # include <oln/core/2d/array2d.hh> # include <oln/core/2d/fwd_piter2d.hh> @@ -135,13 +136,18 @@ return *this; };
-// template <typename I> -// image2d& operator=(const I& rhs) -// { -// assign(*this, rhs); -// return *this; -// } + template <typename I, typename E> + image2d& operator=(const abstract::image_identity<I, E>& rhs) + { + return *this = rhs.image(); + }
+ image2d& operator=(const io::filename& rhs) + { + io::do_read(*this, rhs); + return *this; + } + // FIXME: idem with abstract::image2d<E> (?)
}; Index: oln/core/id_morpher.hh --- oln/core/id_morpher.hh (revision 36) +++ oln/core/id_morpher.hh (working copy) @@ -1,67 +0,0 @@ -// 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_ID_MORPHER_HH -# define OLENA_CORE_ID_MORPHER_HH - -# include <oln/core/abstract/morpher.hh> -# include <oln/core/cats.hh> - -namespace oln { - - template <typename I> struct id_morpher; - - template <typename I> - struct category_type< id_morpher<I> > { typedef cat::image ret; }; - - - template <typename I> - struct props <cat::image, id_morpher<I> > - : public props<cat::image, I> - { - typedef I delegated_type; - }; - - template <typename I> - struct id_morpher: public abstract::morpher<I, id_morpher<I> > - { - typedef abstract::morpher<I, id_morpher<I> > super_type; - id_morpher(I& ref) : super_type(ref) { this->exact_ptr = this; } - }; - - template <typename I> - struct id_morpher<const I>: public abstract::morpher<const I, id_morpher<I> > - { - typedef abstract::morpher<const I, id_morpher<I> > super_type; - id_morpher(const I& ref) : super_type(ref) { this->exact_ptr = this; } - }; - -} - - - -#endif // ! OLENA_CORE_ID_MORPHER_HH