Commit 038f5a7d authored by Guillaume Lazzara's avatar Guillaume Lazzara
Browse files

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

git-svn-id: https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008@2553 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent b79150a2
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.
......
......@@ -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:
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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:
......@@ -256,6 +264,14 @@ namespace mln
return h_;
}
template <typename V>
inline
bool
max_h<V>::is_valid() const
{
return true;
}
template <typename V>
inline
void
......
......@@ -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
......
// 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)
......
......@@ -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
......
......@@ -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
......
......@@ -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:
......@@ -257,6 +265,15 @@ namespace mln
return h_;
}
template <typename V>
inline
bool
min_h<V>::is_valid() const
{
return true;
}
template <typename V>
inline
void
......
// 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