* mln/value/internal/limits.hh: add support for std::numeric_limits with gcc 2.95. * headers.mk: add limits.hh. * mln/topo/complex.hh, * mln/topo/face.hh, * mln/topo/n_face.hh, * mln/value/builtin/floatings.hh, * mln/value/builtin/integers.hh: use value::internal::limits. * mln/util/internal/graph_base.hh, * mln/util/tree.hh: use <iostream> instead of <ostream>. * mln/core/dpoint.hh, * mln/core/point.hh: Help the compiler resolving 'G::dim' in method return type. * mln/value/float01.hh: use '&&' operator instead of 'and'. * tests/unit_test/Makefile.am, * tests/unit_test/mln_value_internal_limits.cc: Add new unit test. --- milena/ChangeLog | 26 +++ milena/headers.mk | 1 + milena/mln/core/dpoint.hh | 47 ++--- milena/mln/core/point.hh | 61 +++--- milena/mln/topo/complex.hh | 49 ++--- milena/mln/topo/face.hh | 24 +- milena/mln/topo/n_face.hh | 20 +- milena/mln/util/internal/graph_base.hh | 2 +- milena/mln/util/tree.hh | 2 +- milena/mln/value/builtin/floatings.hh | 22 +- milena/mln/value/builtin/integers.hh | 14 +- milena/mln/value/float01.hh | 4 +- milena/mln/value/internal/limits.hh | 220 ++++++++++++++++++++ milena/tests/unit_test/Makefile.am | 8 + .../tests/unit_test/mln_value_internal_limits.cc | 11 + 15 files changed, 386 insertions(+), 125 deletions(-) create mode 100644 milena/mln/value/internal/limits.hh create mode 100644 milena/tests/unit_test/mln_value_internal_limits.cc diff --git a/milena/ChangeLog b/milena/ChangeLog index 1ae05f4..8e4bb36 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,31 @@ 2008-12-29 Guillaume Lazzara <z@lrde.epita.fr> + Fix issues with GCC 2.95. + + * mln/value/internal/limits.hh: add support for std::numeric_limits with gcc 2.95. + + * headers.mk: add limits.hh. + + * mln/topo/complex.hh, + * mln/topo/face.hh, + * mln/topo/n_face.hh, + * mln/value/builtin/floatings.hh, + * mln/value/builtin/integers.hh: use value::internal::limits. + + + * mln/util/internal/graph_base.hh, + * mln/util/tree.hh: use <iostream> instead of <ostream>. + + * mln/core/dpoint.hh, + * mln/core/point.hh: Help the compiler resolving 'G::dim' in method return type. + + * mln/value/float01.hh: use '&&' operator instead of 'and'. + + * tests/unit_test/Makefile.am, + * tests/unit_test/mln_value_internal_limits.cc: Add new unit test. + +2008-12-29 Guillaume Lazzara <z@lrde.epita.fr> + Update tutorial according to the last renamings. * apps/statues/mesh-complex-segm.cc, diff --git a/milena/headers.mk b/milena/headers.mk index 7111d16..faea509 100644 --- a/milena/headers.mk +++ b/milena/headers.mk @@ -287,6 +287,7 @@ mln/value/internal/gray_f.hh \ mln/value/internal/all.hh \ mln/value/internal/value_like.hh \ mln/value/internal/iterable_set.hh \ +mln/value/internal/limits.hh \ mln/value/internal/encoding.hh \ mln/value/internal/convert.hh \ mln/value/internal/gray_.hh \ diff --git a/milena/mln/core/dpoint.hh b/milena/mln/core/dpoint.hh index f634cc3..4cb55bd 100644 --- a/milena/mln/core/dpoint.hh +++ b/milena/mln/core/dpoint.hh @@ -29,10 +29,9 @@ #ifndef MLN_CORE_DPOINT_HH # define MLN_CORE_DPOINT_HH -/*! \file mln/core/dpoint.hh - * - * \brief Definition of the generic delta-point class mln::dpoint. - */ +/// \file mln/core/dpoint.hh +/// +/// Definition of the generic delta-point class mln::dpoint. # include <mln/core/def/coord.hh> # include <mln/core/concept/gdpoint.hh> @@ -44,7 +43,7 @@ namespace mln { - /// \{ Fwd decls. + /// \{ Forward declarations. template <typename G, typename C> struct point; namespace literal { struct zero_t; @@ -53,19 +52,17 @@ namespace mln /// \} - /*! \brief Generic delta-point class. - * - * Parameters are \c G the dimension of the space and \c C the - * coordinate type in this space. - */ + /// Generic delta-point class. + /// + /// Parameters are \c G the dimension of the space and \c C the + /// coordinate type in this space. template <typename G, typename C> struct dpoint : public Gdpoint< dpoint<G,C> >, public internal::mutable_coord_impl_< G::dim, C, dpoint<G,C> > { - /*! \var dim - * \brief Dimension of the space. - * \invariant dim > 0 - */ + /// \var dim + /// Dimension of the space. + /// \invariant dim > 0 enum { dim = G::dim }; /// Grid associated type. @@ -83,16 +80,14 @@ namespace mln /// Algebra vector (vec) associated type. typedef algebra::vec<G::dim, C> vec; - /*! \brief Read-only access to the \p i-th coordinate value. - * \param[in] i The coordinate index. - * \pre \p i < \c dim - */ + /// Read-only access to the \p i-th coordinate value. + /// \param[in] i The coordinate index. + /// \pre \p i < \c dim C operator[](unsigned i) const; - /*! \brief Read-write access to the \p i-th coordinate value. - * \param[in] i The coordinate index. - * \pre \p i < \c dim - */ + /// Read-write access to the \p i-th coordinate value. + /// \param[in] i The coordinate index. + /// \pre \p i < \c dim C& operator[](unsigned i); /// Constructor without argument. @@ -126,10 +121,10 @@ namespace mln /// Conversion towards a algebra::vec. template <typename Q> - operator mln::algebra::vec<G::dim, Q>() const; + operator mln::algebra::vec<dpoint<G,C>::dim, Q>() const; /// Explicit conversion. - const mln::algebra::vec<G::dim, C>& to_vec() const; + const vec& to_vec() const; protected: mln::algebra::vec<G::dim, C> coord_; @@ -251,14 +246,14 @@ namespace mln template <typename G, typename C> template <typename Q> inline - dpoint<G,C>::operator mln::algebra::vec<G::dim, Q> () const + dpoint<G,C>::operator mln::algebra::vec<dpoint<G,C>::dim, Q> () const { return coord_; } template <typename G, typename C> inline - const mln::algebra::vec<G::dim, C>& + const typename dpoint<G,C>::vec& dpoint<G,C>::to_vec() const { return coord_; diff --git a/milena/mln/core/point.hh b/milena/mln/core/point.hh index 25b7bc9..4153a49 100644 --- a/milena/mln/core/point.hh +++ b/milena/mln/core/point.hh @@ -1,4 +1,5 @@ // Copyright (C) 2007, 2008 EPITA Research and Development Laboratory +// (LRDE) // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -28,10 +29,10 @@ #ifndef MLN_CORE_POINT_HH # define MLN_CORE_POINT_HH -/*! \file mln/core/point.hh - * - * \brief Definition of the generic point class mln::point. - */ +/// \file mln/core/point.hh +/// +/// Definition of the generic point class mln::point. + # include <mln/core/def/coord.hh> # include <mln/core/concept/gpoint.hh> @@ -49,7 +50,7 @@ namespace mln { - /// \{ Fwd decls. + /// \{ Forward declarations. template <typename G, typename C> struct point; template <typename G, typename C> struct dpoint; namespace literal { @@ -76,11 +77,10 @@ namespace mln - /*! \brief Generic point class. - * - * Parameters are \c n the dimension of the space and \c C the - * coordinate type in this space. - */ + /// Generic point class. + /// + /// Parameters are \c n the dimension of the space and \c C the + /// coordinate type in this space. template <typename G, typename C> struct point : public Gpoint< point<G,C> >, public internal::mutable_coord_impl_< G::dim, C, point<G,C> > @@ -90,10 +90,9 @@ namespace mln typedef point psite; - /*! \var dim - * \brief Dimension of the space. - * \invariant dim > 0 - */ + /// \var dim + /// Dimension of the space. + /// \invariant dim > 0 enum { dim = G::dim }; /// Grid associated type. @@ -111,16 +110,17 @@ namespace mln /// Algebra vector (vec) associated type. typedef algebra::vec<G::dim, C> vec; - /*! \brief Read-only access to the \p i-th coordinate value. - * \param[in] i The coordinate index. - * \pre \p i < \c dim - */ + /// Algebra hexagonal vector (hvec) associated type. + typedef algebra::h_vec<G::dim, C> h_vec; + + /// Read-only access to the \p i-th coordinate value. + /// \param[in] i The coordinate index. + /// \pre \p i < \c dim const C& operator[](unsigned i) const; - /*! \brief Read-write access to the \p i-th coordinate value. - * \param[in] i The coordinate index. - * \pre \p i < \c dim - */ + /// Read-write access to the \p i-th coordinate value. + /// \param[in] i The coordinate index. + /// \pre \p i < \c dim C& operator[](unsigned i); @@ -187,10 +187,10 @@ namespace mln #endif /// Explicit conversion towards mln::algebra::vec. - const algebra::vec<G::dim, C>& to_vec() const; + const vec& to_vec() const; /// Transform to point in homogene coordinate system. - algebra::h_vec<G::dim, C> to_h_vec() const; + h_vec to_h_vec() const; /// Point with all coordinates set to the maximum value. static const point<G,C>& plus_infty(); @@ -206,7 +206,7 @@ namespace mln /// FIXME... template <typename G, typename C> - const algebra::vec<G::dim - 1, C>& cut_(const point<G,C>& p); + const algebra::vec<point<G,C>::dim - 1, C>& cut_(const point<G,C>& p); template <typename C> const util::yes& cut_(const point<grid::tick,C>& p); @@ -405,15 +405,16 @@ namespace mln template <typename G, typename C> inline - const algebra::vec<G::dim, C>& + const typename point<G,C>::vec& point<G,C>::to_vec() const { return coord_; } - + template <typename G, typename C> inline - algebra::h_vec<G::dim, C> point<G,C>::to_h_vec() const + typename point<G,C>::h_vec + point<G,C>::to_h_vec() const { algebra::h_vec<G::dim, C> tmp; for (unsigned i = 0; i < dim; ++i) @@ -444,10 +445,10 @@ namespace mln template <typename G, typename C> inline - const algebra::vec<G::dim - 1, C>& + const algebra::vec<point<G,C>::dim - 1, C>& cut_(const point<G,C>& p) { - return *(const algebra::vec<G::dim - 1, C>*)(& p.to_vec()); + return *(const algebra::vec<point<G,C>::dim - 1, C>*)(& p.to_vec()); } template <typename C> diff --git a/milena/mln/topo/complex.hh b/milena/mln/topo/complex.hh index 619c3ca..2b392ac 100644 --- a/milena/mln/topo/complex.hh +++ b/milena/mln/topo/complex.hh @@ -29,14 +29,13 @@ # define MLN_TOPO_COMPLEX_HH /// \file mln/topo/complex.hh -/// \brief Structures for general complexes. +/// Structures for general complexes. /// /// A complex defines a topological space which can be used as a /// support for an image (i.e., as site sets). # include <cstddef> -# include <limits> # include <iosfwd> # include <mln/metal/bool.hh> @@ -82,7 +81,7 @@ namespace mln | Complex. | `----------*/ - /// \brief General complex of dimension \p D. + /// General complex of dimension \p D. template <unsigned D> class complex { @@ -107,10 +106,10 @@ namespace mln /// Create a new \p D-complex. complex(); - /// \brief Add a 0-face to the complex. + /// Add a 0-face to the complex. n_face<0u, D> add_face(); - /// \brief Add a \p (N+1)-face to the complex (with \p N >= 0). + /// Add a \p (N+1)-face to the complex (with \p N >= 0). /// /// \param adjacent_faces The (\p N-1)-faces adjacent to the new /// \p N-face. @@ -118,24 +117,24 @@ namespace mln n_face<N + 1, D> add_face(const n_faces_set<N, D>& adjacent_faces); /// \} - /// \brief Static manipulators. + /// Static manipulators. /// /// These methods use statically-known input. /// \{ - /// \brief Return the total number of faces, whatever their + /// Return the total number of faces, whatever their /// dimension. unsigned nfaces() const; - /// \brief Return the number of \p N-faces. + /// Return the number of \p N-faces. template <unsigned N> unsigned nfaces() const; /// \} - /// \brief Dynamic manipulators. + /// Dynamic manipulators. /// /// These methods use input know as run time. /// \{ - /// \brief Return the number of \a n-faces. + /// Return the number of \a n-faces. /// /// Warning, this function has a complexity linear in term of N, /// since each n_faces_set is checked (the present implementation @@ -153,7 +152,7 @@ namespace mln void print_faces(std::ostream& ostr) const; /// \} - /// \brief Get the address of the data of this complex. + /// Get the address of the data of this complex. /// /// This address is a concise and useful information to print /// and track the actual content of this complex. @@ -186,7 +185,7 @@ namespace mln /* FIXME: Replace F and ACCU by a Milena accumulator? */ - /** \brief Apply a kind of static fold left operator to the + /** Apply a kind of static fold left operator to the implicit list of n_faces_set using a functor \a f and a value \a accu. @@ -198,13 +197,13 @@ namespace mln template <typename BinaryFunction, typename T> T fold_left_(const BinaryFunction& f, const T& accu) const; - /// \brief Apply a functor \a f to this list of \a n-faces. + /// Apply a functor \a f to this list of \a n-faces. template <typename UnaryFunction> typename UnaryFunction::result_type apply_if_dim_matches_(unsigned n, const UnaryFunction& f) const; /// \} - /// \brief Connect two algebraic faces. + /// Connect two algebraic faces. /// /// \param f1 An algebraic face of dimension \p N /// \param f2 A face of dimension \p N + 1 @@ -232,7 +231,7 @@ namespace mln | Complex data. | `---------------*/ - /** \brief Complex data. + /** Complex data. Data is aggregated as follows in an mln::topo::complex<D>: @@ -291,7 +290,7 @@ namespace mln template <unsigned N, unsigned D> struct faces_set_mixin; - /// \brief Complex data. + /// Complex data. template <unsigned D> struct complex_data : faces_set_mixin<D, D> { @@ -319,7 +318,7 @@ namespace mln // mln::topo::internal::faces_set_mixin. // // -------------------------------------- // - /// \brief Recursive mixins of set of faces. + /// Recursive mixins of set of faces. /// \{ template <unsigned N, unsigned D> struct faces_set_mixin; @@ -339,11 +338,11 @@ namespace mln /// Functional meta-manipulators. /// \{ - /// \brief Fold left. + /// Fold left. /// \see mln::complex<D>::fold_left_. template <typename BinaryFunction, typename T> T fold_left_(const BinaryFunction& f, const T& accu) const; - /// \brief Apply a functor \a f to the list of faces if \a n == \p D. + /// Apply a functor \a f to the list of faces if \a n == \p D. /// \see mln::complex<D>::apply_if_dim_matches_. template <typename UnaryFunction> typename UnaryFunction::result_type @@ -370,11 +369,11 @@ namespace mln /// Functional meta-manipulators. /// \{ - /// \brief Fold left. + /// Fold left. /// \see mln::complex<D>::fold_left_. template <typename BinaryFunction, typename T> T fold_left_(const BinaryFunction& f, const T& accu) const; - /// \brief Apply a functor \a f to the list of faces if \a n == \p N. + /// Apply a functor \a f to the list of faces if \a n == \p N. /// \see mln::complex<D>::apply_if_dim_matches_. template <typename UnaryFunction> typename UnaryFunction::result_type @@ -397,11 +396,11 @@ namespace mln /// Functional meta-manipulators. /// \{ - /// \brief Fold left. + /// Fold left. /// \see mln::complex<D>::fold_left_. template <typename BinaryFunction, typename T> T fold_left_(const BinaryFunction& f, const T& accu) const; - /// \brief Apply a functor \a f to the list of faces if \a n == 0. + /// Apply a functor \a f to the list of faces if \a n == 0. /// \see mln::complex<D>::apply_if_dim_matches_. template <typename UnaryFunction> typename UnaryFunction::result_type @@ -424,11 +423,11 @@ namespace mln /// Functional meta-manipulators. /// \{ - /// \brief Fold left. + /// Fold left. /// \see mln::complex<D>::fold_left_. template <typename BinaryFunction, typename T> T fold_left_(const BinaryFunction& f, const T& accu) const; - /// \brief Apply a functor \a f to the list of faces if \a n == 0. + /// Apply a functor \a f to the list of faces if \a n == 0. /// \see mln::complex<D>::apply_if_dim_matches_. template <typename UnaryFunction> typename UnaryFunction::result_type diff --git a/milena/mln/topo/face.hh b/milena/mln/topo/face.hh index 3d25954..74077f1 100644 --- a/milena/mln/topo/face.hh +++ b/milena/mln/topo/face.hh @@ -29,12 +29,12 @@ # define MLN_TOPO_FACE_HH /// \file mln/topo/face.hh -/// \brief Face of a complex. +/// Face of a complex. # include <iostream> -# include <limits> # include <vector> +# include <mln/value/internal/limits.hh> # include <mln/core/contract.hh> # include <mln/metal/bool.hh> @@ -56,7 +56,7 @@ namespace mln | Face. | `-------*/ - /// \brief Face handle in a complex; the face dimension is dynamic. + /// Face handle in a complex; the face dimension is dynamic. /// /// Contrary to an mln::topo::n_face, the dimension of an /// mln::topo::face is not fixed. @@ -121,14 +121,14 @@ namespace mln /// \} private: - /// \brief The complex the face belongs to. + /// The complex the face belongs to. /// /// A const face can be used to modify a complex. mutable complex<D> cplx_; /// The dimension of the face. // FIXME: Rename as `dim_'? unsigned n_; - /// \brief The id of the face. + /// The id of the face. // FIXME: Rename as `id_'? unsigned face_id_; }; @@ -137,21 +137,21 @@ namespace mln /// Comparison of two instances of mln::topo::face. /// \{ - /// \brief Is \a lhs equal to \a rhs? + /// Is \a lhs equal to \a rhs? /// /// \pre Arguments \a lhs and \a rhs must belong to the same /// mln::topo::complex. template <unsigned D> bool operator==(const face<D>& lhs, const face<D>& rhs); - /// \brief Is \a lhs different from \a rhs? + /// Is \a lhs different from \a rhs? /// /// \pre Arguments \a lhs and \a rhs must belong to the same /// mln::topo::complex. template <unsigned D> bool operator!=(const face<D>& lhs, const face<D>& rhs); - /// \brief Is \a lhs ``less'' than \a rhs? + /// Is \a lhs ``less'' than \a rhs? /// /// This comparison is required by algorithms sorting face handles. /// @@ -177,8 +177,8 @@ namespace mln inline face<D>::face() : cplx_(), - n_(std::numeric_limits<unsigned>::max()), - face_id_(std::numeric_limits<unsigned>::max()) + n_(value::internal::limits<unsigned>::max()), + face_id_(value::internal::limits<unsigned>::max()) { } @@ -214,8 +214,8 @@ namespace mln void face<D>::invalidate() { - set_n(std::numeric_limits<unsigned>::max()); - set_face_id(std::numeric_limits<unsigned>::max()); + set_n(value::internal::limits<unsigned>::max()); + set_face_id(value::internal::limits<unsigned>::max()); } template <unsigned D> diff --git a/milena/mln/topo/n_face.hh b/milena/mln/topo/n_face.hh index e7a6475..ee146a8 100644 --- a/milena/mln/topo/n_face.hh +++ b/milena/mln/topo/n_face.hh @@ -30,12 +30,12 @@ /// \file mln/topo/n_face.hh /// -/// \brief n-face of a complex. +/// n-face of a complex. # include <iostream> -# include <limits> # include <vector> +# include <mln/value/internal/limits.hh> # include <mln/core/contract.hh> # include <mln/metal/bool.hh> @@ -55,7 +55,7 @@ namespace mln | n-Face. | `---------*/ - /// \brief \p N-face handle in a complex. + /// \p N-face handle in a complex. /// /// Contrary to an mln::topo::face, the dimension of an /// mln::topo::n_face is fixed. @@ -108,11 +108,11 @@ namespace mln /// \} private: - /// \brief The complex the face belongs to. + /// The complex the face belongs to. /// /// A const mln::topo::n_face can be used to modify a complex. mutable complex<D> cplx_; - /// \brief The id of the face. + /// The id of the face. // FIXME: Rename as `id_'? unsigned face_id_; }; @@ -121,21 +121,21 @@ namespace mln /// Comparison of two instances of mln::topo::n_face. /// \{ - /// \brief Is \a lhs equal to \a rhs? + /// Is \a lhs equal to \a rhs? /// /// \pre Arguments \a lhs and \a rhs must belong to the same /// mln::topo::complex. template <unsigned N, unsigned D> bool operator==(const n_face<N, D>& lhs, const n_face<N, D>& rhs); - /// \brief Is \a lhs different from \a rhs? + /// Is \a lhs different from \a rhs? /// /// \pre Arguments \a lhs and \a rhs must belong to the same /// mln::topo::complex. template <unsigned N, unsigned D> bool operator!=(const n_face<N, D>& lhs, const n_face<N, D>& rhs); - /// \brief Is \a lhs ``less'' than \a rhs? + /// Is \a lhs ``less'' than \a rhs? /// /// This comparison is required by algorithms sorting face handles. /// @@ -159,7 +159,7 @@ namespace mln template <unsigned N, unsigned D> inline n_face<N, D>::n_face() - : cplx_(), face_id_(std::numeric_limits<unsigned>::max()) + : cplx_(), face_id_(value::internal::limits<unsigned>::max()) { // Ensure N is compatible with D. metal::bool_< N <= D >::check(); @@ -188,7 +188,7 @@ namespace mln void n_face<N, D>::invalidate() { - set_face_id(std::numeric_limits<unsigned>::max()); + set_face_id(value::internal::limits<unsigned>::max()); } template <unsigned N, unsigned D> diff --git a/milena/mln/util/internal/graph_base.hh b/milena/mln/util/internal/graph_base.hh index ac6099e..f011324 100644 --- a/milena/mln/util/internal/graph_base.hh +++ b/milena/mln/util/internal/graph_base.hh @@ -37,7 +37,7 @@ # include <algorithm> # include <vector> # include <set> -# include <ostream> +# include <iostream> # include <mln/core/concept/object.hh> # include <mln/core/concept/graph.hh> diff --git a/milena/mln/util/tree.hh b/milena/mln/util/tree.hh index 0f09dcf..fc0b029 100644 --- a/milena/mln/util/tree.hh +++ b/milena/mln/util/tree.hh @@ -30,7 +30,7 @@ # include <vector> # include <algorithm> -# include <ostream> +# include <iostream> # include <algorithm> # include <mln/core/contract.hh> diff --git a/milena/mln/value/builtin/floatings.hh b/milena/mln/value/builtin/floatings.hh index 9afbde1..3fd0b50 100644 --- a/milena/mln/value/builtin/floatings.hh +++ b/milena/mln/value/builtin/floatings.hh @@ -1,4 +1,5 @@ // Copyright (C) 2007, 2008 EPITA Research and Development Laboratory +// (LRDE) // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -28,12 +29,11 @@ #ifndef MLN_VALUE_BUILTIN_FLOATINGS_HH # define MLN_VALUE_BUILTIN_FLOATINGS_HH -/*! \file mln/value/builtin/floatings.hh - * - * \brief Some definitions about built-in floating types. - */ +/// \file mln/value/builtin/floatings.hh +/// +/// Some definitions about built-in floating types. -# include <limits> +# include <mln/value/internal/limits.hh> # include <mln/value/concept/built_in.hh> # include <mln/value/concept/floating.hh> @@ -74,17 +74,17 @@ namespace mln static float min() { - static const float min_ = std::numeric_limits<float>::min(); + static const float min_ = mln::value::internal::limits<float>::min(); return min_; } static float max() { - static const float max_ = std::numeric_limits<float>::max(); + static const float max_ = mln::value::internal::limits<float>::max(); return max_; } static float epsilon() { - static const float epsilon_ = std::numeric_limits<float>::epsilon(); + static const float epsilon_ = mln::value::internal::limits<float>::epsilon(); return epsilon_; } @@ -105,17 +105,17 @@ namespace mln static double min() { - static const double min_ = std::numeric_limits<double>::min(); + static const double min_ = mln::value::internal::limits<double>::min(); return min_; } static double max() { - static const double max_ = std::numeric_limits<double>::max(); + static const double max_ = mln::value::internal::limits<double>::max(); return max_; } static double epsilon() { - static const double epsilon_ = std::numeric_limits<double>::epsilon(); + static const double epsilon_ = mln::value::internal::limits<double>::epsilon(); return epsilon_; } diff --git a/milena/mln/value/builtin/integers.hh b/milena/mln/value/builtin/integers.hh index 09dd233..cb4cced 100644 --- a/milena/mln/value/builtin/integers.hh +++ b/milena/mln/value/builtin/integers.hh @@ -1,4 +1,5 @@ // Copyright (C) 2007, 2008 EPITA Research and Development Laboratory +// (LRDE) // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -28,12 +29,11 @@ #ifndef MLN_VALUE_BUILTIN_INTEGERS_HH # define MLN_VALUE_BUILTIN_INTEGERS_HH -/*! \file mln/value/builtin/integers.hh - * - * \brief Some definitions about built-in integer types. - */ +/// \file mln/value/builtin/integers.hh +/// +/// Some definitions about built-in integer types. -# include <limits> +# include <mln/value/internal/limits.hh> # include <mln/value/concept/built_in.hh> # include <mln/value/concept/integer.hh> @@ -81,8 +81,8 @@ namespace mln typedef trait::value::kind::data kind; typedef mln_value_quant_from_(card) quant; - static const E min() { return std::numeric_limits<E>::min(); } - static const E max() { return std::numeric_limits<E>::max(); } + static const E min() { return mln::value::internal::limits<E>::min(); } + static const E max() { return mln::value::internal::limits<E>::max(); } typedef float sum; }; diff --git a/milena/mln/value/float01.hh b/milena/mln/value/float01.hh index f5348b0..577aa10 100644 --- a/milena/mln/value/float01.hh +++ b/milena/mln/value/float01.hh @@ -254,7 +254,7 @@ namespace mln inline bool operator==(const float01& lhs, const float01& rhs) { - mln_precondition(lhs.nbits() != 0 and rhs.nbits() != 0); + mln_precondition(lhs.nbits() != 0 && rhs.nbits() != 0); if (rhs.nbits() == lhs.nbits()) return lhs.value_ind() == rhs.value_ind(); @@ -270,7 +270,7 @@ namespace mln inline bool operator<(const float01& lhs, const float01& rhs) { - mln_precondition(lhs.nbits() != 0 and rhs.nbits() != 0); + mln_precondition(lhs.nbits() != 0 && rhs.nbits() != 0); if (rhs.nbits() == lhs.nbits()) return lhs.value() < rhs.value(); if (lhs.nbits() > rhs.nbits()) diff --git a/milena/mln/value/internal/limits.hh b/milena/mln/value/internal/limits.hh new file mode 100644 index 0000000..61f6f75 --- /dev/null +++ b/milena/mln/value/internal/limits.hh @@ -0,0 +1,220 @@ +// Copyright (C) 2008 EPITA Research and Development Laboratory +// (LRDE) +// +// 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_VALUE_INTERNAL_LIMITS_HH +# define MLN_VALUE_INTERNAL_LIMITS_HH + +/// \file mln/value/internal/limits.hh +/// +/// Define built-in type limits. + +# if defined(__GNUC__) && __GNUC__ < 3 +# include <cfloat> +# include <climits> +# else +# include <limits> +# endif + +namespace mln +{ + + namespace value + { + + namespace internal + { + + template<typename T> + struct limits +# if !defined(__GNUC__) || __GNUC__ >= 3 + : std::numeric_limits<T> + { }; +# else + { + static const bool is_specialized = false; + }; + + template<> + struct limits<bool> + { + static bool min() throw() { return false; } + static bool max() throw() { return false; } + static bool epsilon() throw() + { return false; } + }; + + template<> + struct limits<char> + { + static char min() throw() { return CHAR_MIN; } + static char max() throw() { return CHAR_MAX; } + static char epsilon() throw() + { return 0; } + }; + + template<> + struct limits<signed char> + { + static signed char min() throw() { return SCHAR_MIN; } + static signed char max() throw() { return SCHAR_MAX; } + static signed char epsilon() throw() + { return 0; } + }; + + template<> + struct limits<unsigned char> + { + static unsigned char min() throw() { return 0; } + static unsigned char max() throw() { return UCHAR_MAX; } + static unsigned char epsilon() throw() + { return 0; } + }; + + template<> + struct limits<short> + { + static short min() throw() { return SHRT_MIN; } + static short max() throw() { return SHRT_MAX; } + static short epsilon() throw() + { return 0; } + }; + + template<> + struct limits<unsigned short> + { + static unsigned short min() throw() { return 0; } + static unsigned short max() throw() { return USHRT_MAX; } + static unsigned short epsilon() throw() + { return 0; } + }; + + template<> + struct limits<int> + { + static int min() throw() { return INT_MIN; } + static int max() throw() { return INT_MAX; } + static int epsilon() throw() + { return 0; } + }; + + template<> + struct limits<unsigned int> + { + static unsigned int min() throw() { return 0; } + static unsigned int max() throw() { return UINT_MAX; } + static unsigned int epsilon() throw() + { return 0; } + }; + + template<> + struct limits<long> + { + static long min() throw() { return LONG_MIN; } + static long max() throw() { return LONG_MAX; } + static long epsilon() throw() + { return 0; } + }; + + template<> + struct limits<unsigned long> + { + static unsigned long min() throw() { return 0; } + static unsigned long max() throw() { return ULONG_MAX; } + static unsigned long epsilon() throw() + { return 0; } + }; + + +/* +** Some pre-ANSI-C99 systems like Linux/GCC 2.95 define +** ULONGLONG_MAX, LONGLONG_MIN, LONGLONG_MAX; we use them if they're defined. +*/ + +# if defined(HAVE_LONG_LONG) && !defined(LONGLONG_MIN) +# define LONGLONG_MIN((long long) 0x8000000000000000LL) +# define LONGLONG_MAX((long long) 0x7FFFFFFFFFFFFFFFLL) +# endif + + +# if defined(HAVE_LONG_LONG) && !defined(ULONGLONG_MAX) + /* First check for ANSI C99 definition: */ +# ifdef ULLONG_MAX +# define ULONGLONG_MAX ULLONG_MAX +# else +# define ULONGLONG_MAX ((unsigned long long)(~0ULL)) +# endif + +# endif /* defined (HAVE_LONG_LONG) && !defined(ULONGLONG_MAX)*/ + + +# if defined(HAVE_LONG_LONG) + template<> + struct limits<long long> + { + static long long min() throw() { return LONGLONG_MIN; } + static long long max() throw() { return LONGLONG_MAX; } + static long long epsilon() throw() + { return 0; } + }; + + template<> + struct limits<unsigned long long> + { + static unsigned long long min() throw() { return 0; } + static unsigned long long max() throw() { return ULONGLONG_MAX; } + static unsigned long long epsilon() throw() + { return 0; } + }; +# endif + + template<> + struct limits<float> + { + static float min() throw() { return FLT_MIN; } + static float max() throw() { return FLT_MAX; } + static float epsilon() throw() + { return FLT_EPSILON; } + }; + + template<> + struct limits<double> + { + static float min() throw() { return DBL_MIN; } + static float max() throw() { return DBL_MAX; } + static float epsilon() throw() + { return DBL_EPSILON; } + }; + +# endif + } // end of namespace mln::value::internal + + } // end of namespace mln::value + +} // end of namespace mln + +#endif // ! MLN_VALUE_INTERNAL_LIMITS_HH diff --git a/milena/tests/unit_test/Makefile.am b/milena/tests/unit_test/Makefile.am index a3c3035..2f3426e 100644 --- a/milena/tests/unit_test/Makefile.am +++ b/milena/tests/unit_test/Makefile.am @@ -187,6 +187,7 @@ mln_fun_vv2v_min \ mln_fun_vv2v_essential \ mln_fun_internal_array_base \ mln_fun_internal_x2x_linear_impl \ +mln_fun_internal_ch_function_value_impl \ mln_fun_internal_selector \ mln_fun_v2w_w2v_norm \ mln_fun_p2v_ternary \ @@ -209,6 +210,7 @@ mln_fun_v2v_dec \ mln_fun_v2v_abs \ mln_fun_v2v_rgb_to_hsl \ mln_fun_v2v_cast \ +mln_fun_v2v_ch_function_value \ mln_fun_v2v_rgb_to_hsi \ mln_fun_v2v_enc \ mln_fun_v2v_convert \ @@ -283,6 +285,7 @@ mln_value_internal_gray_f \ mln_value_internal_all \ mln_value_internal_value_like \ mln_value_internal_iterable_set \ +mln_value_internal_limits \ mln_value_internal_encoding \ mln_value_internal_convert \ mln_value_internal_gray_ \ @@ -434,6 +437,7 @@ mln_trait_value_essential \ mln_trait_images \ mln_trait_window_props \ mln_trait_window_print \ +mln_trait_ch_function_value \ mln_trait_ch_value \ mln_trait_solve \ mln_trait_solve_unary \ @@ -1190,6 +1194,7 @@ mln_fun_vv2v_min_SOURCES = mln_fun_vv2v_min.cc mln_fun_vv2v_essential_SOURCES = mln_fun_vv2v_essential.cc mln_fun_internal_array_base_SOURCES = mln_fun_internal_array_base.cc mln_fun_internal_x2x_linear_impl_SOURCES = mln_fun_internal_x2x_linear_impl.cc +mln_fun_internal_ch_function_value_impl_SOURCES = mln_fun_internal_ch_function_value_impl.cc mln_fun_internal_selector_SOURCES = mln_fun_internal_selector.cc mln_fun_v2w_w2v_norm_SOURCES = mln_fun_v2w_w2v_norm.cc mln_fun_p2v_ternary_SOURCES = mln_fun_p2v_ternary.cc @@ -1212,6 +1217,7 @@ mln_fun_v2v_dec_SOURCES = mln_fun_v2v_dec.cc mln_fun_v2v_abs_SOURCES = mln_fun_v2v_abs.cc mln_fun_v2v_rgb_to_hsl_SOURCES = mln_fun_v2v_rgb_to_hsl.cc mln_fun_v2v_cast_SOURCES = mln_fun_v2v_cast.cc +mln_fun_v2v_ch_function_value_SOURCES = mln_fun_v2v_ch_function_value.cc mln_fun_v2v_rgb_to_hsi_SOURCES = mln_fun_v2v_rgb_to_hsi.cc mln_fun_v2v_enc_SOURCES = mln_fun_v2v_enc.cc mln_fun_v2v_convert_SOURCES = mln_fun_v2v_convert.cc @@ -1286,6 +1292,7 @@ mln_value_internal_gray_f_SOURCES = mln_value_internal_gray_f.cc mln_value_internal_all_SOURCES = mln_value_internal_all.cc mln_value_internal_value_like_SOURCES = mln_value_internal_value_like.cc mln_value_internal_iterable_set_SOURCES = mln_value_internal_iterable_set.cc +mln_value_internal_limits_SOURCES = mln_value_internal_limits.cc mln_value_internal_encoding_SOURCES = mln_value_internal_encoding.cc mln_value_internal_convert_SOURCES = mln_value_internal_convert.cc mln_value_internal_gray__SOURCES = mln_value_internal_gray_.cc @@ -1437,6 +1444,7 @@ mln_trait_value_essential_SOURCES = mln_trait_value_essential.cc mln_trait_images_SOURCES = mln_trait_images.cc mln_trait_window_props_SOURCES = mln_trait_window_props.cc mln_trait_window_print_SOURCES = mln_trait_window_print.cc +mln_trait_ch_function_value_SOURCES = mln_trait_ch_function_value.cc mln_trait_ch_value_SOURCES = mln_trait_ch_value.cc mln_trait_solve_SOURCES = mln_trait_solve.cc mln_trait_solve_unary_SOURCES = mln_trait_solve_unary.cc diff --git a/milena/tests/unit_test/mln_value_internal_limits.cc b/milena/tests/unit_test/mln_value_internal_limits.cc new file mode 100644 index 0000000..5dd172a --- /dev/null +++ b/milena/tests/unit_test/mln_value_internal_limits.cc @@ -0,0 +1,11 @@ +// Unit test for mln/value/internal/limits.hh. +// Generated by ./build_unit_test.sh, do not modify. + +// Include the file twice, so we detect missing inclusion guards. +#include <mln/value/internal/limits.hh> +#include <mln/value/internal/limits.hh> + +int main() +{ + // Nothing. +} -- 1.5.6.5