2353: Update iterators on p_complex.

* mln/core/internal/p_complex_piter_base.hh (mln::p_complex_piter_base_<D, P>): Inherit from internal::site_set_iterator_base. (mln::p_complex_piter_base_<D, P>::super_): Update typedef. (mln::p_complex_piter_base_<D, P>::complex_dim): New constant. (mln::p_complex_piter_base_<D, P>::pset) (mln::p_complex_piter_base_<D, P>::psite): Remove typedefs. (mln::p_complex_piter_base_<D, P>::p_complex_piter_base_): New default ctor. (mln::p_complex_piter_base_<D, P>::p_complex_piter_base_(const self&)): Remove copy ctor. (mln::p_complex_piter_base_<D, P>::p_complex_piter_base_): Update other ctor. (mln::p_complex_piter_base_<D, P>::operator=(const self&)): Remove operator. (mln::p_complex_piter_base_<D, P>::next_) (mln::p_complex_piter_base_<D, P>::update_): Update methods. (mln::p_complex_piter_base_<D, P>::is_valid) (mln::p_complex_piter_base_<D, P>::invalidate) (mln::p_complex_piter_base_<D, P>::start): Likewise. Rename as... (mln::p_complex_piter_base_<D, P>::is_valid_) (mln::p_complex_piter_base_<D, P>::invalidate_) (mln::p_complex_piter_base_<D, P>::start_): ...these. (mln::p_complex_piter_base_<D, P>::to_point) (mln::p_complex_piter_base_<D, P>::to_psite) (mln::p_complex_piter_base_<D, P>::operator psite) (mln::p_complex_piter_base_<D, P>::operator[]): Remove methods. (operator<<(std::ostream&, const p_complex_piter_base_<I, P, E>&)): Update. (mln::p_complex_piter_base_<D, P>::p_): Get it from the super class. (mln::p_complex_piter_base_<D, P>::psite): Remove attribute. * mln/core/site_set/p_complex_piter.hh: (mln::p_complex_fwd_piter_<D, P>::p_complex_fwd_piter_) (mln::p_complex_bkd_piter_<D, P>::p_complex_bkd_piter_): New default ctors. (mln::p_complex_fwd_piter_<D, P>::p_complex_fwd_piter_) (mln::p_complex_bkd_piter_<D, P>::p_complex_bkd_piter_): Adjust other ctor. (mln::p_complex_fwd_piter_<D, P>::p_complex_fwd_piter_(const self_&)) (mln::p_complex_bkd_piter_<D, P>::p_complex_bkd_piter_(const self_&)) (mln::p_complex_fwd_piter_<D, P>::operator=(const self_&)) (mln::p_complex_bkd_piter_<D, P>::operator=(const self_&)): Remove. --- milena/ChangeLog | 55 +++++++ milena/mln/core/internal/p_complex_piter_base.hh | 173 +++++----------------- milena/mln/core/site_set/p_complex_piter.hh | 44 +----- 3 files changed, 103 insertions(+), 169 deletions(-) diff --git a/milena/ChangeLog b/milena/ChangeLog index 583ddc0..ee684ea 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,60 @@ 2008-09-22 Roland Levillain <roland@lrde.epita.fr> + Update iterators on p_complex. + + * mln/core/internal/p_complex_piter_base.hh + (mln::p_complex_piter_base_<D, P>): Inherit + from internal::site_set_iterator_base. + (mln::p_complex_piter_base_<D, P>::super_): Update typedef. + (mln::p_complex_piter_base_<D, P>::complex_dim): New constant. + (mln::p_complex_piter_base_<D, P>::pset) + (mln::p_complex_piter_base_<D, P>::psite): + Remove typedefs. + (mln::p_complex_piter_base_<D, P>::p_complex_piter_base_): + New default ctor. + (mln::p_complex_piter_base_<D, P>::p_complex_piter_base_(const self&)): + Remove copy ctor. + (mln::p_complex_piter_base_<D, P>::p_complex_piter_base_): + Update other ctor. + (mln::p_complex_piter_base_<D, P>::operator=(const self&)): + Remove operator. + (mln::p_complex_piter_base_<D, P>::next_) + (mln::p_complex_piter_base_<D, P>::update_): + Update methods. + (mln::p_complex_piter_base_<D, P>::is_valid) + (mln::p_complex_piter_base_<D, P>::invalidate) + (mln::p_complex_piter_base_<D, P>::start): + Likewise. + Rename as... + (mln::p_complex_piter_base_<D, P>::is_valid_) + (mln::p_complex_piter_base_<D, P>::invalidate_) + (mln::p_complex_piter_base_<D, P>::start_): + ...these. + (mln::p_complex_piter_base_<D, P>::to_point) + (mln::p_complex_piter_base_<D, P>::to_psite) + (mln::p_complex_piter_base_<D, P>::operator psite) + (mln::p_complex_piter_base_<D, P>::operator[]): + Remove methods. + (operator<<(std::ostream&, const p_complex_piter_base_<I, P, E>&)): + Update. + (mln::p_complex_piter_base_<D, P>::p_): Get it from the super + class. + (mln::p_complex_piter_base_<D, P>::psite): Remove attribute. + * mln/core/site_set/p_complex_piter.hh: + (mln::p_complex_fwd_piter_<D, P>::p_complex_fwd_piter_) + (mln::p_complex_bkd_piter_<D, P>::p_complex_bkd_piter_): + New default ctors. + (mln::p_complex_fwd_piter_<D, P>::p_complex_fwd_piter_) + (mln::p_complex_bkd_piter_<D, P>::p_complex_bkd_piter_): + Adjust other ctor. + (mln::p_complex_fwd_piter_<D, P>::p_complex_fwd_piter_(const self_&)) + (mln::p_complex_bkd_piter_<D, P>::p_complex_bkd_piter_(const self_&)) + (mln::p_complex_fwd_piter_<D, P>::operator=(const self_&)) + (mln::p_complex_bkd_piter_<D, P>::operator=(const self_&)): + Remove. + +2008-09-22 Roland Levillain <roland@lrde.epita.fr> + Update site on mln::p_faces. * mln/core/faces_psite.hh (mln::faces_psite<N, D, P>): Inherit diff --git a/milena/mln/core/internal/p_complex_piter_base.hh b/milena/mln/core/internal/p_complex_piter_base.hh index a9d5f6d..c9787c1 100644 --- a/milena/mln/core/internal/p_complex_piter_base.hh +++ b/milena/mln/core/internal/p_complex_piter_base.hh @@ -32,16 +32,14 @@ /// \brief Definition of an implementation (factoring) class for /// iterators on mln::p_complex. -# include <limits> - -# include <mln/core/internal/point_iterator_base.hh> -# include <mln/core/p_complex.hh> +# include <mln/core/internal/site_set_iterator_base.hh> +# include <mln/core/site_set/p_complex.hh> # include <mln/core/complex_psite.hh> # include <mln/core/complex_iter.hh> + namespace mln { - /* FIXME: Get rid of P? */ // Forward declarations. template <unsigned D, typename P> class p_complex; @@ -57,75 +55,58 @@ namespace mln /// \brief Factoring class for iterators on mln::p_complex. /// /// \arg \p I The type of the underlying complex iterator. - /// \arg \p P The associated point type. + /// \arg \p P The associated site type. /// \arg \p E The type exact type of the iterator. template <typename I, typename P, typename E> - class p_complex_piter_base_ : public point_iterator_base_< P, E > + class p_complex_piter_base_ + : public internal::site_set_iterator_base< p_complex<I::complex_dim, P>, + p_complex_piter_base_<I, P, E> > { + static const unsigned D = I::complex_dim; + typedef p_complex_piter_base_<I, P, E> self_; - typedef point_iterator_base_< P, E > super_; + typedef internal::site_set_iterator_base< p_complex<D, P>, + self_ > super_; /// The type of the underlying complex iterator. typedef I iter; public: - typedef p_complex<iter::complex_dim, P> pset; - typedef complex_psite<iter::complex_dim, P> psite; - typedef P point; - typedef mln_coord(point) coord; - /// Construction and assignment. /// \{ - p_complex_piter_base_(const pset& pc); - p_complex_piter_base_(const self_& rhs); - self_& operator= (const self_& rhs); + p_complex_piter_base_(); + p_complex_piter_base_(const p_complex<D, P>& pc); /// \} /// Manipulation. /// \{ + public: /// Test if the iterator is valid. - bool is_valid() const; + bool is_valid_() const; /// Invalidate the iterator. - void invalidate(); - /// Start an iteration. - void start(); + void invalidate_(); + /// Start an iteration. + void start_(); /// Go to the next point. void next_(); - /// Update the internal data of the iterator. + + private: + /// Update the psite. void update_(); /// \} - /// Conversion and accessors. - /// \{ - /// Reference to the corresponding point. - // FIXME: Don't use this method (dummy value). - const point& to_point () const; - /// Reference to the corresponding point site. - const psite& to_psite () const; - /// Convert the iterator into a line graph psite. - operator psite() const; - - /// Read-only access to the \a i-th coordinate. - // FIXME: Don't use this operator (dummy value). - coord operator[](unsigned i) const; - /// \} + protected: + /// The psite corresponding to this iterator. + using super_::p_; private: /// The underlying complex iterator. iter iter_; - /// The psite corresponding to this iterator. - psite psite_; - /// \brief The point associated to this psite. - // FIXME: Actually, this is a dummy value! - point p_; }; - /* FIXME: This hand-made delegation is painful. We should rely on - the general mechanism provided by Point_Site. But then again, we - need to refine/adjust the interface of Point_Site w.r.t. the - mandatory conversions to points. */ + /// Print an mln::p_complex_piter_base_<I, P, E>. template <typename I, typename P, typename E> inline std::ostream& @@ -133,7 +114,6 @@ namespace mln - # ifndef MLN_INCLUDE_ONLY /*---------------------------------. @@ -142,50 +122,24 @@ namespace mln template <typename I, typename P, typename E> inline - p_complex_piter_base_<I, P, E>::p_complex_piter_base_(const pset& pc) - // Initialize psite_ and p_ a dummy values. - : psite_(), - p_() - { - iter_.set_cplx(pc.cplx()); - mln_postcondition(!is_valid()); - } - - template <typename I, typename P, typename E> - inline - p_complex_piter_base_<I, P, E>::p_complex_piter_base_(const p_complex_piter_base_<I, P, E>& rhs) - : iter_(rhs.iter_), - psite_(rhs.psite_), - // Dummy value. - p_() - { - } - - template <typename I, typename P, typename E> - inline - p_complex_piter_base_<I, P, E>& - p_complex_piter_base_<I, P, E>::operator=(const p_complex_piter_base_<I, P, E>& rhs) + p_complex_piter_base_<I, P, E>::p_complex_piter_base_() { - if (&rhs == this) - return *this; - iter_ = rhs.iter_; - psite_ = rhs.psite_; - return *this; + mln_postcondition(!this->is_valid()); } template <typename I, typename P, typename E> inline - mln_coord(P) - p_complex_piter_base_<I, P, E>::operator[](unsigned i) const + p_complex_piter_base_<I, P, E>::p_complex_piter_base_(const p_complex<D, P>& pc) { - // Dummy value. - return p_[i]; + this->change_target(pc); + iter_.set_cplx(pc.cplx()); + mln_postcondition(!this->is_valid()); } template <typename I, typename P, typename E> inline bool - p_complex_piter_base_<I, P, E>::is_valid() const + p_complex_piter_base_<I, P, E>::is_valid_() const { return iter_.is_valid(); } @@ -193,7 +147,7 @@ namespace mln template <typename I, typename P, typename E> inline void - p_complex_piter_base_<I, P, E>::invalidate() + p_complex_piter_base_<I, P, E>::invalidate_() { iter_.invalidate(); } @@ -201,10 +155,11 @@ namespace mln template <typename I, typename P, typename E> inline void - p_complex_piter_base_<I, P, E>::start() + p_complex_piter_base_<I, P, E>::start_() { iter_.start(); - update_(); + if (this->is_valid()) + update_(); } template <typename I, typename P, typename E> @@ -213,7 +168,7 @@ namespace mln p_complex_piter_base_<I, P, E>::next_() { iter_.next_(); - if (is_valid()) + if (this->is_valid()) update_(); } @@ -222,44 +177,9 @@ namespace mln void p_complex_piter_base_<I, P, E>::update_() { + mln_precondition(this->is_valid()); // Update psite_. - psite_ = psite(iter_); - } - - template <typename I, typename P, typename E> - inline - const P& - p_complex_piter_base_<I, P, E>::to_point() const - { - // Dummy value. - return p_; - } - - template <typename I, typename P, typename E> - inline - const typename p_complex_piter_base_<I, P, E>::psite& - p_complex_piter_base_<I, P, E>::to_psite() const - { - /* We don't check whether the iterator is valid before returning - the value using - - mln_precondition(is_valid()); - - since this method may be called *before* the iterator is - actually initialized. This is the case for instance when this - point iterator (say, P) is used to initialize another iterator - on window or neighborhood (say, Q); most of the time, for_all() - is responsible for the initialization of P, but it takes place - *after* the creation of Q. */ - return psite_; - } - - template <typename I, typename P, typename E> - inline - p_complex_piter_base_<I, P, E>::operator psite() const - { - mln_precondition(is_valid()); - return psite_; + p_ = complex_psite<D, P>(exact(this)->site_set(), iter_); } @@ -268,20 +188,7 @@ namespace mln std::ostream& operator<<(std::ostream& ostr, const p_complex_piter_base_<I, P, E>& p) { - /* FIXME: We should use p.to_psite() here, but as it lacks the - precondition the conversion operator has, so we use the latter. - - We should - - rename `to_psite' as `to_psite_'; - - write a new `to_psite' routine checking the validity of the - iterator; - - have the conversion operator to psite use this new `to_psite' - routine; - - adjust former clients of `to_psite' - - This is a general remark that applies to all point/psite - iterators of Milena. */ - return ostr << static_cast< mln_psite(E) >(p); + return ostr << p.unproxy_(); } # endif // ! MLN_INCLUDE_ONLY diff --git a/milena/mln/core/site_set/p_complex_piter.hh b/milena/mln/core/site_set/p_complex_piter.hh index 817306e..7cde5bf 100644 --- a/milena/mln/core/site_set/p_complex_piter.hh +++ b/milena/mln/core/site_set/p_complex_piter.hh @@ -35,8 +35,6 @@ namespace mln { - /* FIXME: Get rid of P? */ - /*-----------------------------. | p_complex_fwd_piter_<D, P>. | @@ -56,9 +54,8 @@ namespace mln public: /// Construction and assignment. /// \{ + p_complex_fwd_piter_(); p_complex_fwd_piter_(const p_complex<D, P>& pc); - p_complex_fwd_piter_(const self_& rhs); - self_& operator= (const self_& rhs); /// \} }; @@ -81,9 +78,8 @@ namespace mln public: /// Construction and assignment. /// \{ + p_complex_bkd_piter_(); p_complex_bkd_piter_(const p_complex<D, P>& pc); - p_complex_bkd_piter_(const self_& rhs); - self_& operator= (const self_& rhs); /// \} }; @@ -97,27 +93,15 @@ namespace mln template <unsigned D, typename P> inline - p_complex_fwd_piter_<D, P>::p_complex_fwd_piter_(const p_complex<D, P>& pc) - : super_(pc) - { - } - - template <unsigned D, typename P> - inline - p_complex_fwd_piter_<D, P>::p_complex_fwd_piter_(const p_complex_fwd_piter_<D, P>& rhs) - : super_(rhs) + p_complex_fwd_piter_<D, P>::p_complex_fwd_piter_() { } template <unsigned D, typename P> inline - p_complex_fwd_piter_<D, P>& - p_complex_fwd_piter_<D, P>::operator=(const p_complex_fwd_piter_<D, P>& rhs) + p_complex_fwd_piter_<D, P>::p_complex_fwd_piter_(const p_complex<D, P>& pc) + : super_(pc) { - if (&rhs == this) - return *this; - super_::operator=(rhs); - return *this; } @@ -127,27 +111,15 @@ namespace mln template <unsigned D, typename P> inline - p_complex_bkd_piter_<D, P>::p_complex_bkd_piter_(const p_complex<D, P>& pc) - : super_(pc) + p_complex_bkd_piter_<D, P>::p_complex_bkd_piter_() { } template <unsigned D, typename P> inline - p_complex_bkd_piter_<D, P>::p_complex_bkd_piter_(const p_complex_bkd_piter_<D, P>& rhs) - : super_(rhs) - { - } - - template <unsigned D, typename P> - inline - p_complex_bkd_piter_<D, P>& - p_complex_bkd_piter_<D, P>::operator=(const p_complex_bkd_piter_<D, P>& rhs) + p_complex_bkd_piter_<D, P>::p_complex_bkd_piter_(const p_complex<D, P>& pc) + : super_(pc) { - if (&rhs == this) - return *this; - super_::operator=(rhs); - return *this; } # endif // ! MLN_INCLUDE_ONLY -- 1.6.0.1
participants (1)
-
Roland Levillain