
* mln/fun/v2b/compare.hh, * mln/fun/v2b/threshold_gt.hh, * mln/fun/v2b/threshold_lt.hh: New. --- milena/ChangeLog | 8 ++++ milena/mln/fun/v2b/{lnot.hh => compare.hh} | 35 +++++++++++++------- .../fun/v2b/{threshold_ge.hh => threshold_gt.hh} | 18 +++++----- .../fun/v2b/{threshold_ge.hh => threshold_lt.hh} | 21 ++++++------ 4 files changed, 50 insertions(+), 32 deletions(-) copy milena/mln/fun/v2b/{lnot.hh => compare.hh} (73%) copy milena/mln/fun/v2b/{threshold_ge.hh => threshold_gt.hh} (84%) copy milena/mln/fun/v2b/{threshold_ge.hh => threshold_lt.hh} (81%) diff --git a/milena/ChangeLog b/milena/ChangeLog index 6433185..7052b67 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,13 @@ 2012-10-19 Guillaume Lazzara <z@lrde.epita.fr> + New comparison functions. + + * mln/fun/v2b/compare.hh, + * mln/fun/v2b/threshold_gt.hh, + * mln/fun/v2b/threshold_lt.hh: New. + +2012-10-19 Guillaume Lazzara <z@lrde.epita.fr> + Force abort() on unsafe conversions. * mln/value/interval.hh, diff --git a/milena/mln/fun/v2b/lnot.hh b/milena/mln/fun/v2b/compare.hh similarity index 73% copy from milena/mln/fun/v2b/lnot.hh copy to milena/mln/fun/v2b/compare.hh index 73d9ecf..22f5d88 100644 --- a/milena/mln/fun/v2b/lnot.hh +++ b/milena/mln/fun/v2b/compare.hh @@ -1,4 +1,4 @@ -// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE) +// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE) // // This file is part of Olena. // @@ -23,12 +23,12 @@ // exception does not however invalidate any other reasons why the // executable file might be covered by the GNU General Public License. -#ifndef MLN_FUN_V2B_LNOT_HH -# define MLN_FUN_V2B_LNOT_HH +#ifndef MLN_FUN_V2B_COMPARE_HH +# define MLN_FUN_V2B_COMPARE_HH /// \file /// -/// Functor that computes "logical not" on a value. +/// FIXME. # include <mln/core/concept/function.hh> @@ -42,12 +42,16 @@ namespace mln namespace v2b { - /// Functor computing logical-not on a value. + /// Comparison function. + /// f(v) = (v == ref). template <typename V> - struct lnot : public Function_v2b< lnot<V> > + struct compare : public Function_v2b< compare<V> > { - typedef V result; - V operator()(const V& v) const; + typedef bool result; + bool operator()(const V& v) const; + + compare(const V& a); + V a; }; @@ -55,10 +59,17 @@ namespace mln template <typename V> inline - V - lnot<V>::operator()(const V& v) const + compare<V>::compare(const V& a) + : a(a) + { + } + + template <typename V> + inline + bool + compare<V>::operator()(const V& v) const { - return ! v; + return v == a; } # endif // ! MLN_INCLUDE_ONLY @@ -70,4 +81,4 @@ namespace mln } // end of namespace mln -#endif // ! MLN_FUN_V2B_LNOT_HH +#endif // ! MLN_FUN_V2B_COMPARE_HH diff --git a/milena/mln/fun/v2b/threshold_ge.hh b/milena/mln/fun/v2b/threshold_gt.hh similarity index 84% copy from milena/mln/fun/v2b/threshold_ge.hh copy to milena/mln/fun/v2b/threshold_gt.hh index c5fef9e..05edd97 100644 --- a/milena/mln/fun/v2b/threshold_ge.hh +++ b/milena/mln/fun/v2b/threshold_gt.hh @@ -24,8 +24,8 @@ // exception does not however invalidate any other reasons why the // executable file might be covered by the GNU General Public License. -#ifndef MLN_FUN_V2B_THRESHOLD_GE_HH -# define MLN_FUN_V2B_THRESHOLD_GE_HH +#ifndef MLN_FUN_V2B_THRESHOLD_GT_HH +# define MLN_FUN_V2B_THRESHOLD_GT_HH /// \file /// @@ -44,14 +44,14 @@ namespace mln { /// Threshold function. - /// f(v) = (v >= threshold). + /// f(v) = (v > threshold). template <typename V> - struct threshold_ge : public Function_v2b< threshold_ge<V> > + struct threshold_gt : public Function_v2b< threshold_gt<V> > { typedef bool result; bool operator()(const V& v) const; - threshold_ge(const V& a); + threshold_gt(const V& a); V a; }; @@ -60,7 +60,7 @@ namespace mln template <typename V> inline - threshold_ge<V>::threshold_ge(const V& a) + threshold_gt<V>::threshold_gt(const V& a) : a(a) { } @@ -68,12 +68,12 @@ namespace mln template <typename V> inline bool - threshold_ge<V>::operator()(const V& v) const + threshold_gt<V>::operator()(const V& v) const { // Here the test seems to be inversed compared to the usual // use. Indeed, we want to preserve the following convention: // True for foreground and False for background. - return v >= a; + return v > a; } # endif // ! MLN_INCLUDE_ONLY @@ -85,4 +85,4 @@ namespace mln } // end of namespace mln -#endif // ! MLN_FUN_V2B_THRESHOLD_GE_HH +#endif // ! MLN_FUN_V2B_THRESHOLD_GT_HH diff --git a/milena/mln/fun/v2b/threshold_ge.hh b/milena/mln/fun/v2b/threshold_lt.hh similarity index 81% copy from milena/mln/fun/v2b/threshold_ge.hh copy to milena/mln/fun/v2b/threshold_lt.hh index c5fef9e..dd82305 100644 --- a/milena/mln/fun/v2b/threshold_ge.hh +++ b/milena/mln/fun/v2b/threshold_lt.hh @@ -1,5 +1,4 @@ -// Copyright (C) 2008, 2009, 2011 EPITA Research and Development -// Laboratory (LRDE) +// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE) // // This file is part of Olena. // @@ -24,8 +23,8 @@ // exception does not however invalidate any other reasons why the // executable file might be covered by the GNU General Public License. -#ifndef MLN_FUN_V2B_THRESHOLD_GE_HH -# define MLN_FUN_V2B_THRESHOLD_GE_HH +#ifndef MLN_FUN_V2B_THRESHOLD_LT_HH +# define MLN_FUN_V2B_THRESHOLD_LT_HH /// \file /// @@ -44,14 +43,14 @@ namespace mln { /// Threshold function. - /// f(v) = (v >= threshold). + /// f(v) = (v < threshold). template <typename V> - struct threshold_ge : public Function_v2b< threshold_ge<V> > + struct threshold_lt : public Function_v2b< threshold_lt<V> > { typedef bool result; bool operator()(const V& v) const; - threshold_ge(const V& a); + threshold_lt(const V& a); V a; }; @@ -60,7 +59,7 @@ namespace mln template <typename V> inline - threshold_ge<V>::threshold_ge(const V& a) + threshold_lt<V>::threshold_lt(const V& a) : a(a) { } @@ -68,12 +67,12 @@ namespace mln template <typename V> inline bool - threshold_ge<V>::operator()(const V& v) const + threshold_lt<V>::operator()(const V& v) const { // Here the test seems to be inversed compared to the usual // use. Indeed, we want to preserve the following convention: // True for foreground and False for background. - return v >= a; + return v < a; } # endif // ! MLN_INCLUDE_ONLY @@ -85,4 +84,4 @@ namespace mln } // end of namespace mln -#endif // ! MLN_FUN_V2B_THRESHOLD_GE_HH +#endif // ! MLN_FUN_V2B_THRESHOLD_LT_HH -- 1.7.2.5