
* mln/accu/math/span.hh: New. --- milena/ChangeLog | 6 ++ milena/mln/accu/math/{inf.hh => span.hh} | 97 +++++++++++++---------------- 2 files changed, 50 insertions(+), 53 deletions(-) copy milena/mln/accu/math/{inf.hh => span.hh} (63%) diff --git a/milena/ChangeLog b/milena/ChangeLog index 5d2bea5..aa215c4 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,11 @@ 2012-10-18 Guillaume Lazzara <z@lrde.epita.fr> + New span accumulator. + + * mln/accu/math/span.hh: New. + +2012-10-18 Guillaume Lazzara <z@lrde.epita.fr> + Add functions. * mln/fun/vv2v/span.hh, diff --git a/milena/mln/accu/math/inf.hh b/milena/mln/accu/math/span.hh similarity index 63% copy from milena/mln/accu/math/inf.hh copy to milena/mln/accu/math/span.hh index 17780b9..eda4e85 100644 --- a/milena/mln/accu/math/inf.hh +++ b/milena/mln/accu/math/span.hh @@ -1,4 +1,4 @@ -// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) +// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE) // // This file is part of Olena. // @@ -23,18 +23,15 @@ // exception does not however invalidate any other reasons why the // executable file might be covered by the GNU General Public License. -#ifndef MLN_ACCU_MATH_INF_HH -# define MLN_ACCU_MATH_INF_HH +#ifndef MLN_ACCU_MATH_SPAN_HH +# define MLN_ACCU_MATH_SPAN_HH /// \file /// -/// Define an accumulator that computes a inf. +/// Define an accumulator that computes a span. # include <mln/accu/internal/base.hh> -# include <mln/core/concept/meta_accumulator.hh> -# include <mln/trait/value_.hh> -# include <mln/util/pix.hh> -# include <mln/fun/math/inf.hh> +# include <mln/value/interval.hh> namespace mln { @@ -46,29 +43,30 @@ namespace mln { - /// \brief Generic inf accumulator class. + /// \brief Generic span accumulator class. /// - /// The parameter \c T is the type of values. + /// The parameter \c T is the type of values used in the + /// underlying interval. /// /// \ingroup modaccuvalues // template <typename T> - struct inf : public mln::accu::internal::base< const T&, inf<T> > + struct span : public mln::accu::internal::base< const value::interval<T>&, span<T> > { - typedef T argument; + typedef value::interval<T> argument; - inf(); + span(); /// Manipulators. /// \{ void init(); void take_as_init_(const argument& t); void take(const argument& t); - void take(const inf<T>& other); + void take(const span<T>& other); /// \} /// Get the value of the accumulator. - const T& to_result() const; + const value::interval<T>& to_result() const; /// Check whether this accu is able to return a result. /// Always true here. @@ -76,36 +74,13 @@ namespace mln protected: - T t_; - typename mln::fun::inf::with<T, T>::ret fun_; + value::interval<T> t_; + bool is_valid_; }; - - template <typename I> struct inf< util::pix<I> >; - } // end of mln::accu::math - namespace meta - { - - namespace math - { - - /// Meta accumulator for inf. - - struct inf : public Meta_Accumulator< inf > - { - template <typename T> - struct with - { - typedef accu::math::inf<T> ret; - }; - }; - - } // end of namespace mln::accu::meta::math - - } // end of namespace mln::accu::meta # ifndef MLN_INCLUDE_ONLY @@ -115,7 +90,7 @@ namespace mln template <typename T> inline - inf<T>::inf() + span<T>::span() { init(); } @@ -123,37 +98,53 @@ namespace mln template <typename T> inline void - inf<T>::init() + span<T>::init() { - t_ = mln_max(T); + is_valid_ = false; } template <typename T> inline - void inf<T>::take_as_init_(const argument& t) + void span<T>::take_as_init_(const argument& t) { t_ = t; + is_valid_ = true; } template <typename T> inline - void inf<T>::take(const argument& t) + void span<T>::take(const argument& t) { - this->t_ = this->fun_(t_, t); + if (is_valid_) + this->t_ = value::span(this->t_, t); + else + { + this->t_ = t; + if (!is_valid_) + is_valid_ = true; + } } template <typename T> inline void - inf<T>::take(const inf<T>& other) + span<T>::take(const span<T>& other) { - this->t_ = this->fun_(t_, other.t_); + mln_precondition(other.is_valid()); + + if (is_valid_) + this->t_ = value::span(this->t_, other.t_); + else + { + this->t_ = other.t_; + is_valid_ = other.is_valid_; + } } template <typename T> inline - const T& - inf<T>::to_result() const + const value::interval<T>& + span<T>::to_result() const { return t_; } @@ -161,9 +152,9 @@ namespace mln template <typename T> inline bool - inf<T>::is_valid() const + span<T>::is_valid() const { - return true; + return is_valid_; } } // end of namespace mln::accu::math @@ -175,4 +166,4 @@ namespace mln } // end of namespace mln -#endif // ! MLN_ACCU_MATH_INF_HH +#endif // ! MLN_ACCU_MATH_SPAN_HH -- 1.7.2.5