* mln/core/site_set/p_graph_piter.hh
(mln::p_graph_fwd_piter<P>)
(mln::p_graph_bkd_piter<P>):
Inherit from internal::site_set_iterator_base.
(mln::p_graph_fwd_piter<P>::super_)
(mln::p_graph_bkd_piter<P>::super_):
Adjust.
(mln::p_graph_fwd_piter<P>::dim)
(mln::p_graph_bkd_piter<P>::dim):
Remove enums.
(mln::p_graph_fwd_piter<P>::psite)
(mln::p_graph_fwd_piter<P>::point)
(mln::p_graph_fwd_piter<P>::coord)
(mln::p_graph_bkd_piter<P>::psite)
(mln::p_graph_bkd_piter<P>::point)
(mln::p_graph_bkd_piter<P>::coord):
Remove typedefs.
(mln::p_graph_fwd_piter<P>::p_graph_fwd_piter)
(mln::p_graph_bkd_piter<P>::p_graph_bkd_piter):
New default ctors.
(mln::p_graph_fwd_piter<P>::p_graph_fwd_piter(const p_graph<P>& pg))
(mln::p_graph_bkd_piter<P>::p_graph_bkd_piter(const p_graph<P>& pg)):
Ajust ctors.
(mln::p_graph_fwd_piter<P>::p_graph_fwd_piter(const self_&))
(mln::p_graph_bkd_piter<P>::p_graph_bkd_piter(const self_&))
(mln::p_graph_fwd_piter<P>::operator=(const self_&))
(mln::p_graph_bkd_piter<P>::operator=(const self_&)):
Remove.
(mln::p_graph_fwd_piter<P>::next_)
(mln::p_graph_bkd_piter<P>::next_):
Catch up with the new interface of graph_psite.
(mln::p_graph_fwd_piter<P>::is_valid)
(mln::p_graph_fwd_piter<P>::invalidate)
(mln::p_graph_fwd_piter<P>::start)
(mln::p_graph_bkd_piter<P>::is_valid)
(mln::p_graph_bkd_piter<P>::invalidate)
(mln::p_graph_bkd_piter<P>::start):
Likewise.
Rename as...
(mln::p_graph_fwd_piter<P>::is_valid_)
(mln::p_graph_fwd_piter<P>::invalidate_)
(mln::p_graph_fwd_piter<P>::start_):
(mln::p_graph_bkd_piter<P>::is_valid_)
(mln::p_graph_bkd_piter<P>::invalidate_)
(mln::p_graph_bkd_piter<P>::start_):
...these.
(mln::p_graph_fwd_piter<P>::to_point)
(mln::p_graph_fwd_piter<P>::to_psite)
(mln::p_graph_fwd_piter<P>::operator psite)
(mln::p_graph_fwd_piter<P>::operator[])
(mln::p_graph_bkd_piter<P>::to_point)
(mln::p_graph_bkd_piter<P>::to_psite)
(mln::p_graph_bkd_piter<P>::operator psite)
(mln::p_graph_bkd_piter<P>::operator[]):
Remove.
(mln::p_graph_fwd_piter<P>::pg_)
(mln::p_graph_fwd_piter<P>::id_)
(mln::p_graph_fwd_piter<P>::psite_)
(mln::p_graph_bkd_piter<P>::pg_)
(mln::p_graph_bkd_piter<P>::id_)
(mln::p_graph_bkd_piter<P>::psite_):
Remove attributes
(mln::p_graph_fwd_piter<P>::p_)
(mln::p_graph_bkd_piter<P>::p_):
Remove.
Use the one from the super class.
---
milena/ChangeLog | 71 ++++++
milena/mln/core/site_set/p_graph_piter.hh | 349 +++++------------------------
2 files changed, 127 insertions(+), 293 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 323a1fe..ee2ec1b 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,76 @@
2008-09-22 Roland Levillain <roland(a)lrde.epita.fr>
+ Update iterators on mln::p_graph.
+
+ * mln/core/site_set/p_graph_piter.hh
+ (mln::p_graph_fwd_piter<P>)
+ (mln::p_graph_bkd_piter<P>):
+ Inherit from internal::site_set_iterator_base.
+ (mln::p_graph_fwd_piter<P>::super_)
+ (mln::p_graph_bkd_piter<P>::super_):
+ Adjust.
+ (mln::p_graph_fwd_piter<P>::dim)
+ (mln::p_graph_bkd_piter<P>::dim):
+ Remove enums.
+ (mln::p_graph_fwd_piter<P>::psite)
+ (mln::p_graph_fwd_piter<P>::point)
+ (mln::p_graph_fwd_piter<P>::coord)
+ (mln::p_graph_bkd_piter<P>::psite)
+ (mln::p_graph_bkd_piter<P>::point)
+ (mln::p_graph_bkd_piter<P>::coord):
+ Remove typedefs.
+ (mln::p_graph_fwd_piter<P>::p_graph_fwd_piter)
+ (mln::p_graph_bkd_piter<P>::p_graph_bkd_piter):
+ New default ctors.
+ (mln::p_graph_fwd_piter<P>::p_graph_fwd_piter(const p_graph<P>& pg))
+ (mln::p_graph_bkd_piter<P>::p_graph_bkd_piter(const p_graph<P>& pg)):
+ Ajust ctors.
+ (mln::p_graph_fwd_piter<P>::p_graph_fwd_piter(const self_&))
+ (mln::p_graph_bkd_piter<P>::p_graph_bkd_piter(const self_&))
+ (mln::p_graph_fwd_piter<P>::operator=(const self_&))
+ (mln::p_graph_bkd_piter<P>::operator=(const self_&)):
+ Remove.
+ (mln::p_graph_fwd_piter<P>::next_)
+ (mln::p_graph_bkd_piter<P>::next_):
+ Catch up with the new interface of graph_psite.
+ (mln::p_graph_fwd_piter<P>::is_valid)
+ (mln::p_graph_fwd_piter<P>::invalidate)
+ (mln::p_graph_fwd_piter<P>::start)
+ (mln::p_graph_bkd_piter<P>::is_valid)
+ (mln::p_graph_bkd_piter<P>::invalidate)
+ (mln::p_graph_bkd_piter<P>::start):
+ Likewise.
+ Rename as...
+ (mln::p_graph_fwd_piter<P>::is_valid_)
+ (mln::p_graph_fwd_piter<P>::invalidate_)
+ (mln::p_graph_fwd_piter<P>::start_):
+ (mln::p_graph_bkd_piter<P>::is_valid_)
+ (mln::p_graph_bkd_piter<P>::invalidate_)
+ (mln::p_graph_bkd_piter<P>::start_):
+ ...these.
+ (mln::p_graph_fwd_piter<P>::to_point)
+ (mln::p_graph_fwd_piter<P>::to_psite)
+ (mln::p_graph_fwd_piter<P>::operator psite)
+ (mln::p_graph_fwd_piter<P>::operator[])
+ (mln::p_graph_bkd_piter<P>::to_point)
+ (mln::p_graph_bkd_piter<P>::to_psite)
+ (mln::p_graph_bkd_piter<P>::operator psite)
+ (mln::p_graph_bkd_piter<P>::operator[]):
+ Remove.
+ (mln::p_graph_fwd_piter<P>::pg_)
+ (mln::p_graph_fwd_piter<P>::id_)
+ (mln::p_graph_fwd_piter<P>::psite_)
+ (mln::p_graph_bkd_piter<P>::pg_)
+ (mln::p_graph_bkd_piter<P>::id_)
+ (mln::p_graph_bkd_piter<P>::psite_):
+ Remove attributes
+ (mln::p_graph_fwd_piter<P>::p_)
+ (mln::p_graph_bkd_piter<P>::p_):
+ Remove.
+ Use the one from the super class.
+
+2008-09-22 Roland Levillain <roland(a)lrde.epita.fr>
+
Update site of mln::p_graph.
* mln/core/image/graph_psite.hh (mln::graph_psite<P>): Inherit
diff --git a/milena/mln/core/site_set/p_graph_piter.hh
b/milena/mln/core/site_set/p_graph_piter.hh
index 56419d9..7ef1859 100644
--- a/milena/mln/core/site_set/p_graph_piter.hh
+++ b/milena/mln/core/site_set/p_graph_piter.hh
@@ -28,12 +28,16 @@
#ifndef MLN_CORE_SITE_SET_P_GRAPH_PITER_HH
# define MLN_CORE_SITE_SET_P_GRAPH_PITER_HH
-# include <mln/core/internal/site_iterator_base.hh>
+/// \file mln/core/site_set/p_graph_piter.hh
+/// \brief Definition of point iterator on graph-based point set.
+
+# include <mln/core/internal/site_set_iterator_base.hh>
# include <mln/core/site_set/p_graph.hh>
# include <mln/core/image/graph_psite.hh>
-/// \file mln/core/site_set/p_graph_piter.hh
-/// \brief Definition of point iterator on graph-based point set.
+/* FIXME: Iterators on p_graph and p_line_graph share common code.
+ Factor as much as possible. */
+
namespace mln
{
@@ -41,6 +45,7 @@ namespace mln
template <typename P> class p_graph;
template <typename P> class graph_psite;
+
/*------------------------.
| p_graph_fwd_piter_<P>. |
`------------------------*/
@@ -48,69 +53,39 @@ namespace mln
/// \brief Forward iterator on point sites of a mln::p_graph<P>.
template <typename P>
class p_graph_fwd_piter_
- : public internal::site_iterator_base< P, p_graph_fwd_piter_<P> >
+ : public internal::site_set_iterator_base< p_graph<P>,
+ p_graph_fwd_piter_<P> >
{
typedef p_graph_fwd_piter_<P> self_;
- typedef internal::site_iterator_base< P, self_ > super_;
+ typedef internal::site_set_iterator_base< p_graph<P>, self_ > super_;
public:
- // Make definitions from super class available.
- enum { dim = super_::dim };
-
- typedef graph_psite<P> psite;
- typedef P point;
- typedef mln_coord(point) coord;
-
/// Construction and assignment.
/// \{
+ p_graph_fwd_piter_();
p_graph_fwd_piter_(const p_graph<P>& pg);
- p_graph_fwd_piter_(const self_& rhs);
- self_& operator= (const self_& rhs);
/// \}
/// Manipulation.
/// \{
/// 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.
- void update_();
- /// \}
-
- /// Conversion and accessors.
- /// \{
- /// Reference to the corresponding point.
- const point& to_point () const;
- /// Reference to the corresponding point site.
- const psite& to_psite () const;
- /// Convert the iterator into a graph psite.
- operator psite() const;
-
- /// Read-only access to the \p i-th coordinate.
- mln_coord(P) operator[](unsigned i) const;
/// \}
private:
- /// The p_graph this point site belongs to.
- const p_graph<P>* pg_;
- /// The id of the vertex this psite is pointing towards.
- unsigned id_;
/// The psite corresponding to this iterator.
- psite psite_;
- /// The point corresponding to this iterator.
- point p_;
+ using super_::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_graph_fwd_piter_<P>.
template <typename P>
inline
std::ostream&
@@ -124,76 +99,46 @@ namespace mln
/// \brief Backward iterator on point sites of a mln::p_graph<P>.
template <typename P>
class p_graph_bkd_piter_
- : public internal::site_iterator_base< P, p_graph_bkd_piter_<P> >
+ : public internal::site_set_iterator_base< p_graph<P>,
+ p_graph_bkd_piter_<P> >
{
typedef p_graph_bkd_piter_<P> self_;
- typedef internal::site_iterator_base< P, self_ > super_;
+ typedef internal::site_set_iterator_base< p_graph<P>, self_ > super_;
public:
- // Make definitions from super class available.
- enum { dim = super_::dim };
-
- typedef graph_psite<P> psite;
- typedef P point;
- typedef mln_coord(point) coord;
-
/// Construction and assignment.
/// \{
+ p_graph_bkd_piter_();
p_graph_bkd_piter_(const p_graph<P>& pg);
- p_graph_bkd_piter_(const self_& rhs);
- self_& operator= (const self_& rhs);
/// \}
/// Manipulation.
/// \{
/// 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.
- void update_();
- /// \}
-
- /// Conversion and accessors.
- /// \{
- /// Reference to the corresponding point.
- const point& to_point () const;
- /// Reference to the corresponding point site.
- const psite& to_psite () const;
- /// Convert the iterator into a graph psite.
- operator psite() const;
-
- /// Read-only access to the \p i-th coordinate.
- coord operator[](unsigned i) const;
/// \}
private:
- /// The p_graph this point site belongs to.
- const p_graph<P>* pg_;
- /// The id of the vertex this psite is pointing towards.
- unsigned id_;
/// The psite corresponding to this iterator.
- psite psite_;
- /// The point corresponding to this iterator.
- point p_;
+ using super_::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_graph_bkd_piter_<P>.
template <typename P>
inline
std::ostream&
operator<<(std::ostream& ostr, const p_graph_bkd_piter_<P>& p);
+
# ifndef MLN_INCLUDE_ONLY
/*------------------------.
@@ -202,71 +147,41 @@ namespace mln
template <typename P>
inline
- p_graph_fwd_piter_<P>::p_graph_fwd_piter_(const p_graph<P>& pg)
- : pg_(&pg),
- // Initialize psite_ to a dummy value.
- psite_(pg, -1)
- {
- // Invalidate id_.
- invalidate();
- }
-
- template <typename P>
- inline
- p_graph_fwd_piter_<P>::p_graph_fwd_piter_(const p_graph_fwd_piter_<P>&
rhs)
- : pg_(rhs.pg_),
- id_(rhs.id_),
- psite_(rhs.psite_),
- p_(rhs.p_)
- {
- }
-
- template <typename P>
- inline
- p_graph_fwd_piter_<P>&
- p_graph_fwd_piter_<P>::operator=(const p_graph_fwd_piter_<P>& rhs)
+ p_graph_fwd_piter_<P>::p_graph_fwd_piter_()
{
- if (&rhs == this)
- return *this;
- pg_ = rhs.pg_;
- id_ = rhs.id_;
- psite_ = rhs.psite_;
- p_ = rhs.p_;
- return *this;
+ mln_postcondition(!this->is_valid());
}
template <typename P>
inline
- mln_coord(P)
- p_graph_fwd_piter_<P>::operator[](unsigned i) const
+ p_graph_fwd_piter_<P>::p_graph_fwd_piter_(const p_graph<P>& pg)
{
- return p_[i];
+ this->change_target(pg);
+ mln_postcondition(!this->is_valid());
}
template <typename P>
inline
bool
- p_graph_fwd_piter_<P>::is_valid() const
+ p_graph_fwd_piter_<P>::is_valid_() const
{
- return pg_ && id_ < pg_->nvertices();
+ return p_.is_valid();
}
template <typename P>
inline
void
- p_graph_fwd_piter_<P>::invalidate()
+ p_graph_fwd_piter_<P>::invalidate_()
{
- id_ = -1;
+ p_.invalidate();
}
template <typename P>
inline
void
- p_graph_fwd_piter_<P>::start()
+ p_graph_fwd_piter_<P>::start_()
{
- id_ = 0;
- if (is_valid())
- update_();
+ p_.change_vertex_id(0);
}
template <typename P>
@@ -274,66 +189,7 @@ namespace mln
void
p_graph_fwd_piter_<P>::next_()
{
- ++id_;
- if (is_valid())
- update_();
- }
-
- template <typename P>
- inline
- void
- p_graph_fwd_piter_<P>::update_()
- {
- // Update psite_.
- psite_ = graph_psite<P>(*pg_, id_);
- // Update p_.
- p_ = pg_->point_from_id(id_);
- }
-
- template <typename P>
- inline
- const P&
- p_graph_fwd_piter_<P>::to_point() 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 p_;
- }
-
- template <typename P>
- inline
- const graph_psite<P>&
- p_graph_fwd_piter_<P>::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 P>
- inline
- p_graph_fwd_piter_<P>::operator graph_psite<P>() const
- {
- mln_precondition(is_valid());
- return psite_;
+ p_.inc_vertex_id();
}
@@ -342,9 +198,7 @@ namespace mln
std::ostream&
operator<<(std::ostream& ostr, const p_graph_fwd_piter_<P>& p)
{
- // FIXME: We should use p.to_psite() here, but as it lacks the
- // precondition the conversion operator has, we use the latter.
- return ostr << static_cast< graph_psite<P> >(p);
+ return ostr << p.unproxy_();
}
@@ -354,71 +208,41 @@ namespace mln
template <typename P>
inline
- p_graph_bkd_piter_<P>::p_graph_bkd_piter_(const p_graph<P>& pg)
- : pg_(&pg),
- // Initialize psite_ to a dummy value.
- psite_(pg, -1)
- {
- // Invalidate id_.
- invalidate();
- }
-
- template <typename P>
- inline
- p_graph_bkd_piter_<P>::p_graph_bkd_piter_(const p_graph_bkd_piter_<P>&
rhs)
- : pg_(rhs.pg_),
- id_(rhs.id_),
- psite_(rhs.psite_),
- p_(rhs.p_)
- {
- }
-
- template <typename P>
- inline
- p_graph_bkd_piter_<P>&
- p_graph_bkd_piter_<P>::operator=(const p_graph_bkd_piter_<P>& rhs)
+ p_graph_bkd_piter_<P>::p_graph_bkd_piter_()
{
- if (&rhs == this)
- return *this;
- pg_ = rhs.pg_;
- id_ = rhs.id_;
- psite_ = rhs.psite_;
- p_ = rhs.p_;
- return *this;
+ mln_postcondition(!this->is_valid());
}
template <typename P>
inline
- mln_coord(P)
- p_graph_bkd_piter_<P>::operator[](unsigned i) const
+ p_graph_bkd_piter_<P>::p_graph_bkd_piter_(const p_graph<P>& pg)
{
- return p_[i];
+ this->change_target(pg);
+ mln_postcondition(!this->is_valid());
}
template <typename P>
inline
bool
- p_graph_bkd_piter_<P>::is_valid() const
+ p_graph_bkd_piter_<P>::is_valid_() const
{
- return pg_ && id_ < pg_->nvertices();
+ return p_.is_valid();
}
template <typename P>
inline
void
- p_graph_bkd_piter_<P>::invalidate()
+ p_graph_bkd_piter_<P>::invalidate_()
{
- id_ = -1;
+ p_.invalidate();
}
template <typename P>
inline
void
- p_graph_bkd_piter_<P>::start()
+ p_graph_bkd_piter_<P>::start_()
{
- id_ = pg_->nvertices() - 1;
- if (is_valid())
- update_();
+ p_.change_vertex_id(this->site_set().nvertices() - 1);
}
template <typename P>
@@ -426,66 +250,7 @@ namespace mln
void
p_graph_bkd_piter_<P>::next_()
{
- --id_;
- if (is_valid())
- update_();
- }
-
- template <typename P>
- inline
- void
- p_graph_bkd_piter_<P>::update_()
- {
- // Update psite_.
- psite_ = graph_psite<P>(*pg_, id_);
- // Update p_.
- p_ = pg_->point_from_id(id_);
- }
-
- template <typename P>
- inline
- const P&
- p_graph_bkd_piter_<P>::to_point() 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 p_;
- }
-
- template <typename P>
- inline
- const graph_psite<P>&
- p_graph_bkd_piter_<P>::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 P>
- inline
- p_graph_bkd_piter_<P>::operator graph_psite<P>() const
- {
- mln_precondition(is_valid());
- return psite_;
+ p_.dec_vertex_id();
}
@@ -494,9 +259,7 @@ namespace mln
std::ostream&
operator<<(std::ostream& ostr, const p_graph_bkd_piter_<P>& p)
{
- // FIXME: We should use p.to_psite() here, but as it lacks the
- // precondition the conversion operator has, we use the latter.
- return ostr << static_cast< graph_psite<P> >(p);
+ return ostr << p.unproxy_();
}
# endif // ! MLN_INCLUDE_ONLY
--
1.5.6.5