2553: Add is_valid() to accus and move meta-accus in meta namespace.

--- milena/ChangeLog | 37 ++++++++++++++++ milena/mln/accu/bbox.hh | 6 +++ milena/mln/accu/count.hh | 32 +++++++++++---- milena/mln/accu/height.hh | 28 ++++++++++--- milena/mln/accu/histo.hh | 34 +++++++++++++++ milena/mln/accu/max.hh | 18 ++++++++- milena/mln/accu/max_h.hh | 16 +++++++ milena/mln/accu/mean.hh | 16 +++++++ milena/mln/accu/median_alt.hh | 67 +++++++++++++++++++----------- milena/mln/accu/median_h.hh | 16 +++++++ milena/mln/accu/min.hh | 18 ++++++++- milena/mln/accu/min_h.hh | 17 ++++++++ milena/mln/accu/nil.hh | 39 +++++++++++++---- milena/mln/accu/p.hh | 18 ++++++++- milena/mln/accu/pair.hh | 18 ++++++++ milena/mln/accu/rank.hh | 36 ++++++++++++---- milena/mln/accu/rank_bool.hh | 16 +++++++ milena/mln/accu/rank_high_quant.hh | 38 ++++++++++++----- milena/mln/accu/sum.hh | 16 +++++++ milena/mln/accu/tuple.hh | 38 +++++++++++++---- milena/mln/accu/v.hh | 47 +++++++++++++++------ milena/mln/accu/volume.hh | 30 +++++++++++--- milena/mln/core/concept/accumulator.hh | 6 ++- milena/mln/morpho/gradient_elementary.hh | 2 +- milena/tests/accu/all_accus.cc | 2 +- milena/tests/accu/max.cc | 15 +----- milena/tests/accu/mean.cc | 4 +- milena/tests/accu/min.cc | 13 +---- milena/tests/accu/min_max.cc | 4 +- milena/tests/accu/nil.cc | 7 ++- 30 files changed, 523 insertions(+), 131 deletions(-) diff --git a/milena/ChangeLog b/milena/ChangeLog index 9ad63cc..5385c0f 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,42 @@ 2008-10-14 Guillaume Lazzara <z@lrde.epita.fr> + Add is_valid() in the accumulator concept and move meta-accumulators + in meta namespace. + * milena/mln/accu/count.hh, + * milena/mln/accu/height.hh, + * milena/mln/accu/histo.hh, + * milena/mln/accu/max.hh, + * milena/mln/accu/max_h.hh, + * milena/mln/accu/mean.hh, + * milena/mln/accu/median_alt.hh, + * milena/mln/accu/min.hh, + * milena/mln/accu/min_h.hh, + * milena/mln/accu/nil.hh, + * milena/mln/accu/p.hh, + * milena/mln/accu/pair.hh, + * milena/mln/accu/rank.hh, + * milena/mln/accu/rank_bool.hh, + * milena/mln/accu/rank_high_quant.hh, + * milena/mln/accu/sum.hh, + * milena/mln/accu/tuple.hh, + * milena/mln/accu/v.hh, + * milena/mln/accu/volume.hh: + Add is_valid() and move meta-accumulators in meta namespace if needed. + + * milena/mln/core/concept/accumulator.hh: + Add is_valid() static test. + + * milena/tests/accu/all_accus.cc, + * milena/tests/accu/max.cc, + * milena/tests/accu/mean.cc, + * milena/tests/accu/min.cc, + * milena/tests/accu/min_max.cc, + * milena/tests/accu/nil.cc: + Fix tests. + + +2008-10-14 Guillaume Lazzara <z@lrde.epita.fr> + Add labeling::compute. * milena/mln/labeling/compute.hh: do it. * milena/tests/labeling/Makefile.am, diff --git a/milena/mln/accu/bbox.hh b/milena/mln/accu/bbox.hh index bf83445..9327b0f 100644 --- a/milena/mln/accu/bbox.hh +++ b/milena/mln/accu/bbox.hh @@ -56,14 +56,20 @@ namespace mln bbox(); + /// Manipulators. + /// \{ void init(); void take_as_init(const P& p); void take(const P& p); void take(const bbox<P>& other); void take(const box<P>& b); + /// \} + /// Get the value of the accumulator. const box<P>& to_result() const; + /// Check whether this accu is able to return a result. + /// Always true here. bool is_valid() const; protected: diff --git a/milena/mln/accu/count.hh b/milena/mln/accu/count.hh index 608836d..c2c1f02 100644 --- a/milena/mln/accu/count.hh +++ b/milena/mln/accu/count.hh @@ -55,28 +55,36 @@ namespace mln void take(const argument&); void take(const count_<T>& other); - /// Force the value of the counter to \a c. + /// Force the value of the counter to \a c. void set_value(std::size_t c); /// \} /// Get the value of the accumulator. std::size_t to_result() const; + /// Check whether this accu is able to return a result. + /// Always true here. + bool is_valid() const; + protected: /// The value of the counter. std::size_t count__; }; - - /// \brief Meta accumulator for count. - struct count : public Meta_Accumulator< count > + namespace meta { - template <typename T> - struct with + + /// \brief Meta accumulator for count. + struct count : public Meta_Accumulator< count > { - typedef count_<T> ret; + template <typename T> + struct with + { + typedef count_<T> ret; + }; }; - }; + + } // end of namespace mln::accu::meta # ifndef MLN_INCLUDE_ONLY @@ -128,6 +136,14 @@ namespace mln count__ = c; } + template <typename T> + inline + bool + count_<T>::is_valid() const + { + return true; + } + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln::accu diff --git a/milena/mln/accu/height.hh b/milena/mln/accu/height.hh index 38ae6be..80dc28d 100644 --- a/milena/mln/accu/height.hh +++ b/milena/mln/accu/height.hh @@ -86,6 +86,10 @@ namespace mln /// Get the value of the accumulator. std::size_t to_result() const; + /// Check whether this accu is able to return a result. + /// Always true here. + bool is_valid() const; + protected: /// The minimum level in the component. value min_level__; @@ -96,16 +100,20 @@ namespace mln }; - /// \brief Meta accumulator for height. - struct height : public Meta_Accumulator< height > + namespace meta { - template <typename I> - struct with + + /// \brief Meta accumulator for height. + struct height : public Meta_Accumulator< height > { - typedef height_<I> ret; + template <typename I> + struct with + { + typedef height_<I> ret; + }; }; - }; + } // end of namespace mln::accu::meta # ifndef MLN_INCLUDE_ONLY @@ -165,6 +173,14 @@ namespace mln max_level__ = mln_min(value); } + template <typename I> + inline + bool + height_<I>::is_valid() const + { + return true; + } + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln::accu diff --git a/milena/mln/accu/histo.hh b/milena/mln/accu/histo.hh index d1152a2..564879d 100644 --- a/milena/mln/accu/histo.hh +++ b/milena/mln/accu/histo.hh @@ -39,6 +39,7 @@ # include <algorithm> # include <mln/core/concept/value_set.hh> +# include <mln/core/concept/meta_accumulator.hh> # include <mln/accu/internal/base.hh> # include <mln/value/set.hh> # include <mln/histo/data.hh> @@ -63,6 +64,8 @@ namespace mln typedef V argument; typedef const std::vector<std::size_t>& result; + /// Manipulators. + /// \{ void take(const argument& t); void take(const histo<V>& other); void untake(const argument& t); @@ -72,12 +75,20 @@ namespace mln std::size_t operator[](unsigned i) const; unsigned nvalues() const; std::size_t sum() const; + /// \} + /// Get the value of the accumulator. + /// \{ const std::vector<std::size_t>& vect() const; const std::vector<std::size_t>& to_result() const; + /// \} const value::set<V>& vset() const; + /// Check whether this accu is able to return a result. + /// Always true here. + bool is_valid() const; + protected: mln::histo::data<V> h_; @@ -87,6 +98,21 @@ namespace mln template <typename V> std::ostream& operator<<(std::ostream& ostr, const histo<V>& h); + namespace meta + { + + /// Meta accumulator for histo. + struct histo : public Meta_Accumulator< histo > + { + template <typename V> + struct with + { + typedef mln::accu::histo<V> ret; + }; + }; + + } // end of namespace mln::accu::meta + @@ -206,6 +232,14 @@ namespace mln return ostr; } + template <typename V> + inline + bool + histo<V>::is_valid() const + { + return true; + } + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln::accu diff --git a/milena/mln/accu/max.hh b/milena/mln/accu/max.hh index 62ed3bf..7419a56 100644 --- a/milena/mln/accu/max.hh +++ b/milena/mln/accu/max.hh @@ -58,13 +58,21 @@ namespace mln max_(); + /// Manipulators. + /// \{ void init(); void take_as_init(const argument& t); void take(const argument& t); void take(const max_<T>& other); + /// \} + /// Get the value of the accumulator. T to_result() const; + /// Check whether this accu is able to return a result. + /// Always true here. + bool is_valid() const; + protected: T t_; @@ -78,7 +86,7 @@ namespace mln { /// Meta accumulator for max. - + struct max : public Meta_Accumulator< max > { template <typename T> @@ -142,6 +150,14 @@ namespace mln return t_; } + template <typename T> + inline + bool + max_<T>::is_valid() const + { + return true; + } + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln::accu diff --git a/milena/mln/accu/max_h.hh b/milena/mln/accu/max_h.hh index e393dcc..b5e19d2 100644 --- a/milena/mln/accu/max_h.hh +++ b/milena/mln/accu/max_h.hh @@ -56,18 +56,26 @@ namespace mln max_h(); + /// Manipulators. + /// \{ void init(); void take(const argument& t); void take_as_init(const argument& t); void take(const max_h<V>& other); void untake(const argument& t); + /// \} unsigned card() const { return h_.sum(); } + /// Get the value of the accumulator. argument to_result() const; const accu::histo<V>& histo() const; + /// Check whether this accu is able to return a result. + /// Always true here. + bool is_valid() const; + void debug_print_() const; protected: @@ -258,6 +266,14 @@ namespace mln template <typename V> inline + bool + max_h<V>::is_valid() const + { + return true; + } + + template <typename V> + inline void max_h<V>::debug_print_() const { diff --git a/milena/mln/accu/mean.hh b/milena/mln/accu/mean.hh index 85e5be6..afff048 100644 --- a/milena/mln/accu/mean.hh +++ b/milena/mln/accu/mean.hh @@ -65,12 +65,20 @@ namespace mln mean_(); + /// Manipulators. + /// \{ void init(); void take(const argument& t); void take(const mean_<T,S,M>& other); + /// \} + /// Get the value of the accumulator. M to_result() const; + /// Check whether this accu is able to return a result. + /// Always true here. + bool is_valid() const; + protected: accu::count_<T> count_; @@ -144,6 +152,14 @@ namespace mln return sum_.to_result() / count_.to_result(); } + template <typename T, typename S, typename M> + inline + bool + mean_<T,S,M>::is_valid() const + { + return count_.to_result() != 0; + } + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln::accu diff --git a/milena/mln/accu/median_alt.hh b/milena/mln/accu/median_alt.hh index bcf4fa0..2c84e10 100644 --- a/milena/mln/accu/median_alt.hh +++ b/milena/mln/accu/median_alt.hh @@ -1,4 +1,4 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2007, 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 @@ -54,12 +54,20 @@ namespace mln median_alt(const Value_Set<S>& s); + /// Manipulators. + /// \{ void take(const argument& t); void untake(const argument& t); void init(); + /// \} + /// Get the value of the accumulator. argument to_result() const; + /// Check whether this accu is able to return a result. + /// Always true here. + bool is_valid() const; + // FIXME: remove void debug__() const { @@ -72,12 +80,15 @@ namespace mln protected: histo<S> h_; - const S& s_; // derived from h_ + /// derived from h_ + const S& s_; std::size_t sum_minus_, sum_plus_; - std::size_t i_; // the median index - argument t_; // the median argument + /// the median index + std::size_t i_; + /// the median argument + argument t_; // Auxiliary methods void go_minus_(); @@ -205,6 +216,33 @@ namespace mln } } + template <typename S> + inline + void + median_alt<S>::init() + { + h_.init(); + sum_minus_ = 0; + sum_plus_ = 0; + i_ = (mln_max(argument) - mln_min(argument)) / 2; + t_ = s_[i_]; + } + + template <typename S> + inline + typename median_alt<S>::argument + median_alt<S>::to_result() const + { + return t_; + } + + template <typename S> + inline + bool + median_alt<S>::is_valid() const + { + return true; + } template <typename S> inline @@ -241,27 +279,6 @@ namespace mln t_ = s_[i_]; } - - template <typename S> - inline - void - median_alt<S>::init() - { - h_.init(); - sum_minus_ = 0; - sum_plus_ = 0; - i_ = (mln_max(argument) - mln_min(argument)) / 2; - t_ = s_[i_]; - } - - template <typename S> - inline - typename median_alt<S>::argument - median_alt<S>::to_result() const - { - return t_; - } - template <typename S> inline std::ostream& operator<<(std::ostream& ostr, const median_alt<S>& m) diff --git a/milena/mln/accu/median_h.hh b/milena/mln/accu/median_h.hh index cb69030..32b5b3b 100644 --- a/milena/mln/accu/median_h.hh +++ b/milena/mln/accu/median_h.hh @@ -56,17 +56,25 @@ namespace mln median_h(); + /// Manipulators. + /// \{ void init(); void take(const argument& t); void take(const median_h<V>& other); void untake(const argument& t); + /// \} unsigned card() const { return h_.sum(); } + /// Get the value of the accumulator. argument to_result() const; const accu::histo<V>& histo() const; + /// Check whether this accu is able to return a result. + /// Always true here. + bool is_valid() const; + protected: mutable accu::histo<V> h_; @@ -241,6 +249,14 @@ namespace mln return h_; } + template <typename V> + inline + bool + median_h<V>::is_valid() const + { + return true; + } + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln::accu diff --git a/milena/mln/accu/min.hh b/milena/mln/accu/min.hh index a44d012..e7044de 100644 --- a/milena/mln/accu/min.hh +++ b/milena/mln/accu/min.hh @@ -58,13 +58,21 @@ namespace mln min_(); + /// Manipulators. + /// \{ void init(); void take_as_init(const argument& t); void take(const argument& t); void take(const min_<T>& other); + /// \} + /// Get the value of the accumulator. T to_result() const; + /// Check whether this accu is able to return a result. + /// Always true here. + bool is_valid() const; + protected: T t_; @@ -79,7 +87,7 @@ namespace mln { /// Meta accumulator for min. - + struct min : public Meta_Accumulator< min > { template <typename T> @@ -142,6 +150,14 @@ namespace mln return t_; } + template <typename T> + inline + bool + min_<T>::is_valid() const + { + return true; + } + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln::accu diff --git a/milena/mln/accu/min_h.hh b/milena/mln/accu/min_h.hh index f0e4968..8c9d5fa 100644 --- a/milena/mln/accu/min_h.hh +++ b/milena/mln/accu/min_h.hh @@ -57,18 +57,26 @@ namespace mln min_h(); + /// Manipulators. + /// \{ void init(); void take(const argument& t); void take_as_init(const argument& t); void take(const min_h<V>& other); void untake(const argument& t); + /// \} unsigned card() const { return h_.sum(); } + /// Get the value of the accumulator. result to_result() const; const accu::histo<V>& histo() const; + /// Check whether this accu is able to return a result. + /// Always true here. + bool is_valid() const; + void debug_print_() const; protected: @@ -259,6 +267,15 @@ namespace mln template <typename V> inline + bool + min_h<V>::is_valid() const + { + return true; + } + + + template <typename V> + inline void min_h<V>::debug_print_() const { diff --git a/milena/mln/accu/nil.hh b/milena/mln/accu/nil.hh index 581d07e..5cd7791 100644 --- a/milena/mln/accu/nil.hh +++ b/milena/mln/accu/nil.hh @@ -1,4 +1,4 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2007, 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 @@ -58,26 +58,38 @@ namespace mln nil_(); + /// Manipulators. + /// \{ void init(); void take_as_init(const argument&); void take(const argument&); void take(const nil_<T>&); + /// \} + /// Get the value of the accumulator. util::ignore to_result() const; + + /// Check whether this accu is able to return a result. + /// Always true here. + bool is_valid() const; }; - /*! - * \brief Meta accumulator for nil. - */ - struct nil : public Meta_Accumulator< nil > + namespace meta { - template <typename V> - struct with + + /// Meta accumulator for nil. + + struct nil : public Meta_Accumulator< nil > { - typedef nil_<V> ret; + template <typename V> + struct with + { + typedef nil_<V> ret; + }; }; - }; + + } // end of namespace mln::accu::meta # ifndef MLN_INCLUDE_ONLY @@ -124,6 +136,15 @@ namespace mln return util::ignore(); } + template <typename T> + inline + bool + nil_<T>::is_valid() const + { + return true; + } + + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln::accu diff --git a/milena/mln/accu/p.hh b/milena/mln/accu/p.hh index 423399d..ce4d16c 100644 --- a/milena/mln/accu/p.hh +++ b/milena/mln/accu/p.hh @@ -1,4 +1,4 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2007, 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 @@ -61,13 +61,21 @@ namespace mln p_(); p_(const A& a); + /// Manipulators. + /// \{ void init(); void take_as_init(const argument& t); void take(const argument& t); void take(const p_<A>& other); + /// \} + /// Get the value of the accumulator. result to_result() const; + /// Check whether this accu is able to return a result. + /// Always true here. + bool is_valid() const; + protected: A a_; }; @@ -144,6 +152,14 @@ namespace mln return a_.to_result(); } + template <typename A> + inline + bool + p_<A>::is_valid() const + { + return a_.is_valid(); + } + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln::accu diff --git a/milena/mln/accu/pair.hh b/milena/mln/accu/pair.hh index 7b9402e..5e69c5f 100644 --- a/milena/mln/accu/pair.hh +++ b/milena/mln/accu/pair.hh @@ -67,17 +67,27 @@ namespace mln pair_(); pair_(const A1& a1, const A2& a2); + /// Manipulators. + /// \{ void init(); void take_as_init(const argument& t); void take(const argument& t); void take(const pair_<A1,A2,T>& other); + /// \} + /// Get the value of the accumulator. + /// \{ result to_result() const; void get_result(result_1& r1, result_2& r2) const; + /// \} mln_result(A1) first() const; mln_result(A2) second() const; + /// Check whether this accu is able to return a result. + /// Always true here. + bool is_valid() const; + protected: A1 a1_; @@ -184,6 +194,14 @@ namespace mln return a2_.to_result(); } + template <typename A1, typename A2, typename T> + inline + bool + pair_<A1,A2,T>::is_valid() const + { + return a1_.is_valid() && a2_.is_valid(); + } + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln::accu diff --git a/milena/mln/accu/rank.hh b/milena/mln/accu/rank.hh index 5190e08..69f668c 100644 --- a/milena/mln/accu/rank.hh +++ b/milena/mln/accu/rank.hh @@ -61,15 +61,23 @@ namespace mln rank_(unsigned k, unsigned n); + /// Manipulators. + /// \{ void init(); void take(const argument& t); void take(const rank_<T>& other); void untake(const argument& t); + /// \} unsigned card() const { return h_.sum(); } + /// Get the value of the accumulator. T to_result() const; + /// Check whether this accu is able to return a result. + /// Always true here. + bool is_valid() const; + protected: unsigned k_; // 0 <= k_ < n @@ -94,19 +102,21 @@ namespace mln template <typename I> struct rank_< util::pix<I> >; - /*! - * \brief Meta accumulator for rank. - */ - struct rank : public Meta_Accumulator< rank > + namespace meta { - template <typename T> - struct with + + /// Meta accumulator for rank. + + struct rank : public Meta_Accumulator< rank > { - typedef rank_<T> ret; + template <typename T> + struct with + { + typedef rank_<T> ret; + }; }; - }; - + } // end of namespace mln::accu::meta @@ -264,6 +274,14 @@ namespace mln return t_; } + template <typename T> + inline + bool + rank_<T>::is_valid() const + { + return valid_; + } + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln::accu diff --git a/milena/mln/accu/rank_bool.hh b/milena/mln/accu/rank_bool.hh index 1537825..2ea878f 100644 --- a/milena/mln/accu/rank_bool.hh +++ b/milena/mln/accu/rank_bool.hh @@ -60,19 +60,28 @@ namespace mln rank_(unsigned k, unsigned n); + /// Manipulators. + /// \{ void init(); void take_as_init(const argument& t); void take(const argument& t); void take(const rank_<bool>& other); + /// \} + /// Get the value of the accumulator. bool to_result() const; + /// Check whether this accu is able to return a result. + /// Always true here. + bool is_valid() const; + protected: unsigned nfalse_; unsigned k_; // 0 <= k_ < n unsigned n_; }; + # ifndef MLN_INCLUDE_ONLY inline @@ -124,6 +133,13 @@ namespace mln return k_ >= nfalse_; } + inline + bool + rank_<bool>::is_valid() const + { + return nfalse_ <= n_; + } + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln::accu diff --git a/milena/mln/accu/rank_high_quant.hh b/milena/mln/accu/rank_high_quant.hh index fe3f02b..151c6e5 100644 --- a/milena/mln/accu/rank_high_quant.hh +++ b/milena/mln/accu/rank_high_quant.hh @@ -59,14 +59,22 @@ namespace mln rank_(unsigned k, unsigned n); + /// Manipulators. + /// \{ void init(); void take_as_init(const argument& t); void take(const argument& t); void take(const rank_<T>& other); void sort(); + /// \} + /// Get the value of the accumulator. T to_result() const; + /// Check whether this accu is able to return a result. + /// Always true here. + bool is_valid() const; + protected: std::vector<T> elts_; @@ -79,21 +87,21 @@ namespace mln template <typename I> struct rank_< util::pix<I> >; - /*! - * \brief Meta accumulator for rank. - */ - struct rank : public Meta_Accumulator< rank > + namespace meta { - template <typename T> - struct with - { - typedef rank_<T> ret; - }; - }; - + /// Meta accumulator for rank. + struct rank : public Meta_Accumulator< rank > + { + template <typename T> + struct with + { + typedef rank_<T> ret; + }; + }; + } # ifndef MLN_INCLUDE_ONLY @@ -160,6 +168,14 @@ namespace mln template <typename T> inline + bool + rank_<T>::is_valid() const + { + return true; + } + + template <typename T> + inline void rank_<T>::sort() { diff --git a/milena/mln/accu/sum.hh b/milena/mln/accu/sum.hh index 670b87d..2c0569a 100644 --- a/milena/mln/accu/sum.hh +++ b/milena/mln/accu/sum.hh @@ -64,12 +64,20 @@ namespace mln sum_(); + /// Manipulators. + /// \{ void init(); void take(const argument& t); void take(const sum_<T,S>& other); + /// \} + /// Get the value of the accumulator. S to_result() const; + /// Check whether this accu is able to return a result. + /// Always true here. + bool is_valid() const; + protected: S s_; @@ -135,6 +143,14 @@ namespace mln return s_; } + template <typename T, typename S> + inline + bool + sum_<T,S>::is_valid() const + { + return true; + } + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln::accu diff --git a/milena/mln/accu/tuple.hh b/milena/mln/accu/tuple.hh index fa06331..d1cb1d1 100644 --- a/milena/mln/accu/tuple.hh +++ b/milena/mln/accu/tuple.hh @@ -82,32 +82,44 @@ namespace mln tuple_(); + /// Manipulators. + /// \{ void init(); void take_as_init(const argument& t); void take(const argument& t); void take(const tuple_<A, n, BOOST_PP_ENUM_PARAMS(10, T)>& other); + /// \} + /// Get the value of the accumulator. result to_result() const; + /// Check whether this accu is able to return a result. + /// Always true here. + bool is_valid() const; + protected: intern a_; }; - /*! - * \brief Meta accumulator for tuple. - */ - template <unsigned n, BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(10, typename T, boost::tuples::null_type)> - struct tuple : public Meta_Accumulator< tuple<n, BOOST_PP_ENUM_PARAMS(10, T)> > + namespace meta { - template <typename A> - struct with + + ///Meta accumulator for tuple. + + template <unsigned n, BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(10, typename T, boost::tuples::null_type)> + struct tuple : public Meta_Accumulator< tuple<n, BOOST_PP_ENUM_PARAMS(10, T)> > { + template <typename A> + struct with + { # include BOOST_PP_LOCAL_ITERATE() - typedef tuple_<A, n, BOOST_PP_ENUM_PARAMS(10, AT)> ret; + typedef tuple_<A, n, BOOST_PP_ENUM_PARAMS(10, AT)> ret; + }; }; - }; + + } # ifndef MLN_INCLUDE_ONLY @@ -221,6 +233,14 @@ namespace mln return tmp; } + template <typename A, unsigned n, BOOST_PP_ENUM_PARAMS(10, typename T)> + inline + bool + tuple_<A,n,BOOST_PP_ENUM_PARAMS(10,T) >::is_valid() const + { + return true; + } + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln::accu diff --git a/milena/mln/accu/v.hh b/milena/mln/accu/v.hh index ddb6dd3..53676f1 100644 --- a/milena/mln/accu/v.hh +++ b/milena/mln/accu/v.hh @@ -1,4 +1,4 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2007, 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 @@ -46,9 +46,8 @@ namespace mln { - /*! - * \brief Generic val of accumulators. - */ + + /// Generic val of accumulators. template <typename A> struct val_ : public mln::accu::internal::base< mln_result(A) , val_<A> > { @@ -58,10 +57,13 @@ namespace mln val_(); val_(const A& a); + /// Manipulators. + /// \{ void init(); void take_as_init(const argument& t); void take(const argument& t); void take(const val_<A>& other); + /// \} template <typename I> void take_as_init(const util::pix<I>& pix) @@ -75,27 +77,35 @@ namespace mln a_.take(pix.v()); } + /// Get the value of the accumulator. result to_result() const; + /// Check whether this accu is able to return a result. + /// Always true here. + bool is_valid() const; + protected: A a_; }; - /*! - * \brief Meta accumulator for val. - */ - template <typename mA> - struct val : public Meta_Accumulator< val<mA> > + namespace meta { - template <typename V> - struct with + + /// Meta accumulator for val. + + template <typename mA> + struct val : public Meta_Accumulator< val<mA> > { - typedef mln_accu_with(mA, mln_value(V)) A; - typedef val_<A> ret; + template <typename V> + struct with + { + typedef mln_accu_with(mA, mln_value(V)) A; + typedef val_<A> ret; + }; }; - }; + } # ifndef MLN_INCLUDE_ONLY @@ -154,6 +164,15 @@ namespace mln return a_.to_result(); } + template <typename A> + inline + bool + val_<A>::is_valid() const + { + return a_.is_valid(); + } + + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln::accu diff --git a/milena/mln/accu/volume.hh b/milena/mln/accu/volume.hh index aa1bcad..aed5a51 100644 --- a/milena/mln/accu/volume.hh +++ b/milena/mln/accu/volume.hh @@ -85,6 +85,10 @@ namespace mln /// Get the value of the accumulator. std::size_t to_result() const; + /// Check whether this accu is able to return a result. + /// Always true here. + bool is_valid() const; + protected: /// The reference level (the level of the component's root). value ref_level__; @@ -95,15 +99,21 @@ namespace mln }; - /// \brief Meta accumulator for volume. - struct volume : public Meta_Accumulator< volume > + namespace meta { - template <typename I> - struct with + + /// Meta accumulator for volume. + + struct volume : public Meta_Accumulator< volume > { - typedef volume_<I> ret; + template <typename I> + struct with + { + typedef volume_<I> ret; + }; }; - }; + + } // end of namespace mln::accu::meta # ifndef MLN_INCLUDE_ONLY @@ -182,6 +192,14 @@ namespace mln area__ = 0; } + template <typename I> + inline + bool + volume_<I>::is_valid() const + { + return true; + } + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln::accu diff --git a/milena/mln/core/concept/accumulator.hh b/milena/mln/core/concept/accumulator.hh index 0578780..882341b 100644 --- a/milena/mln/core/concept/accumulator.hh +++ b/milena/mln/core/concept/accumulator.hh @@ -75,6 +75,8 @@ namespace mln result to_result() const; operator mlc_unqualif(result) const; + + bool is_valid() const; */ // Default impl. @@ -104,10 +106,12 @@ namespace mln result (E::*m4)() const = & E::to_result; m4 = 0; - typedef mlc_fix_return(mlc_const_return(result)) result_; result_ (E::*m5)() const = & E::operator result_; m5 = 0; + + bool (E::*m6)() const = & E::is_valid; + m6 = 0; } template <typename E> diff --git a/milena/mln/morpho/gradient_elementary.hh b/milena/mln/morpho/gradient_elementary.hh index 8a5f944..282e494 100644 --- a/milena/mln/morpho/gradient_elementary.hh +++ b/milena/mln/morpho/gradient_elementary.hh @@ -84,7 +84,7 @@ namespace mln trace::entering("morpho::impl::generic::gradient_elementary_on_function"); mln_concrete(I) output; - output = internal::elementary< accu::min_max >(input, nbh, f_grad()); + output = internal::elementary< accu::meta::min_max >(input, nbh, f_grad()); trace::exiting("morpho::impl::generic::gradient_elementary_on_function"); return output; diff --git a/milena/tests/accu/all_accus.cc b/milena/tests/accu/all_accus.cc index 82e51fa..394d750 100644 --- a/milena/tests/accu/all_accus.cc +++ b/milena/tests/accu/all_accus.cc @@ -48,7 +48,7 @@ int main() // min_h< value::set<bool> > mh; // OK: do not work since bool has // no min/max :) min_max_<int> mm; - nil n; + nil_<int> n; pair_< min_<int>, max_<int> > p; sum_<int> s; } diff --git a/milena/tests/accu/max.cc b/milena/tests/accu/max.cc index 310ee1b..427f91f 100644 --- a/milena/tests/accu/max.cc +++ b/milena/tests/accu/max.cc @@ -47,16 +47,7 @@ int main() using namespace mln; image2d<int> ima(3, 3); debug::iota(ima); - mln_assertion(level::compute< accu::max >(ima) == 9); - mln_assertion(level::compute< accu::max_<int> >(ima) == 9); - - accu::compute< accu::nil >(ima); // No-op. - - // FIXME : what's the difference between - // accu::compute< accu::max >(ima); - - mln_assertion( accu::compute< accu::val<accu::max> >(ima) == 9); - -// std::cout << accu::compute< accu::max >(ima) -// << std::endl; + mln_assertion(level::compute(accu::meta::max(), ima) == 9); + accu::max_<int> M; + mln_assertion(level::compute(M, ima) == 9); } diff --git a/milena/tests/accu/mean.cc b/milena/tests/accu/mean.cc index eca1c04..7cd2ca7 100644 --- a/milena/tests/accu/mean.cc +++ b/milena/tests/accu/mean.cc @@ -40,7 +40,7 @@ int main() using namespace mln; { - mln_accu_with_(accu::mean, int) mean; + mln_accu_with_(accu::meta::mean, int) mean; mean.take(10); mean.take(9); @@ -58,7 +58,7 @@ int main() } { - mln_accu_with_(accu::mean, int) mean; + mln_accu_with_(accu::meta::mean, int) mean; mean.take(10); mean.take(8); diff --git a/milena/tests/accu/min.cc b/milena/tests/accu/min.cc index e3769b8..0eba5ab 100644 --- a/milena/tests/accu/min.cc +++ b/milena/tests/accu/min.cc @@ -47,15 +47,8 @@ int main() using namespace mln; image2d<int> ima(3, 3); debug::iota(ima); - mln_assertion(level::compute< accu::min >(ima) == 1); - mln_assertion(level::compute< accu::min_<int> >(ima) == 1); + mln_assertion(level::compute(accu::meta::min(), ima) == 1); -// accu::compute< accu::nil >(ima); // No-op. - -// accu::compute< accu::min >(ima); - - mln_assertion(accu::compute< accu::val<accu::min> >(ima) == 1); - -// std::cout << accu::compute< accu::min >(ima) -// << std::endl; + accu::min_<int> m; + mln_assertion(level::compute(m, ima) == 1); } diff --git a/milena/tests/accu/min_max.cc b/milena/tests/accu/min_max.cc index cdcdb63..74b1ad0 100644 --- a/milena/tests/accu/min_max.cc +++ b/milena/tests/accu/min_max.cc @@ -40,7 +40,7 @@ int main() using namespace mln; { - mln_accu_with_(accu::min_max, int) accu; + mln_accu_with_(accu::meta::min_max, int) accu; accu.take(7); @@ -49,7 +49,7 @@ int main() } { - mln_accu_with_(accu::min_max, int) accu; + mln_accu_with_(accu::meta::min_max, int) accu; accu.take(10); accu.take(9); diff --git a/milena/tests/accu/nil.cc b/milena/tests/accu/nil.cc index 5ae0826..f2421ff 100644 --- a/milena/tests/accu/nil.cc +++ b/milena/tests/accu/nil.cc @@ -41,6 +41,9 @@ int main() { using namespace mln; image2d<value::int_u8> ima(3, 3); - accu::nil a; - level::compute<accu::nil>(ima); + + accu::nil_<value::int_u8> a; + level::compute(a, ima); + + level::compute(accu::meta::nil(), ima); } -- 1.5.6.5
participants (1)
-
Guillaume Lazzara