https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Factor iterators on p_graph neighborhoods and windows.
* mln/core/internal/graph_vicinity_piter.hh: New file.
Use it to factor...
* mln/core/graph_neighborhood_piter.hh,
* mln/core/graph_window_piter.hh
(mln::graph_neighborhood_fwd_piter<P, N>)
(mln::graph_neighborhood_bkd_piter<P, N>)
(mln::graph_window_fwd_piter<P, W>)
(mln::graph_window_bkd_piter<P, W>):
...these iterators.
(mln::internal::graph_neighborhood_piter_<P, N, E>)
(mln::internal::graph_window_piter_<P, W, E>):
New classes.
graph_neighborhood_piter.hh | 346 ++++++++-------------------------------
graph_window_piter.hh | 341 +++++++-------------------------------
internal/graph_vicinity_piter.hh | 232 ++++++++++++++++++++++++++
3 files changed, 375 insertions(+), 544 deletions(-)
Index: mln/core/internal/graph_vicinity_piter.hh
--- mln/core/internal/graph_vicinity_piter.hh (revision 0)
+++ mln/core/internal/graph_vicinity_piter.hh (revision 0)
@@ -0,0 +1,232 @@
+// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// 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. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_CORE_INTERNAL_GRAPH_VICINITY_PITER_HH
+# define MLN_CORE_INTERNAL_GRAPH_VICINITY_PITER_HH
+
+/// \file mln/core/internal/graph_vicinity_piter.hh
+/// \brief Factored implementation for point iterators on a graph windows
+/// and graph neighborhoods, called "vicinities".
+
+# include <mln/core/concept/point_iterator.hh>
+# include <mln/core/p_graph.hh>
+# include <mln/core/graph_psite.hh>
+
+/* FIXME: Due to the poor interface of mln::p_graph and
+ mln::util::graph, we show to much implementation details here.
+ Enrich their interfaces to avoid that. */
+
+namespace mln
+{
+ // Fwd decls.
+ template <typename P> class p_graph;
+ template <typename P> class graph_psite;
+
+
+ /*----------------------------------------.
+ | internal::graph_vicinity_piter_<P, E>. |
+ `----------------------------------------*/
+
+ namespace internal
+ {
+
+ /// \brief Base for iterator on a graph vicinity.
+ template <typename P, typename E>
+ class graph_vicinity_piter_ : public Point_Iterator< E >
+ {
+ typedef graph_vicinity_piter_<P, E> self_;
+ typedef Point_Iterator< self_ > super_;
+
+ public:
+ enum { dim = P::dim };
+
+ typedef graph_psite<P> psite;
+ typedef P point;
+ typedef mln_coord(P) coord;
+ // FIXME: Dummy typedef.
+ typedef void dpoint;
+ // FIXME: Dummy value.
+ typedef void mesh;
+
+ public:
+ /// Construction.
+ /// \{
+ template <typename Pref>
+ graph_vicinity_piter_(const Point_Site<Pref>& p_ref);
+ /// \}
+
+ /// Manipulation.
+ /// \{
+ /// Test if the iterator is valid.
+ bool is_valid() const;
+ /// Invalidate the iterator.
+ void invalidate();
+
+ /// Is the piter adjacent to the reference point?
+ bool adjacent_to_p_ref_() const;
+ /// Is the piter adjacent or equal to the reference point?
+ bool adjacent_or_equal_to_p_ref_() const;
+ /// 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 line graph psite.
+ operator psite() const;
+
+ /// Read-only access to the \a i-th coordinate.
+ coord operator[](unsigned i) const;
+ /// \}
+
+ /// Internals, used by the vicinity.
+ /// \{
+ public:
+ /// An internal iterator on the set of nodes of the underlying graph.
+ util::node_id id_;
+ /// \}
+
+ protected:
+ /// The ``central'' psite of the vicinity (for instance, the
+ /// center of the neighborhood, in the case of a neighborhood
+ /// piter).
+ const psite& p_ref_;
+
+ private:
+ /// The psite corresponding to this iterator.
+ psite psite_;
+ /// The point corresponding to this iterator.
+ point p_;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename P, typename E>
+ template <typename Pref>
+ inline
+ graph_vicinity_piter_<P, E>::graph_vicinity_piter_(const
Point_Site<Pref>& p_ref)
+ : p_ref_(exact(p_ref).to_psite()),
+ // Initialize psite_ to a dummy value.
+ psite_(),
+ p_()
+ {
+ // Invalidate id_.
+ invalidate();
+ }
+
+ template <typename P, typename E>
+ inline
+ bool
+ graph_vicinity_piter_<P, E>::is_valid() const
+ {
+ /* FIXME: We depend too much on the implementation of
+ util::graph here. The util::graph should provide the service
+ to abstract these manipulations. */
+ return p_ref_.is_valid() && id_ < p_ref_.pg().npoints();
+ }
+
+ template <typename P, typename E>
+ inline
+ void
+ graph_vicinity_piter_<P, E>::invalidate()
+ {
+ id_ = -1;
+ }
+
+ template <typename P, typename E>
+ inline
+ bool
+ graph_vicinity_piter_<P, E>::adjacent_to_p_ref_() const
+ {
+ return p_ref_.pg().adjacent(p_ref_.id(), id_);
+ }
+
+ template <typename P, typename E>
+ inline
+ bool
+ graph_vicinity_piter_<P, E>::adjacent_or_equal_to_p_ref_() const
+ {
+ return p_ref_.pg().adjacent_or_equal(p_ref_.id(), id_);
+ }
+
+ template <typename P, typename E>
+ inline
+ void
+ graph_vicinity_piter_<P, E>::update_()
+ {
+ // Update psite_.
+ psite_ = graph_psite<P>(p_ref_.pg(), id_);
+ // Update p_.
+ p_ = p_ref_.pg().point_from_id(id_);
+ }
+
+ template <typename P, typename E>
+ inline
+ const P&
+ graph_vicinity_piter_<P, E>::to_point() const
+ {
+ return p_;
+ }
+
+ template <typename P, typename E>
+ inline
+ const graph_psite<P>&
+ graph_vicinity_piter_<P, E>::to_psite() const
+ {
+ return psite_;
+ }
+
+ template <typename P, typename E>
+ inline
+ graph_vicinity_piter_<P, E>::operator graph_psite<P>() const
+ {
+ mln_precondition(is_valid());
+ return psite_;
+ }
+
+ template <typename P, typename E>
+ inline
+ mln_coord(P)
+ graph_vicinity_piter_<P, E>::operator[](unsigned i) const
+ {
+ assert(i < dim);
+ return p_[i];
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::internal
+
+} // end of namespace mln
+
+#endif // ! MLN_CORE_INTERNAL_GRAPH_VICINITY_PITER_HH
Index: mln/core/graph_neighborhood_piter.hh
--- mln/core/graph_neighborhood_piter.hh (revision 1891)
+++ mln/core/graph_neighborhood_piter.hh (working copy)
@@ -42,9 +42,7 @@
- mln::line_graph_window_bkd_piter
- mln::line_graph_neighborhood_bkd_piter. */
-# include <mln/core/concept/point_iterator.hh>
-# include <mln/core/p_graph.hh>
-# include <mln/core/graph_psite.hh>
+# include <mln/core/internal/graph_vicinity_piter.hh>
/* FIXME: Due to the poor interface of mln::p_graph and
mln::util::graph, we show to much implementation details here.
@@ -52,9 +50,35 @@
namespace mln
{
- // Fwd decls.
- template <typename P> class p_graph;
- template <typename P> class graph_psite;
+
+ /*-----------------------------------------------.
+ | internal::graph_neighborhood_piter_<P, N, E>. |
+ `-----------------------------------------------*/
+
+ namespace internal
+ {
+
+ /// \brief Base for iterator on a graph neighborhood.
+ template <typename P, typename N, typename E>
+ class graph_neighborhood_piter_ : public graph_vicinity_piter_<P, E>
+ {
+ typedef graph_neighborhood_piter_<P, N, E> self_;
+ typedef graph_vicinity_piter_<P, E> super_;
+
+ public:
+ /// Construction.
+ /// \{
+ template <typename Pref>
+ graph_neighborhood_piter_(const Neighborhood<N>& nbh,
+ const Point_Site<Pref>& p_ref);
+ /// \}
+
+ protected:
+ /// The neighborhood.
+ const N& nbh_;
+ };
+
+ } // end of namespace mln::internal
/*-------------------------------------.
@@ -63,21 +87,11 @@
template <typename P, typename N>
class graph_neighborhood_fwd_piter :
- public Point_Iterator< graph_neighborhood_fwd_piter<P, N> >
+ public internal::graph_neighborhood_piter_< P, N,
+ graph_neighborhood_fwd_piter<P, N> >
{
typedef graph_neighborhood_fwd_piter<P, N> self_;
- typedef Point_Iterator< self_ > super_;
-
- public:
- enum { dim = P::dim };
-
- typedef graph_psite<P> psite;
- typedef P point;
- typedef mln_coord(P) coord;
- // FIXME: Dummy typedef.
- typedef void dpoint;
- // FIXME: Dummy value.
- typedef void mesh;
+ typedef internal::graph_neighborhood_piter_<P, N, self_> super_;
public:
/// Construction.
@@ -89,53 +103,19 @@
/// Manipulation.
/// \{
- /// Test if the iterator is valid.
- bool is_valid() const;
- /// Invalidate the iterator.
- void invalidate();
/// Start an iteration.
void start();
-
/// Go to the next point.
void next_();
- /// Is the piter adjacent to the reference point?
- bool adjacent_to_p_ref_() const;
- /// 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 line graph psite.
- operator psite() const;
-
- /// Read-only access to the \a i-th coordinate.
- coord operator[](unsigned i) const;
-
/// Internals, used by the neighborhood.
/// \{
- public:
/// Set the iterator to the first site of the graph.
void first_();
/// Advance the position of the iterator by one step.
void step_();
-
- /// An internal iterator on the set of nodes of the underlying graph.
- util::node_id id_;
/// \}
-
- private:
- /// The neighborhood.
- const N& nbh_;
- /// The ``central'' psite of the neighborhood.
- const psite& p_ref_;
- /// The psite corresponding to this iterator.
- psite psite_;
- /// The point corresponding to this iterator.
- point p_;
};
@@ -145,21 +125,11 @@
template <typename P, typename N>
class graph_neighborhood_bkd_piter :
- public Point_Iterator< graph_neighborhood_bkd_piter<P, N> >
+ public internal::graph_neighborhood_piter_< P, N,
+ graph_neighborhood_bkd_piter<P, N> >
{
typedef graph_neighborhood_bkd_piter<P, N> self_;
- typedef Point_Iterator< self_ > super_;
-
- public:
- enum { dim = P::dim };
-
- typedef graph_psite<P> psite;
- typedef P point;
- typedef mln_coord(P) coord;
- // FIXME: Dummy typedef.
- typedef void dpoint;
- // FIXME: Dummy value.
- typedef void mesh;
+ typedef internal::graph_neighborhood_piter_<P, N, self_> super_;
public:
/// Construction.
@@ -171,95 +141,56 @@
/// Manipulation.
/// \{
- /// Test if the iterator is valid.
- bool is_valid() const;
- /// Invalidate the iterator.
- void invalidate();
/// Start an iteration.
void start();
-
/// Go to the next point.
void next_();
- /// Is the piter adjacent to the reference point?
- bool adjacent_to_p_ref_() const;
- /// 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 line graph psite.
- operator psite() const;
-
- /// Read-only access to the \a i-th coordinate.
- coord operator[](unsigned i) const;
-
/// Internals, used by the neighborhood.
/// \{
- public:
/// Set the iterator to the first site of the graph.
void first_();
/// Advance the position of the iterator by one step.
void step_();
-
- /// An internal iterator on the set of nodes of the underlying graph.
- util::node_id id_;
/// \}
-
- private:
- /// The neighborhood.
- const N& nbh_;
- /// The ``central'' psite of the neighborhood.
- const psite& p_ref_;
- /// The psite corresponding to this iterator.
- psite psite_;
- /// The point corresponding to this iterator.
- point p_;
};
# ifndef MLN_INCLUDE_ONLY
- /*-------------------------------------.
- | graph_neighborhood_fwd_piter<P, N>. |
- `-------------------------------------*/
+ /*-----------------------------------------------.
+ | internal::graph_neighborhood_piter_<P, N, E>. |
+ `-----------------------------------------------*/
- template <typename P, typename N>
+ namespace internal
+ {
+
+ template <typename P, typename N, typename E>
template <typename Pref>
inline
- graph_neighborhood_fwd_piter<P, N>::graph_neighborhood_fwd_piter(const
Neighborhood<N>& nbh,
+ graph_neighborhood_piter_<P, N, E>::graph_neighborhood_piter_(const
Neighborhood<N>& nbh,
const Point_Site<Pref>& p_ref)
- : nbh_(exact(nbh)),
- p_ref_(exact(p_ref).to_psite()),
- // Initialize psite_ to a dummy value.
- psite_(),
- p_()
+ : super_(p_ref),
+ nbh_(exact(nbh))
{
- // Invalidate id_.
- invalidate();
}
- template <typename P, typename N>
- inline
- bool
- graph_neighborhood_fwd_piter<P, N>::is_valid() const
- {
- // FIXME: We depend too much on the implementation of util::graph
- // here. The util::graph should provide the service to abstract
- // these manipulations.
- return p_ref_.is_valid() && id_ < p_ref_.pg().gr_->nnodes();
- }
+ } // end of namespace mln::internal
+
+
+ /*-------------------------------------.
+ | graph_neighborhood_fwd_piter<P, N>. |
+ `-------------------------------------*/
template <typename P, typename N>
+ template <typename Pref>
inline
- void
- graph_neighborhood_fwd_piter<P, N>::invalidate()
+ graph_neighborhood_fwd_piter<P, N>::graph_neighborhood_fwd_piter(const
Neighborhood<N>& nbh,
+ const Point_Site<Pref>& p_ref)
+ : super_(nbh, p_ref)
{
- id_ = -1;
}
template <typename P, typename N>
@@ -267,9 +198,9 @@
void
graph_neighborhood_fwd_piter<P, N>::start()
{
- nbh_.start(*this);
- if (is_valid())
- update_();
+ this->nbh_.start(*this);
+ if (this->is_valid())
+ this->update_();
}
template <typename P, typename N>
@@ -277,9 +208,9 @@
void
graph_neighborhood_fwd_piter<P, N>::next_()
{
- nbh_.next_(*this);
- if (is_valid())
- update_();
+ this->nbh_.next_(*this);
+ if (this->is_valid())
+ this->update_();
}
template <typename P, typename N>
@@ -287,7 +218,7 @@
void
graph_neighborhood_fwd_piter<P, N>::first_()
{
- id_ = 0;
+ this->id_ = 0;
}
template <typename P, typename N>
@@ -295,60 +226,7 @@
void
graph_neighborhood_fwd_piter<P, N>::step_()
{
- ++id_;
- }
-
-
- template <typename P, typename N>
- inline
- bool
- graph_neighborhood_fwd_piter<P, N>::adjacent_to_p_ref_() const
- {
- return p_ref_.pg().adjacent(p_ref_.id(), id_);
- }
-
- template <typename P, typename N>
- inline
- void
- graph_neighborhood_fwd_piter<P, N>::update_()
- {
- // Update psite_.
- psite_ = graph_psite<P>(p_ref_.pg(), id_);
- // Update p_.
- p_ = p_ref_.pg().gr_->node_data(id_);
- }
-
- template <typename P, typename N>
- inline
- const P&
- graph_neighborhood_fwd_piter<P, N>::to_point() const
- {
- return p_;
- }
-
- template <typename P, typename N>
- inline
- const graph_psite<P>&
- graph_neighborhood_fwd_piter<P, N>::to_psite() const
- {
- return psite_;
- }
-
- template <typename P, typename N>
- inline
- graph_neighborhood_fwd_piter<P, N>::operator graph_psite<P>() const
- {
- mln_precondition(is_valid());
- return psite_;
- }
-
- template <typename P, typename N>
- inline
- mln_coord(P)
- graph_neighborhood_fwd_piter<P, N>::operator[](unsigned i) const
- {
- assert(i < dim);
- return p_[i];
+ ++this->id_;
}
@@ -361,33 +239,8 @@
inline
graph_neighborhood_bkd_piter<P, N>::graph_neighborhood_bkd_piter(const
Neighborhood<N>& nbh,
const Point_Site<Pref>& p_ref)
- : nbh_(exact(nbh)),
- p_ref_(exact(p_ref).to_psite()),
- // Initialize psite_ to a dummy value.
- psite_(),
- p_()
+ : super_(nbh, p_ref)
{
- // Invalidate id_.
- invalidate();
- }
-
- template <typename P, typename N>
- inline
- bool
- graph_neighborhood_bkd_piter<P, N>::is_valid() const
- {
- // FIXME: We depend too much on the implementation of util::graph
- // here. The util::graph should provide the service to abstract
- // these manipulations.
- return p_ref_.is_valid() && id_ < p_ref_.pg().gr_->nnodes();
- }
-
- template <typename P, typename N>
- inline
- void
- graph_neighborhood_bkd_piter<P, N>::invalidate()
- {
- id_ = -1;
}
template <typename P, typename N>
@@ -395,9 +248,9 @@
void
graph_neighborhood_bkd_piter<P, N>::start()
{
- nbh_.start(*this);
- if (is_valid())
- update_();
+ this->nbh_.start(*this);
+ if (this->is_valid())
+ this->update_();
}
template <typename P, typename N>
@@ -405,9 +258,9 @@
void
graph_neighborhood_bkd_piter<P, N>::next_()
{
- nbh_.next_(*this);
- if (is_valid())
- update_();
+ this->nbh_.next_(*this);
+ if (this->is_valid())
+ this->update_();
}
template <typename P, typename N>
@@ -415,7 +268,7 @@
void
graph_neighborhood_bkd_piter<P, N>::first_()
{
- id_ = p_ref_.pg().gr_->nnodes() - 1;
+ this->id_ = this->p_ref_.pg().gr_->nnodes() - 1;
}
template <typename P, typename N>
@@ -423,60 +276,7 @@
void
graph_neighborhood_bkd_piter<P, N>::step_()
{
- --id_;
- }
-
-
- template <typename P, typename N>
- inline
- bool
- graph_neighborhood_bkd_piter<P, N>::adjacent_to_p_ref_() const
- {
- return p_ref_.pg().adjacent(p_ref_.id(), id_);
- }
-
- template <typename P, typename N>
- inline
- void
- graph_neighborhood_bkd_piter<P, N>::update_()
- {
- // Update psite_.
- psite_ = graph_psite<P>(p_ref_.pg(), id_);
- // Update p_.
- p_ = p_ref_.pg().gr_->node_data(id_);
- }
-
- template <typename P, typename N>
- inline
- const P&
- graph_neighborhood_bkd_piter<P, N>::to_point() const
- {
- return p_;
- }
-
- template <typename P, typename N>
- inline
- const graph_psite<P>&
- graph_neighborhood_bkd_piter<P, N>::to_psite() const
- {
- return psite_;
- }
-
- template <typename P, typename N>
- inline
- graph_neighborhood_bkd_piter<P, N>::operator graph_psite<P>() const
- {
- mln_precondition(is_valid());
- return psite_;
- }
-
- template <typename P, typename N>
- inline
- mln_coord(P)
- graph_neighborhood_bkd_piter<P, N>::operator[](unsigned i) const
- {
- assert(i < dim);
- return p_[i];
+ --this->id_;
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/core/graph_window_piter.hh
--- mln/core/graph_window_piter.hh (revision 1891)
+++ mln/core/graph_window_piter.hh (working copy)
@@ -42,9 +42,7 @@
- mln::line_graph_window_bkd_piter
- mln::line_graph_neighborhood_bkd_piter. */
-# include <mln/core/concept/point_iterator.hh>
-# include <mln/core/p_graph.hh>
-# include <mln/core/graph_psite.hh>
+# include <mln/core/internal/graph_vicinity_piter.hh>
/* FIXME: Due to the poor interface of mln::p_graph and
mln::util::graph, we show to much implementation details here.
@@ -52,9 +50,34 @@
namespace mln
{
- // Fwd decls.
- template <typename P> class p_graph;
- template <typename P> class graph_psite;
+
+ /*-----------------------------------------.
+ | internal::graph_window_piter_<P, W, E>. |
+ `-----------------------------------------*/
+
+ namespace internal
+ {
+
+ /// \brief Base for iterator on a graph window.
+ template <typename P, typename W, typename E>
+ class graph_window_piter_ : public graph_vicinity_piter_<P, E>
+ {
+ typedef graph_window_piter_<P, W, E> self_;
+ typedef graph_vicinity_piter_<P, E> super_;
+
+ public:
+ /// Construction.
+ /// \{
+ template <typename Pref>
+ graph_window_piter_(const Window<W>& win, const
Point_Site<Pref>& p_ref);
+ /// \}
+
+ protected:
+ /// The window.
+ const W& win_;
+ };
+
+ } // end of namespace mln::internal
/*-------------------------------.
@@ -64,21 +87,10 @@
/// \brief Forward iterator on graph window.
template <typename P, typename W>
class graph_window_fwd_piter :
- public Point_Iterator< graph_window_fwd_piter<P, W> >
+ public internal::graph_window_piter_< P, W, graph_window_fwd_piter<P, W>
>
{
typedef graph_window_fwd_piter<P, W> self_;
- typedef Point_Iterator< self_ > super_;
-
- public:
- enum { dim = P::dim };
-
- typedef graph_psite<P> psite;
- typedef P point;
- typedef mln_coord(P) coord;
- // FIXME: Dummy typedef.
- typedef void dpoint;
- // FIXME: Dummy value.
- typedef void mesh;
+ typedef internal::graph_window_piter_<P, W, self_> super_;
public:
/// Construction.
@@ -89,55 +101,19 @@
/// Manipulation.
/// \{
- /// Test if the iterator is valid.
- bool is_valid() const;
- /// Invalidate the iterator.
- void invalidate();
/// Start an iteration.
void start();
-
/// Go to the next point.
void next_();
- /// Is the piter adjacent or equal to the reference point?
- bool adjacent_or_equal_to_p_ref_() const;
- /// 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 line graph psite.
- operator psite() const;
-
- /// Read-only access to the \a i-th coordinate.
- coord operator[](unsigned i) const;
/// \}
/// Internals, used by the window.
/// \{
- public:
/// Set the iterator to the first site of the graph.
void first_();
/// Advance the position of the iterator by one step.
void step_();
-
- /// An internal iterator on the set of nodes of the underlying graph.
- util::node_id id_;
/// \}
-
- private:
- /// The window.
- const W& win_;
- /// The ``central'' psite of the window.
- const psite& p_ref_;
- /// The psite corresponding to this iterator.
- psite psite_;
- /// The point corresponding to this iterator.
- point p_;
};
@@ -148,21 +124,10 @@
/// \brief Backward iterator on graph window.
template <typename P, typename W>
class graph_window_bkd_piter :
- public Point_Iterator< graph_window_bkd_piter<P, W> >
+ public internal::graph_window_piter_< P, W, graph_window_bkd_piter<P, W>
>
{
typedef graph_window_bkd_piter<P, W> self_;
- typedef Point_Iterator< self_ > super_;
-
- public:
- enum { dim = P::dim };
-
- typedef graph_psite<P> psite;
- typedef P point;
- typedef mln_coord(P) coord;
- // FIXME: Dummy typedef.
- typedef void dpoint;
- // FIXME: Dummy value.
- typedef void mesh;
+ typedef internal::graph_window_piter_<P, W, self_> super_;
public:
/// Construction.
@@ -173,94 +138,56 @@
/// Manipulation.
/// \{
- /// Test if the iterator is valid.
- bool is_valid() const;
- /// Invalidate the iterator.
- void invalidate();
/// Start an iteration.
void start();
-
/// Go to the next point.
void next_();
- /// Is the piter adjacent or equal to the reference point?
- bool adjacent_or_equal_to_p_ref_() const;
- /// 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 line graph psite.
- operator psite() const;
-
- /// Read-only access to the \a i-th coordinate.
- coord operator[](unsigned i) const;
/// \}
/// Internals, used by the window.
/// \{
- public:
/// Set the iterator to the first site of the graph.
void first_();
/// Advance the position of the iterator by one step.
void step_();
-
- /// An internal iterator on the set of nodes of the underlying graph.
- util::node_id id_;
/// \}
-
- private:
- /// The window.
- const W& win_;
- /// The ``central'' psite of the window.
- const psite& p_ref_;
- /// The psite corresponding to this iterator.
- psite psite_;
- /// The point corresponding to this iterator.
- point p_;
};
# ifndef MLN_INCLUDE_ONLY
- /*-------------------------------.
- | graph_window_fwd_piter<P, W>. |
- `-------------------------------*/
+ /*-----------------------------------------.
+ | internal::graph_window_piter_<P, W, E>. |
+ `-----------------------------------------*/
- template <typename P, typename W>
+ namespace internal
+ {
+
+ template <typename P, typename W, typename E>
template <typename Pref>
inline
- graph_window_fwd_piter<P, W>::graph_window_fwd_piter(const Window<W>&
win,
+ graph_window_piter_<P, W, E>::graph_window_piter_(const Window<W>&
win,
const Point_Site<Pref>& p_ref)
- : win_(exact(win)),
- p_ref_(exact(p_ref).to_psite()),
- // Initialize psite_ to a dummy value.
- psite_(),
- p_()
+ : super_(p_ref),
+ win_(exact(win))
{
- // Invalidate id_.
- invalidate();
}
- template <typename P, typename W>
- inline
- bool
- graph_window_fwd_piter<P, W>::is_valid() const
- {
- return p_ref_.is_valid() && id_ < p_ref_.pg().npoints();
- }
+ } // end of namespace mln::internal
+
+
+ /*-------------------------------.
+ | graph_window_fwd_piter<P, W>. |
+ `-------------------------------*/
template <typename P, typename W>
+ template <typename Pref>
inline
- void
- graph_window_fwd_piter<P, W>::invalidate()
+ graph_window_fwd_piter<P, W>::graph_window_fwd_piter(const Window<W>&
win,
+ const Point_Site<Pref>& p_ref)
+ : super_(win, p_ref)
{
- id_ = -1;
}
template <typename P, typename W>
@@ -268,9 +195,9 @@
void
graph_window_fwd_piter<P, W>::start()
{
- win_.start(*this);
- if (is_valid())
- update_();
+ this->win_.start(*this);
+ if (this->is_valid())
+ this->update_();
}
template <typename P, typename W>
@@ -278,9 +205,9 @@
void
graph_window_fwd_piter<P, W>::next_()
{
- win_.next_(*this);
- if (is_valid())
- update_();
+ this->win_.next_(*this);
+ if (this->is_valid())
+ this->update_();
}
template <typename P, typename W>
@@ -288,7 +215,7 @@
void
graph_window_fwd_piter<P, W>::first_()
{
- id_ = 0;
+ this->id_ = 0;
}
template <typename P, typename W>
@@ -296,60 +223,7 @@
void
graph_window_fwd_piter<P, W>::step_()
{
- ++id_;
- }
-
-
- template <typename P, typename W>
- inline
- bool
- graph_window_fwd_piter<P, W>::adjacent_or_equal_to_p_ref_() const
- {
- return p_ref_.pg().adjacent_or_equal(p_ref_.id(), id_);
- }
-
- template <typename P, typename W>
- inline
- void
- graph_window_fwd_piter<P, W>::update_()
- {
- // Update psite_.
- psite_ = graph_psite<P>(p_ref_.pg(), id_);
- // Update p_.
- p_ = p_ref_.pg().point_from_id(id_);
- }
-
- template <typename P, typename W>
- inline
- const P&
- graph_window_fwd_piter<P, W>::to_point() const
- {
- return p_;
- }
-
- template <typename P, typename W>
- inline
- const graph_psite<P>&
- graph_window_fwd_piter<P, W>::to_psite() const
- {
- return psite_;
- }
-
- template <typename P, typename W>
- inline
- graph_window_fwd_piter<P, W>::operator graph_psite<P>() const
- {
- mln_precondition(is_valid());
- return psite_;
- }
-
- template <typename P, typename W>
- inline
- mln_coord(P)
- graph_window_fwd_piter<P, W>::operator[](unsigned i) const
- {
- assert(i < dim);
- return p_[i];
+ ++this->id_;
}
@@ -362,30 +236,8 @@
inline
graph_window_bkd_piter<P, W>::graph_window_bkd_piter(const Window<W>&
win,
const Point_Site<Pref>& p_ref)
- : win_(exact(win)),
- p_ref_(exact(p_ref).to_psite()),
- // Initialize psite_ to a dummy value.
- psite_(),
- p_()
- {
- // Invalidate id_.
- invalidate();
- }
-
- template <typename P, typename W>
- inline
- bool
- graph_window_bkd_piter<P, W>::is_valid() const
- {
- return p_ref_.is_valid() && id_ < p_ref_.pg().npoints();
- }
-
- template <typename P, typename W>
- inline
- void
- graph_window_bkd_piter<P, W>::invalidate()
+ : super_(win, p_ref)
{
- id_ = -1;
}
template <typename P, typename W>
@@ -393,9 +245,9 @@
void
graph_window_bkd_piter<P, W>::start()
{
- win_.start(*this);
- if (is_valid())
- update_();
+ this->win_.start(*this);
+ if (this->is_valid())
+ this->update_();
}
template <typename P, typename W>
@@ -403,9 +255,9 @@
void
graph_window_bkd_piter<P, W>::next_()
{
- win_.next_(*this);
- if (is_valid())
- update_();
+ this->win_.next_(*this);
+ if (this->is_valid())
+ this->update_();
}
template <typename P, typename W>
@@ -413,7 +265,7 @@
void
graph_window_bkd_piter<P, W>::first_()
{
- id_ = p_ref_.pg().gr_->nnodes() - 1;
+ this->id_ = this->p_ref_.pg().gr_->nnodes() - 1;
}
template <typename P, typename W>
@@ -421,60 +273,7 @@
void
graph_window_bkd_piter<P, W>::step_()
{
- --id_;
- }
-
-
- template <typename P, typename W>
- inline
- bool
- graph_window_bkd_piter<P, W>::adjacent_or_equal_to_p_ref_() const
- {
- return p_ref_.pg().adjacent_or_equal(p_ref_.id(), id_);
- }
-
- template <typename P, typename W>
- inline
- void
- graph_window_bkd_piter<P, W>::update_()
- {
- // Update psite_.
- psite_ = graph_psite<P>(p_ref_.pg(), id_);
- // Update p_.
- p_ = p_ref_.pg().point_from_id(id_);
- }
-
- template <typename P, typename W>
- inline
- const P&
- graph_window_bkd_piter<P, W>::to_point() const
- {
- return p_;
- }
-
- template <typename P, typename W>
- inline
- const graph_psite<P>&
- graph_window_bkd_piter<P, W>::to_psite() const
- {
- return psite_;
- }
-
- template <typename P, typename W>
- inline
- graph_window_bkd_piter<P, W>::operator graph_psite<P>() const
- {
- mln_precondition(is_valid());
- return psite_;
- }
-
- template <typename P, typename W>
- inline
- mln_coord(P)
- graph_window_bkd_piter<P, W>::operator[](unsigned i) const
- {
- assert(i < dim);
- return p_[i];
+ --this->id_;
}
# endif // ! MLN_INCLUDE_ONLY