3660: Make util::array a Function_i2v.

* mln/fun/i2v/array.hh: fix doc. * mln/labeling/mean_values.hh: do not use convert::to anymore. * mln/util/array.hh: now inherits from Function_i2v. --- milena/ChangeLog | 10 ++++ milena/mln/fun/i2v/array.hh | 3 +- milena/mln/labeling/mean_values.hh | 4 +- milena/mln/util/array.hh | 89 ++++++++++++++++++++++++++++++++++-- 4 files changed, 98 insertions(+), 8 deletions(-) diff --git a/milena/ChangeLog b/milena/ChangeLog index 99e16b5..7f69bb3 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,15 @@ 2009-04-09 Guillaume Lazzara <lazzara@lrde.epita.fr> + Make util::array a Function_i2v. + + * mln/fun/i2v/array.hh: fix doc. + + * mln/labeling/mean_values.hh: do not use convert::to anymore. + + * mln/util/array.hh: now inherits from Function_i2v. + +2009-04-09 Guillaume Lazzara <lazzara@lrde.epita.fr> + Remove l2l::relabel. * mln/convert/from_to.hxx, diff --git a/milena/mln/fun/i2v/array.hh b/milena/mln/fun/i2v/array.hh index 4058e48..f8030a9 100644 --- a/milena/mln/fun/i2v/array.hh +++ b/milena/mln/fun/i2v/array.hh @@ -116,9 +116,10 @@ namespace mln public: /// Returned value types - /// \{ + /// @{ typedef T result; typedef typename std::vector<T>::reference mutable_result; + /// @} /// Constructors /// \{ diff --git a/milena/mln/labeling/mean_values.hh b/milena/mln/labeling/mean_values.hh index 0565abb..3f6b8f1 100644 --- a/milena/mln/labeling/mean_values.hh +++ b/milena/mln/labeling/mean_values.hh @@ -119,9 +119,7 @@ namespace mln convert::from_to(m_3f, m); m[0] = 150u; //FIXME: handle label 0 correctly. - mln_concrete(I) output = level::transform(lbl, - convert::to< fun::i2v::array<IV> >(m)); - + mln_concrete(I) output = level::transform(lbl, m); trace::exiting("mln::labeling::impl::generic::mean_values"); return output; diff --git a/milena/mln/util/array.hh b/milena/mln/util/array.hh index 0363727..5eb5fc4 100644 --- a/milena/mln/util/array.hh +++ b/milena/mln/util/array.hh @@ -38,6 +38,7 @@ # include <vector> # include <iostream> +# include <mln/core/concept/function.hh> # include <mln/core/concept/proxy.hh> # include <mln/core/concept/iterator.hh> @@ -87,14 +88,23 @@ namespace mln /// The parameter \c T is the element type, which shall not be /// const-qualified. template <typename T> - class array : public Object< mln::util::array<T> > + class array : public Function_i2v< mln::util::array<T> > { public: /// Element associated type. typedef T element; + /// Returned value types. + /// Related to the Function_i2v concept. + /// @{ + typedef T result; + typedef typename std::vector<T>::reference mutable_result; + /// @} + + /// Iterator types + /// @{ /// Forward iterator associated type. typedef array_fwd_iter<T> fwd_eiter; @@ -103,8 +113,11 @@ namespace mln /// Iterator associated type. typedef fwd_eiter eiter; + /// @} + /// Constructors + /// @{ /// Constructor without arguments. array(); @@ -114,7 +127,7 @@ namespace mln /// Construct a new array, resize it to \n elements and fill it /// with \p default_value. array(unsigned n, const T& value); - + /// @} /// Reserve memory for \p n elements. void reserve(unsigned n); @@ -137,12 +150,25 @@ namespace mln /// Return the number of elements of the array. unsigned nelements() const; + /// Return the number of elements of the array. + /// Added for compatibility with fun::i2v::array. + /// \sa nelements + unsigned size() const; + /// Test if the array is empty. bool is_empty() const; /// \brief Return the \p i-th element of the array. /// \pre i < nelements() + const T& operator()(unsigned i) const; + + /// \brief Return the \p i-th element of the array. + /// \pre i < nelements() + T& operator()(unsigned i); + + /// \brief Return the \p i-th element of the array. + /// \pre i < nelements() const T& operator[](unsigned i) const; /// \brief Return the \p i-th element of the array. @@ -165,7 +191,6 @@ namespace mln std::size_t memory_size() const; private: - std::vector<T> v_; }; @@ -190,11 +215,14 @@ namespace mln { public: + /// Constructors + /// @{ /// Constructor without argument. array_fwd_iter(); /// Constructor from an array \p a. array_fwd_iter(const array<T>& a); + /// @} /// Change the array it iterates on to \p a. void change_target(const array<T>& a); @@ -236,12 +264,14 @@ namespace mln array_bkd_iter<T> > { public: - + /// Constructors + /// @{ /// Constructor without argument. array_bkd_iter(); /// Constructor from an array \p a. array_bkd_iter(const array<T>& a); + /// @} /// Change the array it iterates on to \p a. void change_target(const array<T>& a); @@ -282,7 +312,9 @@ namespace mln struct subject_impl<const util::array<T>&, E> { unsigned nelements() const; + unsigned size() const; bool is_empty() const; + const T& operator()(unsigned i) const; const T& operator[](unsigned i) const; const std::vector<T>& std_vector() const; @@ -304,6 +336,7 @@ namespace mln template <typename U> util::array<T>& append(const util::array<U>& other); + T& operator()(unsigned i); T& operator[](unsigned i); void clear(); @@ -431,6 +464,14 @@ namespace mln template <typename T> inline unsigned + array<T>::size() const + { + return nelements(); + } + + template <typename T> + inline + unsigned array<T>::nelements() const { return v_.size(); @@ -439,6 +480,22 @@ namespace mln template <typename T> inline const T& + array<T>::operator()(unsigned i) const + { + return (*this)[i]; + } + + template <typename T> + inline + T& + array<T>::operator()(unsigned i) + { + return (*this)(i); + } + + template <typename T> + inline + const T& array<T>::operator[](unsigned i) const { mln_precondition(i < nelements()); @@ -750,6 +807,14 @@ namespace mln template <typename T, typename E> inline T& + subject_impl<util::array<T>&, E>::operator()(unsigned i) + { + return exact_().get_subject()(i); + } + + template <typename T, typename E> + inline + T& subject_impl<util::array<T>&, E>::operator[](unsigned i) { return exact_().get_subject()[i]; @@ -783,6 +848,14 @@ namespace mln template <typename T, typename E> inline unsigned + subject_impl<const util::array<T>&, E>::size() const + { + return exact_().get_subject().size(); + } + + template <typename T, typename E> + inline + unsigned subject_impl<const util::array<T>&, E>::nelements() const { return exact_().get_subject().nelements(); @@ -799,6 +872,14 @@ namespace mln template <typename T, typename E> inline const T& + subject_impl<const util::array<T>&, E>::operator()(unsigned i) const + { + return exact_().get_subject()(i); + } + + template <typename T, typename E> + inline + const T& subject_impl<const util::array<T>&, E>::operator[](unsigned i) const { return exact_().get_subject()[i]; -- 1.5.6.5
participants (1)
-
Guillaume Lazzara