Commit dd2ed9b3 authored by Thierry Geraud's avatar Thierry Geraud
Browse files

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.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@1035 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 3e354f09
2007-07-24 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.
2007-07-23 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Add some morphers and handle constness in pixterators.
......
......@@ -30,6 +30,7 @@ built-in op objects -> reverse lhs/rhs
* renaming
mlc into metal
+ look for "same_grid" etc.
* clean-up
......
......@@ -1055,6 +1055,7 @@ PREDEFINED = \
"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" \
......
......@@ -58,15 +58,6 @@ namespace mln
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.
......
......@@ -47,6 +47,9 @@ namespace mln
struct Generalized_Pixel
{
/// Image associated type (with possible const qualification).
typedef void image;
/// Value associated type.
typedef void value;
......@@ -67,7 +70,7 @@ namespace mln
*
* \return A pointer to the value address.
*/
value** address_() const;
mln_qlf_value(ima)** address_() const;
protected:
Generalized_Pixel();
......
......@@ -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 @@ namespace mln
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();
};
......@@ -66,6 +81,22 @@ namespace mln
# 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()
{
......@@ -77,15 +108,15 @@ namespace mln
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;
......
......@@ -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 @@ namespace mln
*
* \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 @@ namespace mln
/*
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 @@ namespace mln
{
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
......
......@@ -58,9 +58,6 @@ namespace mln
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 @@ namespace mln
unsigned i_;
/// reference pixel / point in the image
value_** value_ref_;
mln_qlf_value(I)** value_ref_;
// or:
const mln_point(I)* p_ref_;
......
......@@ -82,8 +82,8 @@ namespace mln
/// 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 @@ namespace mln
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...
}
......
......@@ -192,15 +192,15 @@ namespace mln
/// 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 @@ namespace mln
}
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;
}
......
......@@ -53,6 +53,9 @@ namespace mln
{
public:
/// Image type.
typedef I image;
/// Image value type.
typedef mln_value(I) value;
......@@ -62,9 +65,6 @@ namespace mln
/// Image rvalue type.
typedef mln_rvalue(I) rvalue;
/// Qualified value type.
typedef value value_;
/// pixel iterator value.
lvalue operator*();
......@@ -102,15 +102,15 @@ namespace mln
{
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;
......
......@@ -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 @@ namespace mln
{
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 @@ namespace mln
/// 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);
......
......@@ -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
......@@ -163,27 +166,27 @@
* \c I is an image type
* \c T is the new value type
*/
# define mln_ch_value(I, T) typename I::template change_value<T>::ret
# define mln_ch_value(I, T) typename I ::template change_value< T >::ret
// FIXME: Doc!
# define mln_fwd_pixter(I) typename mln::trait::fwd_pixter<I>::ret
# define mln_fwd_pixter_(I) mln::trait::fwd_pixter<I>::ret
# define mln_fwd_pixter(I) typename mln::trait::fwd_pixter< I >::ret
# define mln_fwd_pixter_(I) mln::trait::fwd_pixter< I >::ret
# define mln_bkd_pixter(I) typename mln::trait::bkd_pixter<I>::ret
# define mln_bkd_pixter(I) typename mln::trait::bkd_pixter< I >::ret
# define mln_pixter(I) mln_fwd_pixter(I)
# define mln_pixter_(I) mln_fwd_pixter_(I)
# define mln_fwd_qixter(I, W) typename mln::trait::fwd_qixter<I, W>::ret
# define mln_bkd_qixter(I, W) typename mln::trait::bkd_qixter<I, W>::ret
# define mln_fwd_qixter(I, W) typename mln::trait::fwd_qixter< I, W >::ret
# define mln_bkd_qixter(I, W) typename mln::trait::bkd_qixter< I, W >::ret
# define mln_qixter(I, W) mln_fwd_qixter(I, W)
# define mln_fwd_nixter(I, N) typename mln::trait::fwd_nixter<I, N>::ret
# define mln_bkd_nixter(I, N) typename mln::trait::bkd_nixter<I, N>::ret
# define mln_fwd_nixter(I, N) typename mln::trait::fwd_nixter< I, N >::ret
# define mln_bkd_nixter(I, N) typename mln::trait::bkd_nixter< I, N >::ret
# define mln_nixter(I, N) mln_fwd_nixter(I, N)
......
......@@ -45,10 +45,12 @@ namespace mln
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 @@ namespace mln
unsigned row_offset_;
/// End of the current row.
value_* eor_;
mln_qlf_value(I)* eor_;
};
......
// 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
......@@ -44,7 +44,7 @@ namespace mln
/*! 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
......
......@@ -84,8 +84,8 @@ namespace mln
/// 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 @@ namespace mln
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...
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment