Commit 96748a3c authored by Thierry Geraud's avatar Thierry Geraud
Browse files

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.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@997 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 5068ea58
2007-07-05 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.
2007-07-05 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Add extra documentation in milena.
......
......@@ -140,7 +140,7 @@ namespace mln
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;
}
......
......@@ -33,7 +33,7 @@ namespace mln
*/
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 @@ namespace mln
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;
......
......@@ -73,7 +73,8 @@ namespace mln
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
......
......@@ -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
......@@ -39,6 +39,23 @@ namespace mln
/// \}
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 @@ namespace mln
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 @@ namespace mln
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
......
#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 @@ namespace mln
void allocate_();
void deallocate_();
typedef internal::image_base_< box2d, image2d<T> > super;
};
......@@ -74,7 +107,8 @@ namespace mln
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 @@ namespace mln
bool
image2d<T>::has_data() const
{
return buffer_ != 0 and array_ != 0;
return buffer_ != 0 && array_ != 0;
}
template <typename T>
......@@ -120,7 +154,7 @@ namespace mln
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 @@ namespace mln
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()];
}
......
......@@ -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
......
......@@ -71,7 +71,7 @@ namespace mln
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 @@ namespace mln
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
......
......@@ -97,7 +97,7 @@ namespace mln
: 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)
......
......@@ -26,7 +26,7 @@ namespace mln
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 @@ namespace mln
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 @@ namespace mln
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;
}
......
......@@ -34,7 +34,7 @@ namespace mln
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 @@ namespace mln
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 @@ namespace mln
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 @@ namespace mln
{
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)
......
......@@ -21,7 +21,7 @@ namespace mln
{
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)
......
......@@ -97,7 +97,7 @@ namespace mln
{
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 @@ namespace mln
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 @@ namespace mln
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)
......
#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 @@ namespace mln
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 @@ namespace mln
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
......
......@@ -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()
......
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