
https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Handle constness properly in pixel iterators. * mln/core/trait/qlf_value.hh: New. * mln/core/internal/pixel_iterator_base.hh (qualified_value): Move and rename as... * mln/core/trait/qlf_value.hh (qlf_value): ...this. * doc/Doxyfile.in: Update. * mln/core/macros.hh (mln_qlf_value): New. Add space. * mln/core/pixter2d_b.hh (eor_): Update type. (image): New. * mln/core/dpoints_pixter.hh (value_ref_): Update type. * mln/core/internal/pixel_impl.hh (value_): Remove; obsolete. (image): New. * mln/core/fimage.hh: Fix warning. * mln/core/concept/generalized_pixel.hh (image): New. (address_): Update type. (todo): New. (ctor): Re-activate check. * mln/core/concept/fast_image.hh (offset): New; factor code. (buffer): New overload. * mln/core/concept/doc/generalized_pixel.hh (image): New. (address_): Update type. * mln/core/concept/doc/fast_image.hh (offset): Remove; factored. * mln/core/image2d_b.hh (offset): Remove; factored. (buffer): New. * mln/level/assign.hh: Fix doc. * mln/value/cast.hh: Fix warning. * TODO: Update. TODO | 1 doc/Doxyfile.in | 1 mln/core/concept/doc/fast_image.hh | 9 ---- mln/core/concept/doc/generalized_pixel.hh | 5 +- mln/core/concept/fast_image.hh | 41 ++++++++++++++++-- mln/core/concept/generalized_pixel.hh | 15 +++++- mln/core/dpoints_pixter.hh | 5 -- mln/core/fimage.hh | 6 +- mln/core/image2d_b.hh | 22 ++++------ mln/core/internal/pixel_impl.hh | 12 ++--- mln/core/internal/pixel_iterator_base.hh | 23 +--------- mln/core/macros.hh | 3 + mln/core/pixter2d_b.hh | 6 +- mln/core/trait/qlf_value.hh | 65 ++++++++++++++++++++++++++++++ mln/level/assign.hh | 2 mln/value/cast.hh | 6 +- 16 files changed, 152 insertions(+), 70 deletions(-) Index: doc/Doxyfile.in --- doc/Doxyfile.in (revision 1034) +++ doc/Doxyfile.in (working copy) @@ -1055,6 +1055,7 @@ "mln_fwd_viter(T)=typename T::fwd_viter" \ "mln_bkd_viter(T)=typename T::bkd_viter" \ "mln_value(T)=typename T::value" \ + "mln_qlf_value(T)=typename T::qlf_value" \ "mln_vset(T)=typename T::vset" \ "mln_rvalue(T)=typename T::rvalue" \ "mln_lvalue(T)=typename T::lvalue" \ Index: TODO --- TODO (revision 1034) +++ TODO (working copy) @@ -30,6 +30,7 @@ * renaming mlc into metal ++ look for "same_grid" etc. * clean-up Index: mln/core/macros.hh --- mln/core/macros.hh (revision 1034) +++ mln/core/macros.hh (working copy) @@ -121,6 +121,9 @@ // q +/// Shortcut to access the qualified (const or mutable) value type associated to T. +# define mln_qlf_value(T) typename mln::trait::qlf_value< T >::ret + /// Shortcut to access the qiter type associated to T. # define mln_qiter(T) typename T::fwd_qiter Index: mln/core/trait/qlf_value.hh --- mln/core/trait/qlf_value.hh (revision 0) +++ mln/core/trait/qlf_value.hh (revision 0) @@ -0,0 +1,65 @@ +// 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_TRAIT_QLF_VALUE_HH +# define MLN_CORE_TRAIT_QLF_VALUE_HH + +/*! \file mln/core/trait/qlf_value.hh + * + * \brief Definition of the qlf_value image trait. + */ + +# include <mln/core/macros.hh> + + +namespace mln +{ + + namespace trait + { + + + template <typename I> + struct qlf_value + { + typedef mln_value(I) ret; + }; + + + template <typename I> + struct qlf_value< const I > + { + typedef const mln_value(I) ret; + }; + + + } // end of namespace mln::trait + +} // end of namespace mln + + +#endif // ! MLN_CORE_TRAIT_QLF_VALUE_HH Index: mln/core/fimage.hh --- mln/core/fimage.hh (revision 1034) +++ mln/core/fimage.hh (working copy) @@ -82,8 +82,8 @@ /// Read-only access of pixel value at point site \p p. mln_result(F) operator()(const psite& p) const; - /// Read-write access of pixel value at point site \p p. - void operator()(const psite& p); + /// Read-write access is present but disabled. + void operator()(const psite&); /// Give the set of values of the image. const vset& values() const; @@ -150,7 +150,7 @@ template <typename F, typename S> void - fimage<F,S>::operator()(const psite& p) + fimage<F,S>::operator()(const psite&) { mln_invariant(0); // FIXME: Turn into a compile-time error... } Index: mln/core/pixter2d_b.hh --- mln/core/pixter2d_b.hh (revision 1034) +++ mln/core/pixter2d_b.hh (working copy) @@ -45,10 +45,12 @@ class fwd_pixter2d_b : public internal::pixel_iterator_base_< I, fwd_pixter2d_b<I> > { typedef internal::pixel_iterator_base_< I, fwd_pixter2d_b<I> > super_; - typedef typename super_::value_ value_; public: + /// Image type. + typedef I image; + /*! \brief Constructor. * * \param[in] image Image to iterate over its pixels. @@ -67,7 +69,7 @@ unsigned row_offset_; /// End of the current row. - value_* eor_; + mln_qlf_value(I)* eor_; }; Index: mln/core/dpoints_pixter.hh --- mln/core/dpoints_pixter.hh (revision 1034) +++ mln/core/dpoints_pixter.hh (working copy) @@ -58,9 +58,6 @@ typedef typename internal::pixel_impl_< I, dpoints_fwd_pixter<I> > super_; public: - /// Using super value type. - typedef typename super_::value_ value_; - /*! \brief Constructor. * * \param[in] image Image subject to iteration. @@ -111,7 +108,7 @@ unsigned i_; /// reference pixel / point in the image - value_** value_ref_; + mln_qlf_value(I)** value_ref_; // or: const mln_point(I)* p_ref_; Index: mln/core/internal/pixel_impl.hh --- mln/core/internal/pixel_impl.hh (revision 1034) +++ mln/core/internal/pixel_impl.hh (working copy) @@ -53,6 +53,9 @@ { public: + /// Image type. + typedef I image; + /// Image value type. typedef mln_value(I) value; @@ -62,9 +65,6 @@ /// Image rvalue type. typedef mln_rvalue(I) rvalue; - /// Qualified value type. - typedef value value_; - /// pixel iterator value. lvalue operator*(); @@ -102,15 +102,15 @@ { public: + /// Image type. + typedef const I image; + /// Image value type. typedef mln_value(I) value; /// Image rvalue type. typedef mln_rvalue(I) rvalue; - /// Qualified value type. - typedef const value value_; - /// Get the pixel iterator value. rvalue operator*() const; Index: mln/core/internal/pixel_iterator_base.hh --- mln/core/internal/pixel_iterator_base.hh (revision 1034) +++ mln/core/internal/pixel_iterator_base.hh (working copy) @@ -35,6 +35,7 @@ # include <mln/core/concept/pixel_iterator.hh> # include <mln/core/internal/pixel_impl.hh> +# include <mln/core/trait/qlf_value.hh> namespace mln @@ -44,21 +45,6 @@ { - template <typename I> - struct qualified_value - { - typedef mln_value(I) ret; - }; - - - template <typename I> - struct qualified_value< const I > - { - typedef const mln_value(I) ret; - }; - - - /*! \brief A base class for pixel iterators. * */ @@ -79,16 +65,13 @@ /// Test if the iterator is valid. bool is_valid() const; - /// Qualified (const or not) value type. - typedef typename qualified_value<I>::ret value_; - protected: /// Beginning of the image. - value_* boi_; + mln_qlf_value(I)* boi_; /// End of the image (past-the-end). - value_* eoi_; + mln_qlf_value(I)* eoi_; /// Constructor. pixel_iterator_base_(I& image); Index: mln/core/concept/generalized_pixel.hh --- mln/core/concept/generalized_pixel.hh (revision 1034) +++ mln/core/concept/generalized_pixel.hh (working copy) @@ -35,6 +35,7 @@ # include <mln/core/concept/object.hh> # include <mln/core/internal/force_exact.hh> +# include <mln/core/trait/qlf_value.hh> namespace mln @@ -52,6 +53,8 @@ * * \see mln::doc::Generalized_Pixel for a complete documentation of this * class contents. + * + * \todo (later) Add an access to the targetted image. */ template <typename E> struct Generalized_Pixel @@ -59,9 +62,10 @@ /* typedef value; typedef rvalue; + typedef image; rvalue operator*() const; - value** address_() const; + mln_qlf_value(image)** address_() const; */ protected: Generalized_Pixel(); @@ -75,11 +79,14 @@ { typedef mln_value(E) value; typedef mln_rvalue(E) rvalue; + rvalue (E::*m1)() const = & E::operator*; m1 = 0; - // FIXME: Activate (so add qualif_value): -// value** (E::*m2)() const = & E::address_; -// m2 = 0; + + typedef mln_image(E) image; + + mln_qlf_value(image)** (E::*m2)() const = & E::address_; + m2 = 0; } # endif // ! MLN_INCLUDE_ONLY Index: mln/core/concept/fast_image.hh --- mln/core/concept/fast_image.hh (revision 1034) +++ mln/core/concept/fast_image.hh (working copy) @@ -33,6 +33,8 @@ */ # include <mln/core/concept/image.hh> +# include <mln/core/concept/generalized_point.hh> +# include <mln/core/trait/qlf_value.hh> namespace mln @@ -50,15 +52,28 @@ unsigned border(); int offset(const dpoint& dp) const; - unsigned offset(const point& p) const; point point_at_offset(unsigned o) const; + mln_qlf_value(E)* buffer(); const value* buffer() const; rvalue operator[](unsigned o) const; lvalue operator[](unsigned o); */ + + /*! \brief Give the offset of the point \p p. + * + * \param[in] p A generalized point. + * + * \warning This method is final. + * + * \pre The image has to be initialized and to own the point \p p. + * \post p = point_at_offset(result) + */ + template <typename P> + unsigned offset(const Generalized_Point<P>& p) const; + protected: Fast_Image(); }; @@ -67,6 +82,22 @@ # ifndef MLN_INCLUDE_ONLY template <typename E> + template <typename P> + unsigned + Fast_Image<E>::offset(const Generalized_Point<P>& p_) const + { + // FIXME: check that P is mln_point(E) + const E& this_ = exact(this); + const P& p = internal::force_exact<P>(p_); + mln_precondition(this_->has_data()); + mln_precondition(this_->owns_(p)); + + unsigned o = & this_->operator()(p) - this_->buffer(); + mln_postcondition(p = this_->point_at_offset(o)); + return o; + } + + template <typename E> Fast_Image<E>::Fast_Image() { typedef mln_point(E) point; @@ -77,15 +108,15 @@ int (E::*m1)(const dpoint&) const = & E::offset; m1 = 0; - unsigned (E::*m2)(const point&) const = & E::offset; + point (E::*m2)(unsigned) const = & E::point_at_offset; m2 = 0; - point (E::*m3)(unsigned) const = & E::point_at_offset; + unsigned (E::*m3)() const = & E::border; m3 = 0; - unsigned (E::*m4)() const = & E::border; - m4 = 0; typedef mln_value(E) value; + mln_qlf_value(E)* (E::*m4)() = & E::buffer; + m4 = 0; const value* (E::*m5)() const = & E::buffer; m5 = 0; Index: mln/core/concept/doc/generalized_pixel.hh --- mln/core/concept/doc/generalized_pixel.hh (revision 1034) +++ mln/core/concept/doc/generalized_pixel.hh (working copy) @@ -47,6 +47,9 @@ struct Generalized_Pixel { + /// Image associated type (with possible const qualification). + typedef void image; + /// Value associated type. typedef void value; @@ -67,7 +70,7 @@ * * \return A pointer to the value address. */ - value** address_() const; + mln_qlf_value(ima)** address_() const; protected: Generalized_Pixel(); Index: mln/core/concept/doc/fast_image.hh --- mln/core/concept/doc/fast_image.hh (revision 1034) +++ mln/core/concept/doc/fast_image.hh (working copy) @@ -58,15 +58,6 @@ int offset(const dpoint& dp); - /*! \brief Give the offset of the point \p p. - * - * \param[in] p A point. - * - * \pre The image has to own the point \p p. - */ - unsigned offset(const point& p); - - /*! \brief Give the point at offset \p o. * * \param[in] o An offset. Index: mln/core/image2d_b.hh --- mln/core/image2d_b.hh (revision 1034) +++ mln/core/image2d_b.hh (working copy) @@ -192,15 +192,15 @@ /// Give the offset corresponding to the delta-point \p dp. int offset(const dpoint2d& dp) const; - /// Give the offset corresponding to the point \p p. - unsigned offset(const point2d& p) const; - /// Give the point corresponding to the offset \p o. point2d point_at_offset(unsigned o) const; /// Give a hook to the value buffer. const T* buffer() const; + /// Give a hook to the value buffer. + T* buffer(); + private: @@ -411,21 +411,19 @@ } template <typename T> - int - image2d_b<T>::offset(const dpoint2d& dp) const + T* + image2d_b<T>::buffer() { mln_precondition(this->has_data()); - int o = dp[0] * vb_.len(1) + dp[1]; - return o; + return buffer_; } template <typename T> - unsigned - image2d_b<T>::offset(const point2d& p) const + int + image2d_b<T>::offset(const dpoint2d& dp) const { - mln_precondition(this->owns_(p)); - unsigned o = & this->operator()(p) - this->buffer_; - mln_postcondition(p = point_at_offset(o)); + mln_precondition(this->has_data()); + int o = dp[0] * vb_.len(1) + dp[1]; return o; } Index: mln/level/assign.hh --- mln/level/assign.hh (revision 1034) +++ mln/level/assign.hh (working copy) @@ -44,7 +44,7 @@ /*! Assignment of image \p target with image \p data. * - * \param[out] output The image to be assigned. + * \param[out] target The image to be assigned. * \param[in] data The auxiliary image. * * \pre target.domain = data.domain Index: mln/value/cast.hh --- mln/value/cast.hh (revision 1034) +++ mln/value/cast.hh (working copy) @@ -84,8 +84,8 @@ /// Read-only access of pixel value at point site \p p. T operator()(const psite& p) const; - /// Read-write access of pixel value at point site \p p. - void operator()(const psite& p); + /// Read-write access is present but disabled. + void operator()(const psite&); /// Give the set of values of the image. const vset& values() const; @@ -153,7 +153,7 @@ template <typename T, typename I> void - cast_image<T,I>::operator()(const psite& p) + cast_image<T,I>::operator()(const psite&) { mln_invariant(0); // FIXME: Turn into a compile-time error... }