https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Make milena compile with g++-2.95. * tests/main.cc, * mln/morpho/Rd.hh, * mln/level/fill.hh, * mln/level/compare.hh, * mln/level/paste.hh, * mln/core/macros.hh, * mln/core/box.hh, * mln/core/rectangle2d.hh, * mln/core/concept/box.hh, * mln/core/ops.hh, * mln/core/exact.hh, * mln/core/image2d.hh, * mln/core/contract.hh, * mln/core/box2d.hh, * mln/value/props.hh: Adapt to g++-2.95. mln/core/box.hh | 2 - mln/core/box2d.hh | 4 +-- mln/core/concept/box.hh | 3 +- mln/core/contract.hh | 5 ++-- mln/core/exact.hh | 50 +++++++++++++++++++++++++++++++++++++----------- mln/core/image2d.hh | 42 ++++++++++++++++++++++++++++++++++++---- mln/core/macros.hh | 39 +++++++++++++++++++------------------ mln/core/ops.hh | 4 +-- mln/core/rectangle2d.hh | 2 - mln/level/compare.hh | 6 ++--- mln/level/fill.hh | 8 +++---- mln/level/paste.hh | 2 - mln/morpho/Rd.hh | 6 ++--- mln/value/props.hh | 27 +++++++++++++------------ tests/main.cc | 8 +++---- 15 files changed, 137 insertions(+), 71 deletions(-) Index: tests/main.cc --- tests/main.cc (revision 996) +++ tests/main.cc (working copy) @@ -16,10 +16,10 @@ typedef unsigned char int_u8; -int_u8 cos_sin(const mln::point2d& p) -{ - return (int_u8)(255 * std::cos(float(p.row())) * std::sin(float(p.col()))); -} +// static int_u8 cos_sin(const mln::point2d& p) +// { +// return (int_u8)(255 * std::cos(float(p.row())) * std::sin(float(p.col()))); +// } int main() Index: mln/morpho/Rd.hh --- mln/morpho/Rd.hh (revision 996) +++ mln/morpho/Rd.hh (working copy) @@ -97,7 +97,7 @@ { if (f.has(n)) assert(is_proc(n) = is_proc__(n, p)); - if (f.has(n) and is_proc(n)) + if (f.has(n) && is_proc(n)) do_union(n, p); } is_proc(p) = true; @@ -119,7 +119,7 @@ bool is_proc__(const point& n, const point& p) const { - return g(n) > g(p) or (g(n) = g(p) and n < p); + return g(n) > g(p) || (g(n) = g(p) && n < p); } void make_set(const point& p) @@ -137,7 +137,7 @@ bool equiv(const point& r, const point& p) { - return g(r) = g(p) or g(p) >= o(r); + return g(r) = g(p) || g(p) >= o(r); } void do_union(const point& n, const point& p) Index: mln/level/fill.hh --- mln/level/fill.hh (revision 996) +++ mln/level/fill.hh (working copy) @@ -34,7 +34,7 @@ const mln_value(I)& value) { I& ima = exact(ima_); - assert(ima.has_data()); + mln_precondition(ima.has_data()); mln_piter(I) p(ima.domain()); for_all(p) ima(p) = value; @@ -45,7 +45,7 @@ mln_value(I) (*f)(const mln_point(I)& p)) { I& ima = exact(ima_); - assert(ima.has_data()); + mln_precondition(ima.has_data()); mln_piter(I) p(ima.domain()); for_all(p) ima(p) = f(p); @@ -56,7 +56,7 @@ const mln_value(I) array[]) { I& ima = exact(ima_); - assert(ima.has_data()); + mln_precondition(ima.has_data()); mln_piter(I) p(ima.domain()); unsigned i = 0; for_all(p) @@ -69,7 +69,7 @@ { I& ima = exact(ima_); const J& data = exact(data_); - assert(ima.has_data() and data.has_data()); + mln_precondition(ima.has_data() && data.has_data()); mln_piter(I) p(ima.domain()); for_all(p) Index: mln/level/compare.hh --- mln/level/compare.hh (revision 996) +++ mln/level/compare.hh (working copy) @@ -26,7 +26,7 @@ const R& rhs = exact(rhs_); mln_piter(L) p(lhs.domain()); for_all(p) - if (not (lhs(p) = rhs(p))) + if (! (lhs(p) = rhs(p))) return false; return true; } @@ -38,7 +38,7 @@ const R& rhs = exact(rhs_); mln_piter(L) p(lhs.domain()); for_all(p) - if (not (lhs(p) < rhs(p))) + if (! (lhs(p) < rhs(p))) return false; return true; } @@ -50,7 +50,7 @@ const R& rhs = exact(rhs_); mln_piter(L) p(lhs.domain()); for_all(p) - if (not (lhs(p) <= rhs(p))) + if (! (lhs(p) <= rhs(p))) return false; return true; } Index: mln/level/paste.hh --- mln/level/paste.hh (revision 996) +++ mln/level/paste.hh (working copy) @@ -21,7 +21,7 @@ { const I& data = exact(data_); I& destination = exact(destination_); - assert(ima.has_data() and destination.has_data()); + assert(ima.has_data() && destination.has_data()); mln_piter(I) p(data.domain()); for_all(p) Index: mln/core/macros.hh --- mln/core/macros.hh (revision 996) +++ mln/core/macros.hh (working copy) @@ -2,65 +2,66 @@ # define MLN_CORE_MACROS_HH /*! \file mln/core/macros.hh - * Definition of the set of milena macros. + * + * \brief Definition of the set of milena macros. */ -/// \brief Shortcut to access the point type associated to T. +/// Shortcut to access the point type associated to T. # define mln_point(T) typename T::point -/// \brief Shortcut to access the dpoint type associated to T. +/// Shortcut to access the dpoint type associated to T. # define mln_dpoint(T) typename T::dpoint -/// \brief Shortcut to access the psite type associated to T. +/// Shortcut to access the psite type associated to T. # define mln_psite(T) typename T::psite -/// \brief Shortcut to access the pset type associated to T. +/// Shortcut to access the pset type associated to T. # define mln_pset(T) typename T::pset -/// \brief Shortcut to access the box type associated to T. +/// Shortcut to access the box type associated to T. # define mln_box(T) typename T::box -/// \brief Shortcut to access the coord type associated to T. +/// Shortcut to access the coord type associated to T. # define mln_coord(T) typename T::coord -/// \brief Shortcut to access the piter type associated to T. +/// Shortcut to access the piter type associated to T. # define mln_piter(T) typename T::piter -/// \brief Shortcut to access the fwd_piter type associated to T. +/// Shortcut to access the fwd_piter type associated to T. # define mln_fwd_piter(T) typename T::fwd_piter -/// \brief Shortcut to access the bkd_piter type associated to T. +/// Shortcut to access the bkd_piter type associated to T. # define mln_bkd_piter(T) typename T::bkd_piter -/// \brief Shortcut to access the qiter type associated to T. +/// Shortcut to access the qiter type associated to T. # define mln_qiter(T) typename T::qiter -/// \brief Shortcut to access the fwd_qiter type associated to T. +/// Shortcut to access the fwd_qiter type associated to T. # define mln_fwd_qiter(T) typename T::fwd_qiter -/// \brief Shortcut to access the bkd_qiter type associated to T. +/// Shortcut to access the bkd_qiter type associated to T. # define mln_bkd_qiter(T) typename T::bkd_qiter -/// \brief Shortcut to access the niter type associated to T. +/// Shortcut to access the niter type associated to T. # define mln_niter(T) typename T::niter -/// \brief Shortcut to access the fwd_niter type associated to T. +/// Shortcut to access the fwd_niter type associated to T. # define mln_fwd_niter(T) typename T::fwd_niter -/// \brief Shortcut to access the bkd_niter type associated to T. +/// Shortcut to access the bkd_niter type associated to T. # define mln_bkd_niter(T) typename T::bkd_niter -/// \brief Shortcut to access the value type associated to T. +/// Shortcut to access the value type associated to T. # define mln_value(T) typename T::value -/// \brief Shortcut to access the rvalue type associated to T. +/// Shortcut to access the rvalue type associated to T. # define mln_rvalue(T) typename T::rvalue -/// \brief Shortcut to access the lvalue type associated to T. +/// Shortcut to access the lvalue type associated to T. # define mln_lvalue(T) typename T::lvalue Index: mln/core/box.hh --- mln/core/box.hh (revision 996) +++ mln/core/box.hh (working copy) @@ -140,7 +140,7 @@ box_<P>::has(const P& p) const { for (unsigned i = 0; i < P::dim; ++i) - if (p[i] < pmin_[i] or p[i] > pmax_[i]) + if (p[i] < pmin_[i] || p[i] > pmax_[i]) return false; return true; } Index: mln/core/rectangle2d.hh --- mln/core/rectangle2d.hh (revision 996) +++ mln/core/rectangle2d.hh (working copy) @@ -97,7 +97,7 @@ : half_height_(half_height), half_width_(half_width) { - assert(half_height != 0 and half_width != 0); + mln_precondition(half_height != 0 && half_width != 0); const int drow = half_height, dcol = half_width; for (int row = - drow; row <= drow; ++row) for (int col = - dcol; col <= dcol; ++col) Index: mln/core/concept/box.hh --- mln/core/concept/box.hh (revision 996) +++ mln/core/concept/box.hh (working copy) @@ -73,7 +73,8 @@ Box<E>::npoints() const { std::size_t count = 1; - for (unsigned i = 0; i < E::point::dim; ++i) + typedef typename E::point P; // helps g++-3.3.5 + for (unsigned i = 0; i < P::dim; ++i) count * exact(this)->pmax()[i] + 1 Index: mln/core/ops.hh --- mln/core/ops.hh (revision 996) +++ mln/core/ops.hh (working copy) @@ -71,7 +71,7 @@ template <typename O1, typename O2> bool operator!=(const Object<O1>& lhs, const Object<O2>& rhs) { - return not (exact(lhs) = exact(rhs)); + return ! (exact(lhs) = exact(rhs)); } template <typename O1, typename O2> @@ -90,7 +90,7 @@ bool operator<=(const Object<O1>& lhs, const Object<O2>& rhs) { // if partial ordering, this operator should be re-defined! - return not (exact(rhs) < exact(lhs)); + return ! (exact(rhs) < exact(lhs)); } # endif // ! MLN_INCLUDE_ONLY Index: mln/core/exact.hh --- mln/core/exact.hh (revision 996) +++ mln/core/exact.hh (working copy) @@ -39,6 +39,23 @@ /// \} + namespace internal + { + + template <typename E, typename O> + struct helper_force_exact_ + { + typedef E ret; + }; + + template <typename E, typename O> + struct helper_force_exact_< E, const O > + { + typedef const E ret; + }; + + } // end of namespace mln::internal + /*! \brief Violent exact cast routine. * @@ -62,14 +79,18 @@ const E* force_exact(const O* ptr); template <typename E, typename O> - E& force_exact(O& ref); - - template <typename E, typename O> - const E& force_exact(const O& ref); + typename internal::helper_force_exact_<E, O>::ret & // help g++-3.3 + force_exact(O& ref); /// \} +// template <typename E, typename O> +// E& force_exact(O& ref); + +// template <typename E, typename O> +// const E& force_exact(const O& ref); + # ifndef MLN_INCLUDE_ONLY @@ -113,16 +134,23 @@ return (const E*)(const void*)ptr; } - template <typename E, typename O> - E& force_exact(O& ref) - { - return *(E*)(void*)(&ref); - } +// template <typename E, typename O> +// E& force_exact(O& ref) +// { +// return *(E*)(void*)(&ref); +// } + +// template <typename E, typename O> +// const E& force_exact(const O& ref) +// { +// return *(const E*)(const void*)(&ref); +// } template <typename E, typename O> - const E& force_exact(const O& ref) + typename internal::helper_force_exact_<E, O>::ret & + force_exact(O& ref) { - return *(const E*)(const void*)(&ref); + return *(E*)(void*)(&ref); } # endif // ! MLN_INCLUDE_ONLY Index: mln/core/image2d.hh --- mln/core/image2d.hh (revision 996) +++ mln/core/image2d.hh (working copy) @@ -1,6 +1,11 @@ #ifndef MLN_CORE_IMAGE2D_HH # define MLN_CORE_IMAGE2D_HH +/*! \file mln/core/image2d.hh + * + * \brief Definition of the basic mln::image2d class. + */ + # include <mln/core/internal/image_base.hh> # include <mln/core/box2d.hh> @@ -8,32 +13,58 @@ namespace mln { + /*! \brief Basic 2D image class. + * + * The parameter \c T is the type of pixel values. This image class + * stores data in memory and has no virtual border. + */ template <typename T> struct image2d : public internal::image_base_< box2d, image2d<T> > { + /// Value associated type. typedef T value; + + /// Return type of read-only access. typedef const T& rvalue; + + /// Return type of read-write access. typedef T& lvalue; + /// Change value type. template <typename U> struct change_value { typedef image2d<U> ret; }; + /// Constructor without argument. image2d(); + + /// Constructor with the numbers of rows and columns. image2d(int nrows, int ncols); + + /// Constructor with a box. image2d(const box2d& b); + + /// Copy constructor. image2d(const image2d<T>& rhs); + /// Assignment operator. image2d& operator=(const image2d<T>& rhs); + /// Test if this image has been initialized. bool has_data() const; + + /// Give the definition domain. const box2d& domain() const; + /// Read-only access to the image value located at \p p. const T& operator()(const point2d& p) const; + + /// Read-write access to the image value located at \p p. T& operator()(const point2d& p); + /// Destructor. ~image2d(); private: @@ -44,6 +75,8 @@ void allocate_(); void deallocate_(); + + typedef internal::image_base_< box2d, image2d<T> > super; }; @@ -74,7 +107,8 @@ template <typename T> image2d<T>::image2d(const image2d<T>& rhs) - : b_(rhs.domain()) + : super(rhs), + b_(rhs.domain()) { allocate_(); std::memcpy(this->buffer_, @@ -106,7 +140,7 @@ bool image2d<T>::has_data() const { - return buffer_ != 0 and array_ != 0; + return buffer_ != 0 && array_ != 0; } template <typename T> @@ -120,7 +154,7 @@ const T& image2d<T>::operator()(const point2d& p) const { - assert(this->has_data() and this->owns_(p)); + assert(this->has_data() && this->owns_(p)); return array_[p.row()][p.col()]; } @@ -128,7 +162,7 @@ T& image2d<T>::operator()(const point2d& p) { - assert(this->has_data() and this->owns_(p)); + assert(this->has_data() && this->owns_(p)); return array_[p.row()][p.col()]; } Index: mln/core/contract.hh --- mln/core/contract.hh (revision 996) +++ mln/core/contract.hh (working copy) @@ -2,7 +2,8 @@ # define MLN_CORE_CONTRACT_HH /*! \file mln/core/contract.hh - * Definition of the set of contracts. + * + * \brief Definition of the set of contracts. */ # include <cassert> @@ -21,7 +22,7 @@ # define mln_postcondition(expr) assert(expr) /// Implication. -# define mln_implies(lexpr, repxr) assert(not (rexpr) or (lexpr)) +# define mln_implies(lexpr, repxr) assert(! (rexpr) || (lexpr)) #endif // ! MLN_CORE_CONTRACT_HH Index: mln/core/box2d.hh --- mln/core/box2d.hh (revision 996) +++ mln/core/box2d.hh (working copy) @@ -33,7 +33,7 @@ */ box2d mk_box2d(unsigned nrows, unsigned ncols) { - mln_precondition(nrows != 0 and ncols != 0); + mln_precondition(nrows != 0 && ncols != 0); box2d tmp(mk_point2d(0, 0), mk_point2d(nrows - 1, ncols - 1)); return tmp; @@ -56,7 +56,7 @@ box2d mk_box2d(int min_row, int max_row, int min_col, int max_col) { - mln_precondition(max_row >= min_row and max_col >= min_col); + mln_precondition(max_row >= min_row && max_col >= min_col); box2d tmp(mk_point2d(min_row, min_col), mk_point2d(max_row, max_col)); return tmp; Index: mln/value/props.hh --- mln/value/props.hh (revision 996) +++ mln/value/props.hh (working copy) @@ -1,7 +1,8 @@ #ifndef MLN_VALUE_PROPS_HH # define MLN_VALUE_PROPS_HH -# include <limits> +# include <climits> +# include <cfloat> # define mln_min(T) mln::value::props<T>::min() # define mln_max(T) mln::value::props<T>::max() @@ -63,29 +64,29 @@ template <> struct props<unsigned int> { - static unsigned int min() { return std::numeric_limits<unsigned int>::min(); } - static unsigned int max() { return std::numeric_limits<unsigned int>::max(); } + static unsigned int min() { return 0; } + static unsigned int max() { return UINT_MAX; } }; template <> struct props<signed int> { - static signed int min() { return std::numeric_limits<signed int>::min(); } - static signed int max() { return std::numeric_limits<signed int>::max(); } + static signed int min() { return INT_MIN; } + static signed int max() { return INT_MAX; } }; template <> struct props<unsigned long int> { - static unsigned long int min() { return std::numeric_limits<unsigned long int>::min(); } - static unsigned long int max() { return std::numeric_limits<unsigned long int>::max(); } + static unsigned long int min() { return 0; } + static unsigned long int max() { return ULONG_MAX; } }; template <> struct props<signed long int> { - static signed long int min() { return std::numeric_limits<signed long int>::min(); } - static signed long int max() { return std::numeric_limits<signed long int>::max(); } + static signed long int min() { return LONG_MIN; } + static signed long int max() { return LONG_MAX; } }; // floating @@ -93,15 +94,15 @@ template <> struct props<float> { - static float min() { return std::numeric_limits<float>::min(); } - static float max() { return std::numeric_limits<float>::max(); } + static float min() { return FLT_MIN; } + static float max() { return FLT_MAX; } }; template <> struct props<double> { - static double min() { return std::numeric_limits<double>::min(); } - static double max() { return std::numeric_limits<double>::max(); } + static double min() { return DBL_MIN; } + static double max() { return DBL_MAX; } }; # endif // ! MLN_INCLUDE_ONLY