Commit 5694516b authored by Thierry Geraud's avatar Thierry Geraud
Browse files

Make milena work correctly with g++-2.95.

	* mln/core/exact.hh (force_exact): Move in...
	* mln/core/internal/force_exact.hh: ...this new file.
	(force_exact_): Now a method and g++-2.95 compatible.
	* mln/core/concept/genpoint.hh: Update.
	* mln/core/dpoints_piter.hh: Update.
	* mln/core/internal/coord_impl.hh: Update.

	* tests/window2d.cc: New.
	* tests/box2d.cc: New.
	* tests/point2d.cc: New.
	* tests/dpoint2d.cc: New.
	* mln/fun: New.
	* mln/fun/all.hh: New.
	* mln/core/window.hh (is_centered): Update.

	* doc/Doxyfile.in (PREDEFINED): Add extra macros.
	* mln/core/point.hh (point_): Change arg from val to fun.
	* mln/core/dpoint.hh (dpoint_): Change arg from val to fun.
	* mln/core/image2d.hh: Add explicit typedefs.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@1001 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 7602c6f9
2007-07-06 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Make milena work correctly with g++-2.95.
* mln/core/exact.hh (force_exact): Move in...
* mln/core/internal/force_exact.hh: ...this new file.
(force_exact_): Now a method and g++-2.95 compatible.
* mln/core/concept/genpoint.hh: Update.
* mln/core/dpoints_piter.hh: Update.
* mln/core/internal/coord_impl.hh: Update.
* tests/window2d.cc: New.
* tests/box2d.cc: New.
* tests/point2d.cc: New.
* tests/dpoint2d.cc: New.
* mln/fun: New.
* mln/fun/all.hh: New.
* mln/core/window.hh (is_centered): Update.
* doc/Doxyfile.in (PREDEFINED): Add extra macros.
* mln/core/point.hh (point_): Change arg from val to fun.
* mln/core/dpoint.hh (dpoint_): Change arg from val to fun.
* mln/core/image2d.hh: Add explicit typedefs.
2007-07-05 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Add extra documentation to milena.
......
......@@ -1041,9 +1041,21 @@ INCLUDE_FILE_PATTERNS =
# undefined via #undef or recursively expanded use the := operator
# instead of the = operator.
PREDEFINED = \
"mln_coord(T)=typename T::coord" \
"mln_point(T)=typename T::point" \
PREDEFINED = \
"mln_piter(T)=typename T::piter" \
"mln_fwd_piter(T)=typename T::fwd_piter" \
"mln_bkd_piter(T)=typename T::bkd_piter" \
"mln_qiter(T)=typename T::qiter" \
"mln_fwd_qiter(T)=typename T::fwd_qiter" \
"mln_bkd_qiter(T)=typename T::bkd_qiter" \
"mln_niter(T)=typename T::niter" \
"mln_fwd_niter(T)=typename T::fwd_niter" \
"mln_bkd_niter(T)=typename T::bkd_niter" \
"mln_value(T)=typename T::value" \
"mln_rvalue(T)=typename T::rvalue" \
"mln_lvalue(T)=typename T::lvalue" \
"mln_coord(T)=typename T::coord" \
"mln_point(T)=typename T::point" \
"mln_dpoint(T)=typename T::dpoint"
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES
......
......@@ -36,8 +36,10 @@
# include <mlc/same_coord.hh>
# include <mln/core/concept/object.hh>
# include <mln/core/macros.hh>
# include <mln/core/contract.hh>
# include <mln/core/internal/force_exact.hh>
namespace mln
......@@ -57,7 +59,8 @@ namespace mln
* class contents.
*/
template <typename E>
struct GenPoint // stand-alone class!
struct GenPoint
// : virtual internal::object_<E>
{
/*
......@@ -75,8 +78,11 @@ namespace mln
coord operator[](unsigned i) const;
*/
mln_internal_add_force_exact_(GenPoint<E>)
protected:
GenPoint();
};
......@@ -189,8 +195,9 @@ namespace mln
template <typename E>
GenPoint<E>::GenPoint()
{
const int dim = E::dim;
int dim = E::dim;
mln_invariant(dim > 0);
dim = 0;
typedef mln_point(E) point;
typedef mln_dpoint(E) dpoint;
typedef mln_coord(E) coord;
......@@ -204,8 +211,8 @@ namespace mln
bool operator==(const GenPoint<Pl>& lhs, const GenPoint<Pr>& rhs)
{
// FIXME: mlc::same_grid<Pl, Pr>::check();
const Pl& lhs_ = force_exact<Pl>(lhs);
const Pr& rhs_ = force_exact<Pr>(rhs);
const Pl& lhs_ = lhs.force_exact_();
const Pr& rhs_ = rhs.force_exact_();
mlc::same_point<Pl, Pr>::check();
for (unsigned i = 0; i < Pl::dim; ++i)
if (lhs_[i] != rhs_[i])
......@@ -217,8 +224,8 @@ namespace mln
bool operator<(const GenPoint<Pl>& lhs, const GenPoint<Pr>& rhs)
{
// FIXME: mlc::same_grid<Pl, Pr>::check();
const Pl& lhs_ = force_exact<Pl>(lhs);
const Pr& rhs_ = force_exact<Pr>(rhs);
const Pl& lhs_ = lhs.force_exact_();
const Pr& rhs_ = rhs.force_exact_();
for (unsigned i = 0; i < Pl::dim; ++i)
{
if (lhs_[i] == rhs_[i])
......@@ -235,8 +242,8 @@ namespace mln
mlc::equal<mln_dpoint(Pl), mln_dpoint(Pr)>::check();
// FIXME: mlc::same_grid<Pl, Pr>::check();
mlc::same_coord<Pl, Pr>::check();
const Pl& lhs_ = force_exact<Pl>(lhs);
const Pr& rhs_ = force_exact<Pr>(rhs);
const Pl& lhs_ = lhs.force_exact_();
const Pr& rhs_ = rhs.force_exact_();
mln_dpoint(Pl) tmp;
for (unsigned i = 0; i < Pl::dim; ++i)
tmp[i] = lhs_[i] - rhs_[i];
......@@ -248,7 +255,7 @@ namespace mln
mln_point(P)
operator+(const GenPoint<P>& lhs, const mln_dpoint(P)& rhs)
{
const P& lhs_ = force_exact<P>(lhs);
const P& lhs_ = lhs.force_exact_();
mln_point(P) tmp;
for (unsigned i = 0; i < P::dim; ++i)
tmp[i] = lhs_[i] + rhs[i];
......@@ -258,7 +265,8 @@ namespace mln
template <typename P>
std::ostream& operator<<(std::ostream& ostr, const GenPoint<P>& p)
{
const P& p_ = force_exact<P>(p);
const P& p_ = p.force_exact_();
ostr << '(';
for (unsigned i = 0; i < P::dim; ++i)
{
......
......@@ -83,9 +83,10 @@ namespace mln
*/
dpoint_();
/*! \brief Constructor; all coordinates are set to the value \p c.
/*! \brief Constructor; coordinates are set by function \p f.
*/
dpoint_(C c);
template <typename F>
dpoint_(F f);
/*! \brief Set all coordinates to the value \p c.
*/
......@@ -118,9 +119,11 @@ namespace mln
}
template <unsigned n, typename C>
dpoint_<n,C>::dpoint_(C c)
template <typename F>
dpoint_<n,C>::dpoint_(F f)
{
set_all(c);
for (unsigned i = 0; i < n; ++i)
coord_[i] = f(i);
}
template <unsigned n, typename C>
......
......@@ -112,7 +112,7 @@ namespace mln
dpoints_fwd_piter<D>::dpoints_fwd_piter(const Dps& dps,
const GenPoint<Pref>& p_ref)
: dps_(exact(dps).vec()),
p_ref_(* force_exact<Pref>(p_ref).pointer())
p_ref_(* p_ref.force_exact_().pointer())
{
invalidate();
}
......
......@@ -66,57 +66,6 @@ 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.
*
* This cast is an alternative to the mln::exact cast. It is used
* for objects than do not derive from mln::Object.
*
* It preserves the nature (pointer or reference, const or mutable)
* of its argument. The parameter \a E should not have qualifiers.
*
* \warning Prefer not to use this cast!
*
* \see mln::exact
* \todo Move into mln::internal.
*/
/// \{
template <typename E, typename O>
E* force_exact(O* ptr);
template <typename E, typename O>
const E* force_exact(const O* ptr);
template <typename E, typename O>
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
......@@ -147,39 +96,6 @@ namespace mln
return *(const E*)(const void*)(&ref);
}
// force_exact
template <typename E, typename O>
E* force_exact(O* ptr)
{
return (E*)(void*)ptr;
}
template <typename E, typename O>
const E* force_exact(const O* ptr)
{
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>
// const E& force_exact(const O& ref)
// {
// return *(const E*)(const void*)(&ref);
// }
template <typename E, typename O>
typename internal::helper_force_exact_<E, O>::ret &
force_exact(O& ref)
{
return *(E*)(void*)(&ref);
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
......
......@@ -48,6 +48,17 @@ namespace mln
template <typename T>
struct image2d : public internal::image_base_< box2d, image2d<T> >
{
// warning: just to make effective types appear in Doxygen
typedef box2d pset;
typedef point2d psite;
typedef point2d point;
typedef mln_fwd_piter(box2d) fwd_piter;
typedef mln_bkd_piter(box2d) bkd_piter;
typedef fwd_piter piter;
// end of warning
/// Value associated type.
typedef T value;
......
......@@ -29,10 +29,13 @@
# define MLN_CORE_INTERNAL_COORD_IMPL_HH
/*! \file mln/core/internal/coord_impl.hh
*
* \internal
*
* \brief Define some implementation classes for generalized points.
*/
# include <mln/core/internal/force_exact.hh>
# include <mln/core/concept/object.hh>
......@@ -42,6 +45,13 @@ namespace mln
namespace internal
{
template <typename E>
struct coord_impl_base_
{
mln_internal_add_force_exact_(coord_impl_base_<E>)
};
// coord_impl
/*! \brief Implementation class to equip generalized points with
......@@ -54,12 +64,17 @@ namespace mln
template <typename C, typename E>
struct coord_impl_<1, C, E>
: coord_impl_base_<E>
{
C ind() const;
private:
typedef coord_impl_<1, C, E> self_;
};
template <typename C, typename E>
struct coord_impl_<2, C, E>
: coord_impl_base_<E>
{
C row() const;
C col() const;
......@@ -67,6 +82,7 @@ namespace mln
template <typename C, typename E>
struct coord_impl_<3, C, E>
: coord_impl_base_<E>
{
C sli() const;
C row() const;
......@@ -81,6 +97,7 @@ namespace mln
template <typename C, typename E>
struct mutable_coord_impl_<1, C, E>
: coord_impl_base_<E>
{
C ind() const;
C& ind();
......@@ -88,6 +105,7 @@ namespace mln
template <typename C, typename E>
struct mutable_coord_impl_<2, C, E>
: coord_impl_base_<E>
{
C row() const;
C& row();
......@@ -97,6 +115,7 @@ namespace mln
template <typename C, typename E>
struct mutable_coord_impl_<3, C, E>
: coord_impl_base_<E>
{
C sli() const;
C& sli();
......@@ -116,7 +135,7 @@ namespace mln
template <typename C, typename E>
C coord_impl_<1, C, E>::ind() const
{
return force_exact<E>(*this)[0];
return this->force_exact_()[0];
}
// 2
......@@ -124,13 +143,13 @@ namespace mln
template <typename C, typename E>
C coord_impl_<2, C, E>::row() const
{
return force_exact<E>(*this)[0];
return this->force_exact_()[0];
}
template <typename C, typename E>
C coord_impl_<2, C, E>::col() const
{
return force_exact<E>(*this)[1];
return this->force_exact_()[1];
}
// 3
......@@ -138,19 +157,19 @@ namespace mln
template <typename C, typename E>
C coord_impl_<3, C, E>::sli() const
{
return force_exact<E>(*this)[0];
return this->force_exact_()[0];
}
template <typename C, typename E>
C coord_impl_<3, C, E>::row() const
{
return force_exact<E>(*this)[1];
return this->force_exact_()[1];
}
template <typename C, typename E>
C coord_impl_<3, C, E>::col() const
{
return force_exact<E>(*this)[2];
return this->force_exact_()[2];
}
......@@ -161,13 +180,13 @@ namespace mln
template <typename C, typename E>
C mutable_coord_impl_<1, C, E>::ind() const
{
return force_exact<E>(*this)[0];
return this->force_exact_()[0];
}
template <typename C, typename E>
C& mutable_coord_impl_<1, C, E>::ind()
{
return force_exact<E>(*this)[0];
return this->force_exact_()[0];
}
// 2
......@@ -175,25 +194,25 @@ namespace mln
template <typename C, typename E>
C mutable_coord_impl_<2, C, E>::row() const
{
return force_exact<E>(*this)[0];
return this->force_exact_()[0];
}
template <typename C, typename E>
C& mutable_coord_impl_<2, C, E>::row()
{
return force_exact<E>(*this)[0];
return this->force_exact_()[0];
}
template <typename C, typename E>
C mutable_coord_impl_<2, C, E>::col() const
{
return force_exact<E>(*this)[1];
return this->force_exact_()[1];
}
template <typename C, typename E>
C& mutable_coord_impl_<2, C, E>::col()
{
return force_exact<E>(*this)[1];
return this->force_exact_()[1];
}
// 3
......@@ -201,37 +220,37 @@ namespace mln
template <typename C, typename E>
C mutable_coord_impl_<3, C, E>::sli() const
{
return force_exact<E>(*this)[0];
return this->force_exact_()[0];
}
template <typename C, typename E>
C& mutable_coord_impl_<3, C, E>::sli()
{
return force_exact<E>(*this)[0];
return this->force_exact_()[0];
}
template <typename C, typename E>
C mutable_coord_impl_<3, C, E>::row() const
{
return force_exact<E>(*this)[1];
return this->force_exact_()[1];
}
template <typename C, typename E>
C& mutable_coord_impl_<3, C, E>::row()
{
return force_exact<E>(*this)[1];
return this->force_exact_()[1];
}
template <typename C, typename E>
C mutable_coord_impl_<3, C, E>::col() const
{
return force_exact<E>(*this)[2];
return this->force_exact_()[2];
}
template <typename C, typename E>
C& mutable_coord_impl_<3, C, E>::col()
{
return force_exact<E>(*this)[2];
return this->force_exact_()[2];
}
# endif // ! MLN_INCLUDE_ONLY
......
// 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_INTERNAL_FORCE_EXACT_HH
# define MLN_CORE_INTERNAL_FORCE_EXACT_HH
/*! \file mln/core/internal/force_exact.hh
*
* \brief Definition of a macro for internal use only.
*/
/*! \brief Macro to add a violent exact cast method.
*
* \internal
*
* This cast is an alternative to the mln::exact cast. It is used
* for objects than do not derive from mln::Object.
*
* \warning Do not to use this cast!
*
* \see mln::exact
*/
# define mln_internal_add_force_exact_(Type) \
\
E& force_exact_() const \
{ \
static const E exact_obj; \
static const Type& exact_obj_ref = exact_obj; \
static const int exact_offset = \
(const char*)(void*)(&exact_obj_ref) \
- (const char*)(void*)(&exact_obj); \
return *(E*)((char*)(this) - exact_offset); \
}
#endif // ! MLN_CORE_INTERNAL_FORCE_EXACT_HH
......@@ -83,9 +83,10 @@ namespace mln
*/
point_();
/*! \brief Constructor; all coordinates are set to the value \p c.
/*! \brief Constructor; coordinates are set by function \p f.
*/
point_(C c);
template <typename F>
point_(F f);
/*! \brief Set all coordinates to the value \p c.
*/
......@@ -102,14 +103,14 @@ namespace mln
C point_<n,C>::operator[](unsigned i) const
{
assert(i < n);
return coord_[i];
return this->coord_[i];
}
template <unsigned n, typename C>
C& point_<n,C>::operator[](unsigned i)
{
assert(i < n);
return coord_[i];
return this->coord_[i];
}
template <unsigned n, typename C>
......@@ -118,9 +119,11 @@ namespace mln
}
template <unsigned n, typename C>
point_<n,C>::point_(C c)
template <typename F>
point_<n,C>::point_(F f)
{
set_all(c);
for (unsigned i = 0; i < n; ++i)
coord_[i] = f(i);
}
template <unsigned n, typename C>
......