
* mln/core/p_complex_piter.hh (mln::p_complex_fwd_piter_<D, P>::iter) (mln::p_complex_bkd_piter_<D, P>::iter): New typedef. (mln::p_complex_fwd_piter_<D, P>::face_) (mln::p_complex_bkd_piter_<D, P>::face_): Remove member. (mln::p_complex_fwd_piter_<D, P>::iter_) (mln::p_complex_bkd_piter_<D, P>::iter_): New member. (mln::p_complex_fwd_piter_<D, P>::p_complex_fwd_piter_) (mln::p_complex_bkd_piter_<D, P>::p_complex_bkd_piter_): Adjust ctors. (mln::p_complex_fwd_piter_<D, P>::is_valid) (mln::p_complex_fwd_piter_<D, P>::invalidate) (mln::p_complex_fwd_piter_<D, P>::start) (mln::p_complex_fwd_piter_<D, P>::next) (mln::p_complex_fwd_piter_<D, P>::update): Adjust. (mln::p_complex_fwd_piter_<D, P>::invalid_unsigned_) (mln::p_complex_bkd_piter_<D, P>::invalid_unsigned_): Remove, useless. --- milena/ChangeLog | 27 ++++++ milena/mln/core/p_complex_piter.hh | 157 ++++++++---------------------------- 2 files changed, 61 insertions(+), 123 deletions(-) diff --git a/milena/ChangeLog b/milena/ChangeLog index b40e272..cd60428 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,32 @@ 2008-09-11 Roland Levillain <roland@lrde.epita.fr> + Factor iterators on p_complexes with iterator on complexes. + + * mln/core/p_complex_piter.hh + (mln::p_complex_fwd_piter_<D, P>::iter) + (mln::p_complex_bkd_piter_<D, P>::iter): + New typedef. + (mln::p_complex_fwd_piter_<D, P>::face_) + (mln::p_complex_bkd_piter_<D, P>::face_): + Remove member. + (mln::p_complex_fwd_piter_<D, P>::iter_) + (mln::p_complex_bkd_piter_<D, P>::iter_): + New member. + (mln::p_complex_fwd_piter_<D, P>::p_complex_fwd_piter_) + (mln::p_complex_bkd_piter_<D, P>::p_complex_bkd_piter_): + Adjust ctors. + (mln::p_complex_fwd_piter_<D, P>::is_valid) + (mln::p_complex_fwd_piter_<D, P>::invalidate) + (mln::p_complex_fwd_piter_<D, P>::start) + (mln::p_complex_fwd_piter_<D, P>::next) + (mln::p_complex_fwd_piter_<D, P>::update): + Adjust. + (mln::p_complex_fwd_piter_<D, P>::invalid_unsigned_) + (mln::p_complex_bkd_piter_<D, P>::invalid_unsigned_): + Remove, useless. + +2008-09-11 Roland Levillain <roland@lrde.epita.fr> + Add default constructors to complexes on iterators. * mln/core/complex_iter.hh diff --git a/milena/mln/core/p_complex_piter.hh b/milena/mln/core/p_complex_piter.hh index 98efc11..d9ce17a 100644 --- a/milena/mln/core/p_complex_piter.hh +++ b/milena/mln/core/p_complex_piter.hh @@ -21,7 +21,7 @@ // file, or you compile this file and link it with other files to // produce an executable, this file does not by itself cause the // resulting executable to be covered by the GNU General Public -// License. +// License. // reasons why the executable file might be covered by the GNU General // Public License. @@ -36,6 +36,7 @@ # include <mln/core/internal/point_iterator_base.hh> # include <mln/core/p_complex.hh> # include <mln/core/complex_psite.hh> +# include <mln/core/complex_iter.hh> // Factor p_complex_fwd_piter_<D, P> and p_complex_bkd_piter_<D, P>. @@ -60,6 +61,9 @@ namespace mln typedef p_complex_fwd_piter_<D, P> self_; typedef internal::point_iterator_base_< P, self_ > super_; + /// The type of the underlying complex iterator. + typedef complex_fwd_iter_<D> iter; + public: // Make definitions from super class available. // FIXME: Is it still meaningful for a complex? @@ -107,27 +111,13 @@ namespace mln /// \} private: - /// The face handle this iterator is pointing to. - any_face_handle<D> face_; + /// 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_; - - /// \brief An invalid value for both the dimension and the id of - /// the face. - /// - /// Use a function instead of a static constant, since `static' - /// variables needs to be compiled once, which requires a compiled - /// library to avoid duplicate symbols, which is something that - /// was not really planned in Milena. A function tagged `inlined' - /// can appear multiple times in a program, and solves this - /// problem. We rely on the compiler to inline this call. - /// - /// Of course, we could have used UINT_MAX, but it is not very - /// C++. - unsigned invalid_unsigned_() const; }; @@ -153,6 +143,9 @@ namespace mln typedef p_complex_bkd_piter_<D, P> self_; typedef internal::point_iterator_base_< P, self_ > super_; + /// The type of the underlying complex iterator. + typedef complex_bkd_iter_<D> iter; + public: // Make definitions from super class available. // FIXME: Is it still meaningful for a complex? @@ -200,27 +193,13 @@ namespace mln /// \} private: - /// The face handle this iterator is pointing to. - any_face_handle<D> face_; + /// 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_; - - /// \brief An invalid value for both the dimension and the id of - /// the face. - /// - /// Use a function instead of a static constant, since `static' - /// variables needs to be compiled once, which requires a compiled - /// library to avoid duplicate symbols, which is something that - /// was not really planned in Milena. A function tagged `inlined' - /// can appear multiple times in a program, and solves this - /// problem. We rely on the compiler to inline this call. - /// - /// Of course, we could have used UINT_MAX, but it is not very - /// C++. - unsigned invalid_unsigned_() const; }; @@ -248,15 +227,14 @@ namespace mln : psite_(), p_() { - face_.set_cplx(pc.cplx()); - // Invalidate face_. - invalidate(); + iter_.set_cplx(pc.cplx()); + mln_postcondition(!is_valid()); } template <unsigned D, typename P> inline p_complex_fwd_piter_<D, P>::p_complex_fwd_piter_(const p_complex_fwd_piter_<D, P>& rhs) - : face_(rhs.face_), + : iter_(rhs.iter_), psite_(rhs.psite_), // Dummy value. p_() @@ -270,7 +248,7 @@ namespace mln { if (&rhs == this) return *this; - face_ = rhs.face_; + iter_ = rhs.iter_; psite_ = rhs.psite_; return *this; } @@ -289,7 +267,7 @@ namespace mln bool p_complex_fwd_piter_<D, P>::is_valid() const { - return face_.is_valid(); + return iter_.is_valid(); } template <unsigned D, typename P> @@ -297,50 +275,24 @@ namespace mln void p_complex_fwd_piter_<D, P>::invalidate() { - face_.set_n(invalid_unsigned_()); - face_.set_face_id(invalid_unsigned_()); + iter_.invalidate(); } template <unsigned D, typename P> inline - void + void p_complex_fwd_piter_<D, P>::start() { - face_.set_n(0u); - face_.set_face_id(0u); + iter_.start(); update_(); } template <unsigned D, typename P> inline - void + void p_complex_fwd_piter_<D, P>::next_() { - if (is_valid()) - { - unsigned n = face_.n(); - unsigned face_id = face_.face_id(); - - if (face_id + 1 < face_.cplx().nfaces(n)) - /* FIXME: Provide accessor any_face_handle::n() returning - a mutable reference? This way, we could just write - - ++face_.face_id(); - - instead of the following. */ - face_.set_face_id(face_id + 1); - else - // Start to iterate on the faces of the next dimension if - // possible. - if (n <= D) - { - // FIXME: Same remark as above. - face_.set_n(n + 1); - face_.set_face_id(0u); - } - else - invalidate(); - } + iter_.next_(); if (is_valid()) update_(); } @@ -351,7 +303,7 @@ namespace mln p_complex_fwd_piter_<D, P>::update_() { // Update psite_. - psite_ = complex_psite<D, P>(face_); + psite_ = complex_psite<D, P>(iter_); } template <unsigned D, typename P> @@ -390,13 +342,6 @@ namespace mln return psite_; } - template <unsigned D, typename P> - unsigned - p_complex_fwd_piter_<D, P>::invalid_unsigned_() const - { - return std::numeric_limits<unsigned>::max(); - } - template <unsigned D, typename P> inline @@ -431,15 +376,14 @@ namespace mln : psite_(), p_() { - face_.set_cplx(pc.cplx()); - // Invalidate face_. - invalidate(); + iter_.set_cplx(pc.cplx()); + mln_postcondition(!is_valid()); } template <unsigned D, typename P> inline p_complex_bkd_piter_<D, P>::p_complex_bkd_piter_(const p_complex_bkd_piter_<D, P>& rhs) - : face_(rhs.face_), + : iter_(rhs.iter_), psite_(rhs.psite_), // Dummy value. p_() @@ -453,7 +397,7 @@ namespace mln { if (&rhs == this) return *this; - face_ = rhs.face_; + iter_ = rhs.iter_; psite_ = rhs.psite_; return *this; } @@ -472,7 +416,7 @@ namespace mln bool p_complex_bkd_piter_<D, P>::is_valid() const { - return face_.is_valid(); + return iter_.is_valid(); } template <unsigned D, typename P> @@ -480,50 +424,24 @@ namespace mln void p_complex_bkd_piter_<D, P>::invalidate() { - face_.set_n(invalid_unsigned_()); - face_.set_face_id(invalid_unsigned_()); + iter_.invalidate(); } template <unsigned D, typename P> inline - void + void p_complex_bkd_piter_<D, P>::start() { - face_.set_n(D); - face_.set_face_id(face_.cplx().template nfaces<D>() - 1); + iter_.start(); update_(); } template <unsigned D, typename P> inline - void + void p_complex_bkd_piter_<D, P>::next_() { - if (is_valid()) - { - unsigned n = face_.n(); - unsigned face_id = face_.face_id(); - - if (face_id > 0) - /* FIXME: Provide accessor any_face_handle::n() returning - a mutable reference? This way, we could just write - - ++face_.face_id(); - - instead of the following. */ - face_.set_face_id(face_id - 1); - else - // Start to iterate on the faces of the previous dimension - // if it exists. - if (n > 0) - { - // FIXME: Same remark as above. - face_.set_n(n - 1); - face_.set_face_id(face_.cplx().nfaces(n - 1) - 1); - } - else - invalidate(); - } + iter_.next_(); if (is_valid()) update_(); } @@ -534,7 +452,7 @@ namespace mln p_complex_bkd_piter_<D, P>::update_() { // Update psite_. - psite_ = complex_psite<D, P>(face_); + psite_ = complex_psite<D, P>(iter_); } template <unsigned D, typename P> @@ -573,13 +491,6 @@ namespace mln return psite_; } - template <unsigned D, typename P> - unsigned - p_complex_bkd_piter_<D, P>::invalid_unsigned_() const - { - return std::numeric_limits<unsigned>::max(); - } - template <unsigned D, typename P> inline -- 1.5.6.5