
https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Revamp the default ordering mechanism. Revamp the default ordering mechanism (was util::less). It now relies on the trait solving material so we can now factor definitions. * mln/trait/op/ord.hh: New. * mln/trait/op/all.hh: Update. * mln/util/ord.hh: New. * mln/util/set.hh, * mln/core/p_key.hh (util::less): Replace by... (util::ord): ...this. * mln/core/point.hh, * mln/core/dpoint.hh (less_than): Remove. * mln/algebra/vec.hh, * mln/core/box.hh, * mln/core/concept/gpoint.hh, * mln/core/concept/gdpoint.hh, * mln/core/line2d.hh, * mln/core/p_run.hh, * mln/core/p_runs.hh, (set_precise_unary_): New specializations. (util::less): Remove. * mln/core/concept/site_set.hh (set_precise_unary_): New specialization without implementation. * mln/util/less.hh: Remove. * mln/util/less_than.hh: Remove. Disambiguate between aliases (such as point2d) and taking a variable (with the now obsolete mln_alias macro). * mln/core/alias.hh: Rename as... * mln/core/var.hh: ...this. (mln_alias): Rename as... (mln_VAR): ...this. * sandbox/geraud/cs2d/kruskal.cc: Update. * sandbox/geraud/cs2d/tuto_bis.cc: Update. Misc. * doc/tutorial/examples/line2d.cc: Rename as... * doc/tutorial/examples/p_line2d.cc: ...this. * mln/trait/all.hh: Fix (c). * mln/util/index.hh (dindex_): Move to... * mln/util/dindex.hh: ...this new file. * mln/util/index.hh, * mln/util/dindex.hh (operator<): New. doc/tutorial/examples/p_line2d.cc | 1 mln/algebra/vec.hh | 41 +-------- mln/core/box.hh | 27 +++++- mln/core/concept/gdpoint.hh | 6 + mln/core/concept/gpoint.hh | 8 + mln/core/concept/site_set.hh | 21 +++++ mln/core/dpoint.hh | 45 ---------- mln/core/line2d.hh | 22 +++++ mln/core/p_key.hh | 6 - mln/core/p_run.hh | 54 ++++--------- mln/core/p_runs.hh | 40 ++------- mln/core/point.hh | 52 ------------ mln/core/var.hh | 13 +-- mln/trait/all.hh | 2 mln/trait/op/all.hh | 5 - mln/trait/op/ord.hh | 157 ++++++++++++++++++++++++++++++++++++++ mln/util/dindex.hh | 66 +++------------ mln/util/index.hh | 33 +++---- mln/util/ord.hh | 127 ++++++++++++++++++++++++++++++ mln/util/set.hh | 18 ++-- sandbox/geraud/cs2d/kruskal.cc | 14 +-- sandbox/geraud/cs2d/tuto_bis.cc | 10 +- 22 files changed, 467 insertions(+), 301 deletions(-) Index: doc/tutorial/examples/p_line2d.cc --- doc/tutorial/examples/p_line2d.cc (revision 2155) +++ doc/tutorial/examples/p_line2d.cc (working copy) @@ -4,7 +4,6 @@ # include <mln/core/line2d.hh> # include <mln/core/p_set.hh> -# include <mln/core/alias.hh> # include <mln/core/sub_image.hh> # include <mln/level/fill.hh> # include <mln/debug/println.hh> Index: mln/trait/all.hh --- mln/trait/all.hh (revision 2155) +++ mln/trait/all.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2006 EPITA Research and Development Laboratory +// Copyright (C) 2006, 2008 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 Index: mln/trait/op/ord.hh --- mln/trait/op/ord.hh (revision 0) +++ mln/trait/op/ord.hh (revision 0) @@ -0,0 +1,157 @@ +// Copyright (C) 2008 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_TRAIT_OP_ORD_HH +# define MLN_TRAIT_OP_ORD_HH + +/*! \file mln/trait/op/ord.hh + * + * \brief Declaration of an ordering operator trait. + */ + +# include <mln/trait/op/decl.hh> + + + +namespace mln +{ + + // Forward declarations. + namespace internal { + template <typename T> struct ord_less; + template <typename T> struct ord_vec; + } + namespace util { + template <typename T> bool ord_strict(const T& lhs, const T& rhs); + } + + + namespace trait + { + + namespace op + { + + template <typename T> + struct ord : public solve_unary<ord, T> + { + }; + + } // end of namespace mln::trait::op + + + + template <template <class> class Category, typename T> + struct set_unary_< op::ord, Category, T > + { + typedef mln::internal::ord_less<T> ret; + }; + + + } // end of namespace mln::trait + + + namespace internal + { + + template <typename T> + struct ord_less + { + bool strict(const T& lhs, const T& rhs) const; + bool weak(const T& lhs, const T& rhs) const; + }; + + template <typename T> + struct ord_vec + { + bool strict(const T& lhs, const T& rhs) const; + bool weak(const T& lhs, const T& rhs) const; + }; + + +# ifndef MLN_INCLUDE_ONLY + + // ord_less + + template <typename T> + inline + bool + ord_less<T>::strict(const T& lhs, const T& rhs) const + { + return lhs < rhs; + } + + template <typename T> + inline + bool + ord_less<T>::weak(const T& lhs, const T& rhs) const + { + return lhs <= rhs; + } + + // ord_vec + + template <typename T> + inline + bool + ord_vec<T>::strict(const T& lhs, const T& rhs) const + { + for (unsigned i = 0; i < T::dim; ++i) + { + if (lhs[i] == rhs[i]) + continue; + return mln::util::ord_strict(lhs[i], rhs[i]); + } + return false; + } + + template <typename T> + inline + bool + ord_vec<T>::weak(const T& lhs, const T& rhs) const + { + for (unsigned i = 0; i < T::dim; ++i) + { + if (lhs[i] == rhs[i]) + continue; + return mln::util::ord_strict(lhs[i], rhs[i]); + } + return true; + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::trait::internal + +} // end of namespace mln + + +# include <mln/util/ord.hh> +# include <mln/trait/solve.hh> + + +#endif // ! MLN_TRAIT_OP_ORD_HH Index: mln/trait/op/all.hh --- mln/trait/op/all.hh (revision 2155) +++ mln/trait/op/all.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2006 EPITA Research and Development Laboratory +// Copyright (C) 2006, 2008 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 @@ -76,5 +76,8 @@ # include <mln/trait/op/not.hh> +// Ordering. +# include <mln/trait/op/ord.hh> + #endif // ! MLN_TRAIT_OP_ALL_HH Index: mln/core/point.hh --- mln/core/point.hh (revision 2155) +++ mln/core/point.hh (working copy) @@ -31,8 +31,6 @@ /*! \file mln/core/point.hh * * \brief Definition of the generic point class mln::point_. - * - * \todo Try to generalize less_than with Gl and Gr. */ # include <mln/core/def/coord.hh> @@ -197,38 +195,6 @@ const util::yes& cut_(const point<grid::tick,C>& p); - namespace util - { - - /*! \brief Ordering "less than" comparison between a couple of - * points. - * - * The ordering is based on a lexicographical ordering over - * coordinates. - * - * Both points have to be defined on the same topology. - * - * \warning In the general case this ordering relationship is \em - * not bound to the way of browsing a domain with a forward point - * iterator. - */ - template <typename G, typename Cl, typename Cr> - struct less_than< point<G,Cl>, - point<G,Cr> > - { - /*! \brief Comparison between a couple of points \a lhs and \a - * rhs. - * - * \return True if \p lhs is before \p rhs in the sense of the - * coordinates lexicographic comparison, otherwise false. - */ - bool operator()(const point<G,Cl>& lhs, - const point<G,Cr>& rhs) const; - }; - - } // end of namespace mln::util - - # ifndef MLN_INCLUDE_ONLY template <typename G, typename C> @@ -473,24 +439,6 @@ return *the_; } - - namespace util - { - - template <typename G, typename Cl, typename Cr> - bool - less_than< point<G,Cl>, - point<G,Cr> >::operator()(const point<G,Cl>& lhs, - const point<G,Cr>& rhs) const - { - enum { n = G::dim }; - typedef less_than< algebra::vec<n,Cl>, algebra::vec<n,Cr> > less_t; - static const less_t op = less_t(); - return op(lhs.to_vec(), rhs.to_vec()); - } - - } // end of namespace mln::util - # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln Index: mln/core/dpoint.hh --- mln/core/dpoint.hh (revision 2155) +++ mln/core/dpoint.hh (working copy) @@ -135,34 +135,6 @@ }; - namespace util - { - - /*! \brief Ordering "less than" comparison between a couple of - * delta-points. - * - * The ordering is based on a lexicographical ordering over - * coordinates. - * - * Both delta-points have to be defined on the same topology. - */ - template <typename G, typename Cl, typename Cr> - struct less_than< dpoint<G,Cl>, - dpoint<G,Cr> > - { - /*! \brief Comparison between a couple of delta-points \a lhs - * and \a rhs. - * - * \return True if \p lhs is before \p rhs in the sense of the - * coordinates lexicographic comparison, otherwise false. - */ - bool operator()(const dpoint<G,Cl>& lhs, - const dpoint<G,Cr>& rhs) const; - }; - - } // end of namespace mln::util - - # ifndef MLN_INCLUDE_ONLY template <typename G, typename C> @@ -291,23 +263,6 @@ return coord_; } - namespace util - { - - template <typename G, typename Cl, typename Cr> - bool - less_than< dpoint<G,Cl>, - dpoint<G,Cr> >::operator()(const dpoint<G,Cl>& lhs, - const dpoint<G,Cr>& rhs) const - { - enum { n = G::dim }; - typedef less_than< algebra::vec<n,Cl>, algebra::vec<n,Cr> > less_t; - static const less_t op = less_t(); - return op(lhs.to_vec(), rhs.to_vec()); - } - - } // end of namespace mln::util - # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln Index: mln/core/box.hh --- mln/core/box.hh (revision 2155) +++ mln/core/box.hh (working copy) @@ -39,7 +39,6 @@ # include <mln/core/internal/box_impl.hh> # include <mln/core/point.hh> # include <mln/literal/origin.hh> -# include <mln/util/less.hh> namespace mln @@ -63,7 +62,14 @@ typedef trait::site_set::arity::unique arity; }; - } // end of namespace trait + template <typename P> + struct set_precise_unary_< op::ord, box<P> > + { + typedef set_precise_unary_< op::ord, box<P> > ret; // Itself. + bool strict(const box<P>& lhs, const box<P>& rhs) const; + }; + + } // end of namespace mln::trait /*! \brief Generic box class: site set containing points of a @@ -169,7 +175,7 @@ { // Validity is: for all i, pmin_[i] <= pmax_[i]. // Nota bene: a one-point box is valid. - return util::op_less_or_equal(pmin_, pmax_); + return util::ord_weak(pmin_, pmax_); } template <typename P> @@ -313,6 +319,21 @@ return ostr << "[" << b.pmin() << ".." << b.pmax() << ']'; } + namespace trait + { + + template <typename P> + inline + bool + set_precise_unary_< op::ord, box<P> >::strict(const box<P>& lhs, const box<P>& rhs) const + { + // Lexicographical over "pmin then pmax". + return util::ord_lexi_strict(lhs.pmin(), lhs.pmax(), + rhs.pmin(), rhs.pmax()); + } + + } // end of namespace mln::trait + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln Index: mln/core/p_key.hh --- mln/core/p_key.hh (revision 2155) +++ mln/core/p_key.hh (working copy) @@ -40,7 +40,7 @@ # include <mln/core/p_set.hh> # include <mln/core/p_double.hh> # include <mln/core/internal/site_set_base.hh> -# include <mln/util/less.hh> +# include <mln/util/ord.hh> namespace mln @@ -184,11 +184,11 @@ util::set<K> b_; // Function: key k -> set of sites {p}. - typedef std::map<K, p_set<P>, util::less<K> > s_t; + typedef std::map<K, p_set<P>, util::ord<K> > s_t; s_t s_; // Function: site p -> key k. - typedef std::map<P, K, util::less<P> > k_t; + typedef std::map<P, K, util::ord<P> > k_t; k_t k_; // Number of sites. Index: mln/core/line2d.hh --- mln/core/line2d.hh (revision 2155) +++ mln/core/line2d.hh (working copy) @@ -59,6 +59,13 @@ typedef trait::site_set::arity::unique arity; }; + template <> + struct set_precise_unary_< op::ord, p_line2d > + { + typedef set_precise_unary_< op::ord, p_line2d > ret; // Itself. + bool strict(const p_line2d& lhs, const p_line2d& rhs) const; + }; + } // end of namespace trait @@ -297,6 +304,21 @@ return arr_.memory_size() + sizeof(box2d); } + + namespace trait + { + + inline + bool + set_precise_unary_< op::ord, p_line2d >::strict(const p_line2d& lhs, + const p_line2d& rhs) const + { + return util::ord_lexi_strict(lhs.begin(), lhs.end(), + rhs.begin(), rhs.end()); + } + + } // end of namespace mln::trait + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln Index: mln/core/var.hh --- mln/core/var.hh (revision 2155) +++ mln/core/var.hh (working copy) @@ -25,19 +25,20 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef MLN_CORE_ALIAS_HH -# define MLN_CORE_ALIAS_HH +#ifndef MLN_CORE_VAR_HH +# define MLN_CORE_VAR_HH -/*! \file mln/core/alias.hh +/*! \file mln/core/var.hh * - * \brief Definition of FIXME + * \brief Definition of the macro mln_VAR. Warning: that macro relies + * on an extention of g++ (typeof) so it is NOT standard C++. */ -#define mln_alias(Var, Expr) \ +#define mln_VAR(Var, Expr) \ \ typeof(Expr) Var = Expr; \ typedef typeof(Expr) Var##_t -#endif // ! MLN_CORE_ALIAS_HH +#endif // ! MLN_CORE_VAR_HH Index: mln/core/p_run.hh --- mln/core/p_run.hh (revision 2155) +++ mln/core/p_run.hh (working copy) @@ -32,15 +32,12 @@ * * \brief Definition of a run of points. * - * \todo Get rid of the index attribute in psite. - * * \todo Use a lazy approach (in subj) like in p_array psite. */ # include <mln/core/internal/site_set_base.hh> # include <mln/core/internal/pseudo_site_base.hh> # include <mln/util/index.hh> -# include <mln/util/less.hh> namespace mln @@ -67,6 +64,13 @@ typedef trait::site_set::arity::unique arity; }; + template <typename P> + struct set_precise_unary_< op::ord, p_run<P> > + { + typedef set_precise_unary_< op::ord, p_run<P> > ret; // Itself. + bool strict(const p_run<P>& lhs, const p_run<P>& rhs) const; + }; + } // end of namespace trait @@ -165,19 +169,6 @@ std::ostream& operator<<(std::ostream& ostr, const p_run<P>& r); - namespace util - { - - template <typename P> - struct less< p_run<P> > - { - bool operator()(const p_run<P>& lhs, - const p_run<P>& rhs) const; - }; - - } // end of namespace mln::util - - // p_run_psite<P> @@ -378,24 +369,6 @@ - // Ordering. - - namespace util - { - - template <typename P> - inline - bool - less< p_run<P> >::operator()(const p_run<P>& lhs, - const p_run<P>& rhs) const - { - return op_less(lhs.start(), rhs.start()); - } - - } // end of namespace mln::util - - - // p_run_psite<P> template <typename P> @@ -501,6 +474,19 @@ return *run_; } + namespace trait + { + + template <typename P> + inline + bool + set_precise_unary_< op::ord, p_run<P> >::strict(const p_run<P>& lhs, const p_run<P>& rhs) const + { + return util::ord_strict(lhs.start(), rhs.start()); + } + + } // end of namespace trait + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln Index: mln/core/concept/gpoint.hh --- mln/core/concept/gpoint.hh (revision 2155) +++ mln/core/concept/gpoint.hh (working copy) @@ -36,6 +36,7 @@ # include <mln/core/concept/site.hh> # include <mln/core/concept/gdpoint.hh> # include <mln/value/concept/scalar.hh> +# include <mln/util/ord.hh> namespace mln @@ -70,6 +71,13 @@ typedef mln_delta(L) ret; }; + + template <typename P> + struct set_unary_< op::ord, mln::Gpoint, P > + { + typedef mln::internal::ord_vec< P > ret; + }; + } // end of namespace mln::trait Index: mln/core/concept/gdpoint.hh --- mln/core/concept/gdpoint.hh (revision 2155) +++ mln/core/concept/gdpoint.hh (working copy) @@ -65,6 +65,12 @@ typedef L ret; }; + template <typename D> + struct set_unary_< op::ord, mln::Gdpoint, D > + { + typedef mln::internal::ord_vec< D > ret; + }; + } // end of namespace mln::trait Index: mln/core/concept/site_set.hh --- mln/core/concept/site_set.hh (revision 2155) +++ mln/core/concept/site_set.hh (working copy) @@ -42,10 +42,12 @@ # include <mln/metal/not_equal.hh> # include <mln/metal/is_a.hh> # include <mln/metal/is_unqualif.hh> +# include <mln/util/ord.hh> # include <mln/util/yes.hh> // Temporary include. + namespace mln { @@ -147,6 +149,25 @@ + namespace trait + { + + template <typename S> + struct set_unary_< op::ord, Site_Set, S > + { + // No definition here. + + // That prevents from calling the inclusion operator ("op<") + // which is clearly not the expected ordering... + + // Consequently site sets have to define the way they are + // ordered. + }; + + } // end of namespace mln::trait + + + # ifndef MLN_INCLUDE_ONLY namespace internal Index: mln/core/p_runs.hh --- mln/core/p_runs.hh (revision 2155) +++ mln/core/p_runs.hh (working copy) @@ -65,6 +65,16 @@ typedef trait::site_set::arity::unique arity; }; + template <typename P> + struct set_precise_unary_< op::ord, p_run_set<P> > + { + typedef set_precise_unary_< op::ord, p_run_set<P> > ret; // Itself. + bool strict(const p_run_set<P>& lhs, const p_run_set<P>& rhs) const + { + return util::ord_strict(lhs.run(0), rhs.run(0)); + } + }; + } // end of namespace trait @@ -183,20 +193,6 @@ std::ostream& operator<<(std::ostream& ostr, const p_run_set<P>& r); - namespace util - { - - template <typename P> - struct less< p_run_set<P> > - { - bool operator()(const p_run_set<P>& lhs, - const p_run_set<P>& rhs) const; - }; - - } // end of namespace mln::util - - - # ifndef MLN_INCLUDE_ONLY @@ -404,22 +400,6 @@ return ostr << r.hook_(); } - - namespace util - { - - template <typename P> - inline - bool - less< p_run_set<P> >::operator()(const p_run_set<P>& lhs, - const p_run_set<P>& rhs) const - { - return op_less(lhs.run(0), rhs.run(0)); - } - - } // end of namespace mln::util - - # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln Index: mln/algebra/vec.hh --- mln/algebra/vec.hh (revision 2155) +++ mln/algebra/vec.hh (working copy) @@ -42,7 +42,6 @@ # include <mln/trait/all.hh> # include <mln/trait/value_.hh> # include <mln/fun/i2v/all_to.hh> -# include <mln/util/less_than.hh> # include <mln/debug/format.hh> # include <mln/value/ops.hh> @@ -64,19 +63,6 @@ template <unsigned d, typename C> struct h_vec; - namespace util - { - - template <unsigned n, typename Tl, typename Tr> - struct less_than< algebra::vec<n,Tl>, - algebra::vec<n,Tr> > - { - bool operator()(const algebra::vec<n,Tl>& lhs, - const algebra::vec<n,Tr>& rhs) const; - }; - - } // end of namespace mln::util - namespace trait { @@ -96,6 +82,12 @@ typedef algebra::vec<n, mln_sum(T)> sum; }; + template <unsigned n, typename T> + struct set_precise_unary_< op::ord, mln::algebra::vec<n,T> > + { + typedef mln::internal::ord_vec< mln::algebra::vec<n,T> > ret; + }; + } // end of namespace mln::trait @@ -586,27 +578,6 @@ } // end of namespace mln::algebra - namespace util - { - - template <unsigned n, typename Tl, typename Tr> - bool - less_than< algebra::vec<n,Tl>, - algebra::vec<n,Tr> >::operator()(const algebra::vec<n,Tl>& lhs, - const algebra::vec<n,Tr>& rhs) const - { - for (unsigned i = 0; i < n; ++i) - { - if (lhs[i] == rhs[i]) - continue; - return lhs[i] < rhs[i]; - } - return false; - } - - } // end of namespace mln::util - - # endif // MLN_INCLUDE_ONLY } // end of namespace mln Index: mln/util/ord.hh --- mln/util/ord.hh (revision 0) +++ mln/util/ord.hh (revision 0) @@ -0,0 +1,127 @@ +// Copyright (C) 2008 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_UTIL_ORD_HH +# define MLN_UTIL_ORD_HH + +/*! \file mln/util/ord.hh + * + * \brief Definition of an ordering type and routine. + */ + +# include <mln/core/concept/object.hh> +# include <mln/trait/op/ord.hh> + + + +namespace mln +{ + + namespace util + { + + /// Function-object that defines an ordering between objects with + /// type \p T. + template <typename T> + struct ord + { + bool operator()(const T& lhs, const T& rhs) const; + }; + + + + template <typename T> + bool ord_strict(const T& lhs, const T& rhs); + + template <typename T> + bool ord_weak(const T& lhs, const T& rhs); + + + template <typename T1, typename T2> + bool ord_lexi_strict(const T1& lhs_1, const T2& lhs_2, + const T1& rhs_1, const T2& rhs_2); + + + +# ifndef MLN_INCLUDE_ONLY + + // ord<T> + + template <typename T> + inline + bool + ord<T>::operator()(const T& lhs, const T& rhs) const + { + typedef typename mln::trait::op::ord<T>::ret F; + static const F f_ord = F(); + return f_ord.strict(lhs, rhs); + } + + // ord_strict + + template <typename T> + inline + bool + ord_strict(const T& lhs, const T& rhs) + { + typedef typename mln::trait::op::ord<T>::ret F; + static const F f_ord = F(); + return f_ord.strict(lhs, rhs); + } + + // ord_weak + + template <typename T> + inline + bool ord_weak(const T& lhs, const T& rhs) + { + typedef typename mln::trait::op::ord<T>::ret F; + static const F f_ord = F(); + return f_ord.weak(lhs, rhs); + } + + // ord_lex_strict + + template <typename T1, typename T2> + inline + bool + ord_lexi_strict(const T1& lhs_1, const T2& lhs_2, + const T1& rhs_1, const T2& rhs_2) + { + return + util::ord_strict(lhs_1, rhs_1) || + (lhs_1 == rhs_1 && util::ord_strict(lhs_2, rhs_2)); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::util + +} // end of namespace mln + + +#endif // ! MLN_UTIL_ORD_HH Index: mln/util/set.hh --- mln/util/set.hh (revision 2155) +++ mln/util/set.hh (working copy) @@ -44,7 +44,7 @@ # include <iostream> # include <mln/core/concept/proxy.hh> -# include <mln/util/less.hh> +# include <mln/util/ord.hh> namespace mln @@ -74,10 +74,10 @@ * The parameter \c T is the element type, which shall not be * const-qualified. * - * The unicity of set elements is handled by the mln::util::less - * function-object. + * The unicity of set elements is handled by the mln::util::ord + * mechanism. * - * \see mln::util::less + * \see mln::util::ord */ template <typename T> class set : public Object< mln::util::set<T> > @@ -213,7 +213,7 @@ * * This structure is always up-to-date w.r.t. the set contents. */ - mutable std::set< T, mln::util::less<T> > s_; + mutable std::set< T, util::ord<T> > s_; /*! \brief Freeze the contents of the set (update \a v_ from \a @@ -512,7 +512,9 @@ set<T>::v_has_(const T& elt) const { mln_precondition(frozen_); - if (is_empty() || op_less(elt, v_[0]) || op_less(v_[nelements() - 1], elt)) + if (is_empty() || + util::ord_strict(elt, v_[0]) || + util::ord_strict(v_[nelements() - 1], elt)) return false; return v_[dicho_(elt, 0, nelements())] == elt; } @@ -527,7 +529,9 @@ if (end - beg <= 1) return beg; unsigned med = (beg + end) / 2; - return op_less(elt, v_[med]) ? dicho_(elt, beg, med) : dicho_(elt, med, end); + return util::ord_strict(elt, v_[med]) + ? dicho_(elt, beg, med) + : dicho_(elt, med, end); } Index: mln/util/index.hh --- mln/util/index.hh (revision 2155) +++ mln/util/index.hh (working copy) @@ -46,7 +46,7 @@ namespace util { - // Fwd decl. + // Forward declaration. template <typename Tag> struct dindex_; @@ -56,6 +56,8 @@ template <typename Tag = void> struct index_ // : public Object< index_<Tag> > { + typedef Object<void> category; + typedef dindex_<Tag> dpsite; typedef int coord; @@ -92,30 +94,20 @@ return cpy; } - operator int() const { return i_; } - }; - - typedef index_<void> index; - - - template <typename Tag = void> - struct dindex_ // : public Object< dindex_<Tag> > + bool operator<(const index_& rhs) const { - typedef index_<Tag> psite; - typedef index_<Tag> site; - - typedef int coord; - enum { dim = 1 }; - - int i_; + return i_ < rhs.i_; + } - dindex_() {} - dindex_(int i) : i_(i) {} + bool operator<(int i) const + { + return i_ < i; + } operator int() const { return i_; } }; - typedef dindex_<void> dindex; + typedef index_<void> index; @@ -130,4 +122,7 @@ } // end of namespace mln +# include <mln/util/dindex.hh> + + #endif // ! MLN_UTIL_INDEX_HH Index: mln/util/dindex.hh --- mln/util/dindex.hh (revision 2155) +++ mln/util/dindex.hh (working copy) @@ -25,19 +25,19 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef MLN_UTIL_INDEX_HH -# define MLN_UTIL_INDEX_HH +#ifndef MLN_UTIL_DINDEX_HH +# define MLN_UTIL_DINDEX_HH -/*! \file mln/util/index.hh +/*! \file mln/util/dindex.hh * - * \brief Definition of an "index" type. + * \brief Definition of a "delta-index" type. * * \todo Remove coord and dim, then make window<dindex> work. * * \todo Add inheritance to Object so add operators and traits. */ -# include <mln/core/concept/object.hh> +# include <mln/util/index.hh> namespace mln @@ -50,57 +50,14 @@ template <typename Tag> struct dindex_; - /*! \brief Index structure. + /*! \brief Delta-index structure. * */ template <typename Tag = void> - struct index_ // : public Object< index_<Tag> > - { - typedef dindex_<Tag> dpsite; - - typedef int coord; - enum { dim = 1 }; - - int i_; - - index_() {} - index_(int i) : i_(i) {} - - index_<Tag>& operator++() - { - ++i_; // Pre-inc. - return *this; - } - - index_<Tag> operator++(int) - { - index_<Tag> cpy(i_ + 1); - ++i_; // Post-inc. - return cpy; - } - - index_<Tag>& operator--() - { - --i_; // Pre-dec. - return *this; - } - - index_<Tag> operator--(int) - { - index_<Tag> cpy(i_ + 1); - --i_; // Post-dec. - return cpy; - } - - operator int() const { return i_; } - }; - - typedef index_<void> index; - - - template <typename Tag = void> struct dindex_ // : public Object< dindex_<Tag> > { + typedef Object<void> category; + typedef index_<Tag> psite; typedef index_<Tag> site; @@ -112,6 +69,11 @@ dindex_() {} dindex_(int i) : i_(i) {} + bool operator<(const dindex_& rhs) const + { + return i_ < rhs.i_; + } + operator int() const { return i_; } }; @@ -130,4 +92,4 @@ } // end of namespace mln -#endif // ! MLN_UTIL_INDEX_HH +#endif // ! MLN_UTIL_DINDEX_HH Index: sandbox/geraud/cs2d/kruskal.cc --- sandbox/geraud/cs2d/kruskal.cc (revision 2155) +++ sandbox/geraud/cs2d/kruskal.cc (working copy) @@ -174,7 +174,7 @@ } // mln -#define mln_alias(Var, Expr) typeof(Expr) Var = Expr; +#define mln_VAR(Var, Expr) typeof(Expr) Var = Expr; template <typename DS_t, typename U> @@ -259,7 +259,7 @@ image2d<int_u8> ima(input.nrows() * 2 - 1, input.ncols() * 2 - 1, 0); - mln_alias(cell, ima | is_cell); + mln_VAR(cell, ima | is_cell); typedef typeof(cell) cell_t; debug::println(cell); @@ -270,7 +270,7 @@ cell(pc) = input(pi); } - mln_alias(edge, ima | is_edge); + mln_VAR(edge, ima | is_edge); level::paste(morpho::gradient(edge, nbh_e2c), edge); // ^^^^^^^ // edge -> neighboring cells @@ -317,9 +317,9 @@ debug::println(T); - mln_alias(is_T, pw::value(T) == pw::cst(true)); + mln_VAR(is_T, pw::value(T) == pw::cst(true)); - mln_alias(dom, (T | is_T).domain()); + mln_VAR(dom, (T | is_T).domain()); typedef typeof(dom) dom_t; io::ppm::save(show_edge(T, input.nrows(), input.ncols(), 7), @@ -332,7 +332,7 @@ // [*] See EOF. unsigned nbasins; - mln_alias(wst, morpho::meyer_wst(ima | is_tree, nbh_e2e, nbasins) ); + mln_VAR(wst, morpho::meyer_wst(ima | is_tree, nbh_e2e, nbasins) ); std::cout << "nbasins : " << nbasins << std::endl; { @@ -352,6 +352,6 @@ // have ctor without arg so the init cannot be delayed). As a // consequence, we cannot have the following code: // -// mln_alias(tree, edge | is_T); +// mln_VAR(tree, edge | is_T); // typedef typeof(tree) tree_t; // morpho::meyer_wst(tree, nbh_e2e, nbasins); Index: sandbox/geraud/cs2d/tuto_bis.cc --- sandbox/geraud/cs2d/tuto_bis.cc (revision 2155) +++ sandbox/geraud/cs2d/tuto_bis.cc (working copy) @@ -128,7 +128,7 @@ -#define mln_alias(Var, Expr) \ +#define mln_VAR(Var, Expr) \ typeof(Expr) Var = Expr; @@ -177,14 +177,14 @@ image2d<int> ima(3, 5); - mln_alias(cell, ima | is_cell); + mln_VAR(cell, ima | is_cell); level::fill(cell, fun::p2v::iota); debug::println(cell); // 1 2 3 // // 4 5 6 - mln_alias(edge, ima | is_edge); + mln_VAR(edge, ima | is_edge); level::paste(morpho::gradient(edge, nbh_e2c), edge); // ^^^^^^^ // edge -> neighbooring cells @@ -194,7 +194,7 @@ // 1 1 unsigned nbasins; - mln_alias(wst, morpho::meyer_wst(edge, nbh_e2e, nbasins)); + mln_VAR(wst, morpho::meyer_wst(edge, nbh_e2e, nbasins)); // ^^^^^^^ // edge -> neighbooring edges debug::println(wst); @@ -231,7 +231,7 @@ // YET THOSE VALUES ARE ON EDGES, NOT ON CELLS... - mln_alias(label, wst.full()); + mln_VAR(label, wst.full()); debug::println(label); // 0 2 0 2 0 // 0 0 0 0 0