
--- ChangeLog | 23 + milena/mln/util/graph.hh | 8 +- milena/mln/util/internal/graph_edge.hh | 39 +- milena/mln/util/internal/graph_edge_iter.hh | 273 --------- .../mln/util/internal/graph_edge_nbh_edge_iter.hh | 335 ---------- milena/mln/util/internal/graph_iter.hh | 298 +++++++++ milena/mln/util/internal/graph_iter_base.hh | 144 +++++ milena/mln/util/internal/graph_nbh_iter.hh | 636 ++++++++++++++++++++ milena/mln/util/internal/graph_nbh_iter_base.hh | 175 ++++++ milena/mln/util/internal/graph_vertex_iter.hh | 286 --------- .../util/internal/graph_vertex_nbh_edge_iter.hh | 323 ---------- .../util/internal/graph_vertex_nbh_vertex_iter.hh | 320 ---------- 12 files changed, 1309 insertions(+), 1551 deletions(-) delete mode 100644 milena/mln/util/internal/graph_edge_iter.hh delete mode 100644 milena/mln/util/internal/graph_edge_nbh_edge_iter.hh create mode 100644 milena/mln/util/internal/graph_iter.hh create mode 100644 milena/mln/util/internal/graph_iter_base.hh create mode 100644 milena/mln/util/internal/graph_nbh_iter.hh create mode 100644 milena/mln/util/internal/graph_nbh_iter_base.hh delete mode 100644 milena/mln/util/internal/graph_vertex_iter.hh delete mode 100644 milena/mln/util/internal/graph_vertex_nbh_edge_iter.hh delete mode 100644 milena/mln/util/internal/graph_vertex_nbh_vertex_iter.hh diff --git a/ChangeLog b/ChangeLog index a01d9c9..456606f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,28 @@ 2008-17-07 Guillaume Lazzara <z@lrde.epita.fr> + Refactor graph iterator classes. + * milena/mln/util/internal/graph_edge.hh: add invalidate(). + + * milena/mln/util/internal/graph_iter_base.hh: Base implementation for + a graph iterator. + + * milena/mln/util/internal/graph_vertex_iter.hh, + * milena/mln/util/internal/graph_edge_iter.hh: content moved... + * milena/mln/util/internal/graph_iter.hh: ...here. + + * milena/mln/util/internal/graph_nbh_iter.hh: Base implementation for + a graph iterator on a edge/vertex neighborhood. + + * milena/mln/util/internal/graph_edge_nbh_edge_iter.hh, + * milena/mln/util/internal/graph_vertex_nbh_edge_iter.hh, + * milena/mln/util/internal/graph_vertex_nbh_vertex_iter.hh: content + moved... + * milena/mln/util/internal/graph_nbh_iter_base.hh: ...here. + + * milena/mln/util/graph.hh: update includes. + +2008-17-07 Guillaume Lazzara <z@lrde.epita.fr> + Use track_ptr in graph. * milena/mln/core/concept/graph.hh, * milena/util/graph.hh, diff --git a/milena/mln/util/graph.hh b/milena/mln/util/graph.hh index 765c07c..aecb8e9 100644 --- a/milena/mln/util/graph.hh +++ b/milena/mln/util/graph.hh @@ -32,11 +32,8 @@ /// \brief Definitions of undirected graphs. # include <mln/util/internal/graph_base.hh> -# include <mln/util/internal/graph_vertex_iter.hh> -# include <mln/util/internal/graph_edge_iter.hh> -# include <mln/util/internal/graph_vertex_nbh_vertex_iter.hh> -# include <mln/util/internal/graph_vertex_nbh_edge_iter.hh> -# include <mln/util/internal/graph_edge_nbh_edge_iter.hh> +# include <mln/util/internal/graph_iter.hh> +# include <mln/util/internal/graph_nbh_iter_base.hh> # include <mln/util/ord_pair.hh> namespace mln @@ -48,6 +45,7 @@ namespace mln class graph; } + namespace internal { diff --git a/milena/mln/util/internal/graph_edge.hh b/milena/mln/util/internal/graph_edge.hh index dcbf6ac..42d0e62 100644 --- a/milena/mln/util/internal/graph_edge.hh +++ b/milena/mln/util/internal/graph_edge.hh @@ -62,6 +62,11 @@ namespace mln /// Misc. /// \{ + /// Return whether is points to a known edge. + bool is_valid() const; + /// Invalidate that vertex. + void invalidate(); + /// Return the edge id. unsigned id() const; @@ -86,8 +91,6 @@ namespace mln /// Edge oriented. /// \{ - bool is_valid() const; - /// Return the lowest vertex id adjacent to this edge. unsigned v1() const; @@ -145,6 +148,7 @@ namespace mln { void update_id(unsigned id); void change_graph(const mlc_const(G)& g); + void invalidate(); private: E& exact_(); @@ -219,19 +223,28 @@ namespace mln template <typename G> inline - unsigned - edge<G>::v_other(unsigned id_v) const + bool + edge<G>::is_valid() const { - mln_precondition(v1() == id_v || v2() == id_v); - return g_.v_other(id_, id_v); + return g_.has_e(id_); } template <typename G> inline - bool - edge<G>::is_valid() const + void + edge<G>::invalidate() { - return g_.has_e(id_); + id_ = g_.e_nmax(); + } + + + template <typename G> + inline + unsigned + edge<G>::v_other(unsigned id_v) const + { + mln_precondition(v1() == id_v || v2() == id_v); + return g_.v_other(id_, id_v); } template <typename G> @@ -390,6 +403,14 @@ namespace mln return exact_().get_subject().change_graph(g); } + template <typename G, typename E> + inline + void + subject_impl< util::edge<G>, E >::invalidate() + { + return exact_().get_subject().invalidate(); + } + } // End of namespace mln::internal # endif // !MLN_INCLUDE_ONLY diff --git a/milena/mln/util/internal/graph_edge_iter.hh b/milena/mln/util/internal/graph_edge_iter.hh deleted file mode 100644 index b3d83de..0000000 --- a/milena/mln/util/internal/graph_edge_iter.hh +++ /dev/null @@ -1,273 +0,0 @@ -// 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_UTIL_INTERNAL_GRAPH_EDGE_ITER_HH -# define MLN_UTIL_INTERNAL_GRAPH_EDGE_ITER_HH - -# include <mln/core/concept/iterator.hh> -# include <mln/core/concept/proxy.hh> -# include <mln/util/internal/graph_edge.hh> - -/// \file mln/util/internal/graph_edge_iter.hh -/// \brief Implementation for graph edge iterators. - -namespace mln -{ - - namespace internal - { - - /// Forward edge iterator. - template <typename G> - class edge_fwd_iterator - : public Proxy< edge_fwd_iterator<G> >, - public internal::proxy_impl< const util::edge<G>&, edge_fwd_iterator<G> > - { - public: - /// Constructors. - /// \{ - edge_fwd_iterator(); - edge_fwd_iterator(const G& g); - /// \} - - /// Iterator interface - /// \{ - /// Test if the iterator is valid. - bool is_valid() const; - /// Invalidate the iterator. - void invalidate(); - - /// Start an iteration. - void start(); - - /// Go to the next value. - void next(); - - /// Return current index - unsigned index() const; - /// \} - - /// Proxy. - /// \{ - /// Proxy subject - const util::edge<G>& subj_(); - /// \} - - protected: - util::edge<G> e_; - }; - - template <typename G> - class edge_bkd_iterator - : public Proxy< edge_bkd_iterator<G> >, - public proxy_impl< const util::edge<G>&, edge_bkd_iterator<G> > - { - public: - /// Constructors. - /// \{ - edge_bkd_iterator(); - edge_bkd_iterator(const G& g); - /// \} - - /// Iterator interface. - /// \{ - /// Test if the iterator is valid. - bool is_valid() const; - /// Invalidate the iterator. - void invalidate(); - - /// Start an iteration. - void start(); - - /// Go to the next value. - void next(); - - /// Return current index - unsigned index() const; - /// \} - - /// Proxy. - /// \{ - /// Proxy subject - const util::edge<G>& subj_(); - /// \} - - protected: - util::edge<G> e_; - }; - - } // End of namespace mln::internal - -} // End of namespace mln - - -# ifndef MLN_INCLUDE_ONLY - -namespace mln -{ - - namespace internal - { - - template <typename G> - inline - edge_fwd_iterator<G>::edge_fwd_iterator() - { - } - - template <typename G> - inline - edge_fwd_iterator<G>::edge_fwd_iterator(const G& g) - : e_(util::edge<G>(g)) - { - invalidate(); - } - - template <typename G> - inline - bool - edge_fwd_iterator<G>::is_valid() const - { - return e_.is_valid(); - } - - template <typename G> - inline - void - edge_fwd_iterator<G>::invalidate() - { - e_.update_id(e_.g().e_nmax()); - } - - template <typename G> - inline - void - edge_fwd_iterator<G>::start() - { - e_.update_id(0); - } - - template <typename G> - inline - void - edge_fwd_iterator<G>::next() - { - e_.update_id(e_.id() + 1); - } - - template <typename G> - inline - unsigned - edge_fwd_iterator<G>::index() const - { - return e_.id(); - } - - template <typename G> - inline - const util::edge<G>& - edge_fwd_iterator<G>::subj_() - { - return e_; - } - - - - /*------------------` - | edge_bkd_iterator | - \------------------*/ - - template <typename G> - inline - edge_bkd_iterator<G>::edge_bkd_iterator() - { - } - - template <typename G> - inline - edge_bkd_iterator<G>::edge_bkd_iterator(const G& g) - : e_(util::edge<G>(g)) - { - invalidate(); - } - - template <typename G> - inline - bool - edge_bkd_iterator<G>::is_valid() const - { - return e_.is_valid(); - } - - template <typename G> - inline - void - edge_bkd_iterator<G>::invalidate() - { - e_.update_id(e_.g().e_nmax()); - } - - template <typename G> - inline - void - edge_bkd_iterator<G>::start() - { - e_.update_id(e_.g().e_nmax() - 1); - } - - template <typename G> - inline - void - edge_bkd_iterator<G>::next() - { - e_.update_id(e_.id() - 1); - } - - template <typename G> - inline - unsigned - edge_bkd_iterator<G>::index() const - { - return e_.id(); - } - - template <typename G> - inline - const util::edge<G>& - edge_bkd_iterator<G>::subj_() - { - return e_; - } - - } // End of namespace mln::internal - -} // End of namespace mln - -# endif // !MLN_INCLUDE_ONLY - -#endif // !MLN_UTIL_INTERNAL_GRAPH_EDGE_ITER_HH - diff --git a/milena/mln/util/internal/graph_edge_nbh_edge_iter.hh b/milena/mln/util/internal/graph_edge_nbh_edge_iter.hh deleted file mode 100644 index 3ba8d0e..0000000 --- a/milena/mln/util/internal/graph_edge_nbh_edge_iter.hh +++ /dev/null @@ -1,335 +0,0 @@ -// 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_UTIL_INTERNAL_GRAPH_EDGE_NBH_EDGE_ITER_HH -# define MLN_UTIL_INTERNAL_GRAPH_EDGE_NBH_EDGE_ITER_HH - -# include <mln/core/concept/proxy.hh> - -/// \file mln/util/internal/graph_edge_nbh_edge_iter.hh -/// \brief Implementation for graph edge iterators centered to an edge. - -namespace mln -{ - - namespace internal - { - - template <typename G> - class edge_nbh_edge_fwd_iterator - : public Proxy< edge_nbh_edge_fwd_iterator<G> >, - public internal::proxy_impl< const util::edge<G>&, edge_nbh_edge_fwd_iterator<G> > - { - public: - /// Construction and assignment. - /// \{ - template <typename C> - edge_nbh_edge_fwd_iterator(const C& c); - /// \} - - /// Iterator interface. - /// \{ - /// Test if the iterator is valid. - bool is_valid() const; - /// Invalidate the iterator. - void invalidate(); - - /// Start an iteration. - void start(); - - /// Go to the next value. - void next(); - - /// Return current index - unsigned index() const; - /// \} - - /// Proxy. - /// \{ - /// Proxy subject - const util::edge<G>& subj_(); - /// \} - - protected: - void update_(); - - template <typename C> - void center_at(const C& c); - - - const util::edge<G>* c_; //Center - util::edge<G> e_; - unsigned i_; - }; - - template <typename G> - class edge_nbh_edge_bkd_iterator - : public Proxy< edge_nbh_edge_bkd_iterator<G> >, - public proxy_impl< const util::edge<G>&, edge_nbh_edge_bkd_iterator<G> > - { - public: - /// Construction and assignment. - /// \{ - template <typename C> - edge_nbh_edge_bkd_iterator(const C& e); - /// \} - - /// Iterator interface. - /// \{ - /// Test if the iterator is valid. - bool is_valid() const; - /// Invalidate the iterator. - void invalidate(); - - /// Start an iteration. - void start(); - - /// Go to the next value. - void next(); - - /// Return current index - unsigned index() const; - /// \} - - /// Proxy. - /// \{ - /// Proxy subject - const util::edge<G>& subj_(); - /// \} - - protected: - void update_(); - - template <typename C> - void center_at(const C& c); - - const util::edge<G>* c_; //Center - util::edge<G> e_; - unsigned i_; - }; - - -# ifndef MLN_INCLUDE_ONLY - - template <typename G> - template <typename C> - inline - edge_nbh_edge_fwd_iterator<G>::edge_nbh_edge_fwd_iterator(const C& c) - : e_(c.g()), i_(0) - { - //FIXME: Check if typeof(e.g()) == G - center_at(c); - } - - template <typename G> - inline - bool - edge_nbh_edge_fwd_iterator<G>::is_valid() const - { - return i_ < c_->nmax_nbh_edges(); - } - - template <typename G> - inline - void - edge_nbh_edge_fwd_iterator<G>::invalidate() - { - i_ = e_.g().e_nmax(); - } - - template <typename G> - inline - void - edge_nbh_edge_fwd_iterator<G>::start() - { - i_ = 0; - if (is_valid()) - update_(); - } - - template <typename G> - inline - void - edge_nbh_edge_fwd_iterator<G>::next() - { - ++i_; - if (is_valid()) - update_(); - } - - template <typename G> - inline - unsigned - edge_nbh_edge_fwd_iterator<G>::index() const - { - return i_; - } - - template <typename G> - inline - const util::edge<G>& - edge_nbh_edge_fwd_iterator<G>::subj_() - { - return e_; - } - - template <typename G> - inline - void - edge_nbh_edge_fwd_iterator<G>::update_() - { - mln_precondition(is_valid()); - mln_precondition(c_->is_valid()); - - // We shall encounter vertices which are part of the - // current edge. - // We do not want them to be part of the edge neighbors. - unsigned e_id = c_->ith_nbh_edge(i_); - while (e_id == c_->id()) - e_id = c_->ith_nbh_edge(++i_); - - e_.update_id(e_id); - } - - template <typename G> - template <typename E> - inline - void - edge_nbh_edge_fwd_iterator<G>::center_at(const E& c) - { - internal::get_adr(c_, c); - mln_precondition(c_ != 0); - - invalidate(); - } - - - - /*---------------------------` - | edge_nbh_edge_bkd_iterator | - \---------------------------*/ - - template <typename G> - template <typename C> - inline - edge_nbh_edge_bkd_iterator<G>::edge_nbh_edge_bkd_iterator(const C& c) - : e_(c.g()), i_(0) - { - //FIXME: Check if typeof(e.g()) == G - center_at(c); - } - - template <typename G> - inline - bool - edge_nbh_edge_bkd_iterator<G>::is_valid() const - { - return i_ < c_->nmax_nbh_edges(); - } - - template <typename G> - inline - void - edge_nbh_edge_bkd_iterator<G>::invalidate() - { - i_ = e_.g().e_nmax(); - } - - template <typename G> - inline - void - edge_nbh_edge_bkd_iterator<G>::start() - { - i_ = c_->nmax_nbh_edges() - 1; - if (is_valid()) - update_(); - } - - template <typename G> - inline - void - edge_nbh_edge_bkd_iterator<G>::next() - { - --i_; - if (is_valid()) - update_(); - } - - template <typename G> - inline - unsigned - edge_nbh_edge_bkd_iterator<G>::index() const - { - return i_; - } - - template <typename G> - inline - const util::edge<G>& - edge_nbh_edge_bkd_iterator<G>::subj_() - { - return e_; - } - - template <typename G> - inline - void - edge_nbh_edge_bkd_iterator<G>::update_() - { - mln_precondition(is_valid()); - mln_precondition(c_->is_valid()); - - // We shall encounter vertices which are part of the - // current edge. - // We do not want them to be part of the edge neighbors. - unsigned e_id = c_->ith_nbh_edge(i_); - while (e_id == c_->id()) - e_id = c_->ith_nbh_edge(--i_); - - e_.update_id(e_id); - } - - template <typename G> - template <typename E> - inline - void - edge_nbh_edge_bkd_iterator<G>::center_at(const E& c) - { - internal::get_adr(c_, c); - mln_precondition(c_ != 0); - - invalidate(); - } -# endif // !MLN_INCLUDE_ONLY - - } // End of namespace mln::internal - -} // End of namespace mln - - -#endif // !MLN_UTIL_INTERNAL_GRAPH_EDGE_NBH_EDGE_ITER_HH - diff --git a/milena/mln/util/internal/graph_iter.hh b/milena/mln/util/internal/graph_iter.hh new file mode 100644 index 0000000..ab62582 --- /dev/null +++ b/milena/mln/util/internal/graph_iter.hh @@ -0,0 +1,298 @@ +// 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_UTIL_INTERNAL_GRAPH_ITER_HH +# define MLN_UTIL_INTERNAL_GRAPH_ITER_HH + +# include <mln/core/concept/iterator.hh> +# include <mln/util/internal/graph_vertex.hh> +# include <mln/util/internal/graph_edge.hh> +# include <mln/util/internal/graph_iter_base.hh> + +/// \file mln/util/internal/graph_iter.hh +/// \brief Implementation for graph iterators. + +namespace mln +{ + + namespace internal + { + + template<typename G> + class vertex_fwd_iterator + : public graph_iter_base<G, util::vertex<G>, vertex_fwd_iterator<G> > + { + typedef graph_iter_base<G, util::vertex<G>, vertex_fwd_iterator<G> > super_; + + public: + /// Constructors. + /// \{ + vertex_fwd_iterator(); + vertex_fwd_iterator(const G& g); + /// \} + + protected: + /// Returns the id of the first element. + /// Called in start(); + unsigned start_id_() const; + + /// Returns the next element id. + /// Called in next(); + unsigned next_id_() const; + + using super_::p_; + friend class graph_iter_base<G, util::vertex<G>, vertex_fwd_iterator<G> >; + }; + + + template<typename G> + class vertex_bkd_iterator + : public graph_iter_base<G, util::vertex<G>, vertex_bkd_iterator<G> > + { + typedef graph_iter_base<G, util::vertex<G>, vertex_bkd_iterator<G> > super_; + + public: + /// Constructors. + /// \{ + vertex_bkd_iterator(); + vertex_bkd_iterator(const G& g); + /// \} + + protected: + /// Returns the id of the first element. + /// Called in start(); + unsigned start_id_() const; + + /// Returns the next element id. + /// Called in next(); + unsigned next_id_() const; + + using super_::p_; + friend class graph_iter_base<G, util::vertex<G>, vertex_bkd_iterator<G> >; + }; + + /// Forward edge iterator. + template <typename G> + class edge_fwd_iterator + : public graph_iter_base<G, util::edge<G>, edge_fwd_iterator<G> > + { + typedef graph_iter_base<G, util::edge<G>, edge_fwd_iterator<G> > super_; + + public: + /// Constructors. + /// \{ + edge_fwd_iterator(); + edge_fwd_iterator(const G& g); + /// \} + + protected: + /// Returns the id of the first element. + /// Called in start(); + unsigned start_id_() const; + + /// Returns the next element id. + /// Called in next(); + unsigned next_id_() const; + + using super_::p_; + friend class graph_iter_base<G, util::edge<G>, edge_fwd_iterator<G> >; + }; + + template <typename G> + class edge_bkd_iterator + : public graph_iter_base<G, util::edge<G>, edge_bkd_iterator<G> > + { + typedef graph_iter_base<G, util::edge<G>, edge_bkd_iterator<G> > super_; + + public: + /// Constructors. + /// \{ + edge_bkd_iterator(); + edge_bkd_iterator(const G& g); + /// \} + + protected: + /// Returns the id of the first element. + /// Called in start(); + unsigned start_id_() const; + + /// Returns the next element id. + /// Called in next(); + unsigned next_id_() const; + + using super_::p_; + friend class graph_iter_base<G, util::edge<G>, edge_bkd_iterator<G> >; + }; + +# ifndef MLN_INCLUDE_ONLY + + /*--------------------` + | vertex_fwd_iterator | + \--------------------*/ + + template <typename G> + inline + vertex_fwd_iterator<G>::vertex_fwd_iterator() + { + } + + template <typename G> + inline + vertex_fwd_iterator<G>::vertex_fwd_iterator(const G& g) + : super_(g) + { + } + + template <typename G> + inline + unsigned + vertex_fwd_iterator<G>::start_id_() const + { + return 0; + } + + template <typename G> + inline + unsigned + vertex_fwd_iterator<G>::next_id_() const + { + return p_.id() + 1; + } + + + + /*--------------------` + | vertex_bkd_iterator | + \--------------------*/ + + template <typename G> + inline + vertex_bkd_iterator<G>::vertex_bkd_iterator() + { + } + + template <typename G> + inline + vertex_bkd_iterator<G>::vertex_bkd_iterator(const G& g) + : super_(g) + { + } + + template <typename G> + inline + unsigned + vertex_bkd_iterator<G>::start_id_() const + { + return p_.g().v_nmax() - 1; + } + + template <typename G> + inline + unsigned + vertex_bkd_iterator<G>::next_id_() const + { + return p_.id() - 1; + } + + + + /*------------------` + | edge_fwd_iterator | + \------------------*/ + + template <typename G> + inline + edge_fwd_iterator<G>::edge_fwd_iterator() + { + } + + template <typename G> + inline + edge_fwd_iterator<G>::edge_fwd_iterator(const G& g) + : super_(g) + { + } + + template <typename G> + inline + unsigned + edge_fwd_iterator<G>::start_id_() const + { + return 0; + } + + template <typename G> + inline + unsigned + edge_fwd_iterator<G>::next_id_() const + { + return p_.id() + 1; + } + + + + /*------------------` + | edge_bkd_iterator | + \------------------*/ + + template <typename G> + inline + edge_bkd_iterator<G>::edge_bkd_iterator() + { + } + + template <typename G> + inline + edge_bkd_iterator<G>::edge_bkd_iterator(const G& g) + : super_(g) + { + } + + template <typename G> + inline + unsigned + edge_bkd_iterator<G>::start_id_() const + { + return p_.g().e_nmax() - 1; + } + + template <typename G> + inline + unsigned + edge_bkd_iterator<G>::next_id_() const + { + return p_.id() - 1; + } + +# endif // !MLN_INCLUDE_ONLY + + } // End of namespace mln::internal + +} // End of namespace mln + +#endif // !MLN_UTIL_INTERNAL_GRAPH_ITER_HH + diff --git a/milena/mln/util/internal/graph_iter_base.hh b/milena/mln/util/internal/graph_iter_base.hh new file mode 100644 index 0000000..a901192 --- /dev/null +++ b/milena/mln/util/internal/graph_iter_base.hh @@ -0,0 +1,144 @@ +// 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_UTIL_INTERNAL_GRAPH_ITER_BASE_HH +# define MLN_UTIL_INTERNAL_GRAPH_ITER_BASE_HH + +# include <mln/core/concept/iterator.hh> +# include <mln/core/concept/proxy.hh> +# include <mln/util/internal/graph_edge.hh> + +/// \file mln/util/internal/graph_iter_base.hh +/// \brief Base implementation for graph iterators. + +namespace mln +{ + + namespace internal + { + + template <typename G, typename P, typename E> + class graph_iter_base + : public Proxy< E >, + public internal::proxy_impl< const P&, E > + { + public: + /// Iterator interface + /// \{ + /// Test if the iterator is valid. + bool is_valid() const; + /// Invalidate the iterator. + void invalidate(); + + /// Start an iteration. + void start(); + + /// Go to the next value. + void next(); + + /// Return current index + unsigned index() const; + /// \} + + /// Proxy. + /// \{ + /// Proxy subject + const P& subj_(); + /// \} + + protected: + graph_iter_base(const G& g); + + P p_; + }; + +# ifndef MLN_INCLUDE_ONLY + + template <typename G, typename P, typename E> + inline + graph_iter_base<G, P, E>::graph_iter_base(const G& g) + : p_(P(g)) + { + invalidate(); + } + + template <typename G, typename P, typename E> + inline + bool + graph_iter_base<G, P, E>::is_valid() const + { + return p_.is_valid(); + } + + template <typename G, typename P, typename E> + inline + void + graph_iter_base<G, P, E>::invalidate() + { + p_.invalidate(); + } + + template <typename G, typename P, typename E> + inline + void + graph_iter_base<G, P, E>::start() + { + p_.update_id(exact(this)->start_id_()); + } + + template <typename G, typename P, typename E> + inline + void + graph_iter_base<G, P, E>::next() + { + p_.update_id(exact(this)->next_id_()); + } + + template <typename G, typename P, typename E> + inline + unsigned + graph_iter_base<G, P, E>::index() const + { + return p_.id(); + } + + template <typename G, typename P, typename E> + inline + const P& + graph_iter_base<G, P, E>::subj_() + { + return p_; + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::internal + +} // end of namespace mln + +#endif // ! MLN_UTIL_INTERNAL_GRAPH_ITER_BASE_HH + diff --git a/milena/mln/util/internal/graph_nbh_iter.hh b/milena/mln/util/internal/graph_nbh_iter.hh new file mode 100644 index 0000000..5edecef --- /dev/null +++ b/milena/mln/util/internal/graph_nbh_iter.hh @@ -0,0 +1,636 @@ +// 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_UTIL_INTERNAL_GRAPH_VERTEX_NBH_VERTEX_ITER_HH +# define MLN_UTIL_INTERNAL_GRAPH_VERTEX_NBH_VERTEX_ITER_HH + +# include <mln/core/concept/proxy.hh> +# include <mln/util/internal/graph_nbh_iter_base.hh> + +/// \file mln/util/internal/graph_vertex_nbh_vertex_iter.hh +/// \brief Implementation for graph vertex iterators centered to a vertex. + +namespace mln +{ + + namespace internal + { + + /*-----------------------------` + | vertex_nbh_vertex_*_iterator | + \-----------------------------*/ + + template <typename G> + class vertex_nbh_vertex_fwd_iterator + : public nbh_iterator_base<G, + util::vertex<G>, + util::vertex<G>, + vertex_nbh_vertex_fwd_iterator<G> > + { + typedef util::vertex<G> V; + typedef vertex_nbh_vertex_fwd_iterator<G> self_; + typedef nbh_iterator_base<G, V, V, self_> super_; + + public: + /// Construction and assignment. + /// \{ + template <typename C> + vertex_nbh_vertex_fwd_iterator(const C& c); + /// \} + + protected: + // Manipulation. + /// \{ + /// Test if the iterator is valid. + bool is_valid_() const; + /// Invalidate the iterator. + void invalidate_(); + /// \} + + /// Start an iteration. + unsigned start_id_() const; + + /// Go to the next value. + unsigned next_id_() const; + + void update_(); + + friend class nbh_iterator_base<G, V, V, self_>; + }; + + template <typename G> + class vertex_nbh_vertex_bkd_iterator + : public nbh_iterator_base<G, + util::vertex<G>, + util::vertex<G>, + vertex_nbh_vertex_bkd_iterator<G> > + { + typedef util::vertex<G> V; + typedef vertex_nbh_vertex_bkd_iterator<G> self_; + typedef nbh_iterator_base<G, V, V, self_> super_; + + public: + /// Construction and assignment. + /// \{ + template <typename C> + vertex_nbh_vertex_bkd_iterator(const C& c); + /// \} + + protected: + /// Manipulation. + /// \{ + /// Test if the iterator is valid. + bool is_valid_() const; + /// Invalidate the iterator. + void invalidate_(); + /// \} + + /// Start an iteration. + unsigned start_id_() const; + + /// Go to the next value. + unsigned next_id_() const; + + void update_(); + + friend class nbh_iterator_base<G, V, V, self_>; + }; + + + /*---------------------------` + | vertex_nbh_edge_*_iterator | + \---------------------------*/ + + template <typename G> + class vertex_nbh_edge_fwd_iterator + : public nbh_iterator_base<G, + util::vertex<G>, + util::edge<G>, + vertex_nbh_edge_fwd_iterator<G> > + { + typedef util::vertex<G> V; + typedef util::edge<G> E; + typedef vertex_nbh_edge_fwd_iterator<G> self_; + typedef nbh_iterator_base<G, V, E, self_> super_; + + public: + /// Construction and assignment. + /// \{ + template <typename C> + vertex_nbh_edge_fwd_iterator(const C& c); + /// \} + + protected: + // Manipulation. + /// \{ + /// Test if the iterator is valid. + bool is_valid_() const; + /// Invalidate the iterator. + void invalidate_(); + /// \} + + /// Start an iteration. + unsigned start_id_() const; + + /// Go to the next value. + unsigned next_id_() const; + + void update_(); + + friend class nbh_iterator_base<G, V, E, self_>; + }; + + + template <typename G> + class vertex_nbh_edge_bkd_iterator + : public nbh_iterator_base<G, + util::vertex<G>, + util::edge<G>, + vertex_nbh_edge_bkd_iterator<G> > + { + typedef util::vertex<G> V; + typedef util::edge<G> E; + typedef vertex_nbh_edge_bkd_iterator<G> self_; + typedef nbh_iterator_base<G, V, E, self_> super_; + + public: + /// Construction and assignment. + /// \{ + template <typename C> + vertex_nbh_edge_bkd_iterator(const C& c); + /// \} + + protected: + // Manipulation. + /// \{ + /// Test if the iterator is valid. + bool is_valid_() const; + /// Invalidate the iterator. + void invalidate_(); + /// \} + + /// Start an iteration. + unsigned start_id_() const; + + /// Go to the next value. + unsigned next_id_() const; + + void update_(); + + friend class nbh_iterator_base<G, V, E, self_>; + }; + + + /*---------------------------` + | edge_nbh_edge_*_iterator | + \---------------------------*/ + + template <typename G> + class edge_nbh_edge_fwd_iterator + : public nbh_iterator_base<G, + util::edge<G>, + util::edge<G>, + edge_nbh_edge_fwd_iterator<G> > + { + typedef util::edge<G> E; + typedef edge_nbh_edge_fwd_iterator<G> self_; + typedef nbh_iterator_base<G, E, E, self_> super_; + + public: + /// Construction and assignment. + /// \{ + template <typename C> + edge_nbh_edge_fwd_iterator(const C& c); + /// \} + + protected: + // Manipulation. + /// \{ + /// Test if the iterator is valid. + bool is_valid_() const; + /// Invalidate the iterator. + void invalidate_(); + /// \} + + /// Start an iteration. + unsigned start_id_() const; + + /// Go to the next value. + unsigned next_id_() const; + + void update_(); + + friend class nbh_iterator_base<G, E, E, self_>; + }; + + + template <typename G> + class edge_nbh_edge_bkd_iterator + : public nbh_iterator_base<G, + util::edge<G>, + util::edge<G>, + edge_nbh_edge_bkd_iterator<G> > + { + typedef util::edge<G> E; + typedef edge_nbh_edge_bkd_iterator<G> self_; + typedef nbh_iterator_base<G, E, E, self_> super_; + + public: + /// Construction and assignment. + /// \{ + template <typename C> + edge_nbh_edge_bkd_iterator(const C& c); + /// \} + + protected: + // Manipulation. + /// \{ + /// Test if the iterator is valid. + bool is_valid_() const; + /// Invalidate the iterator. + void invalidate_(); + /// \} + + /// Start an iteration. + unsigned start_id_() const; + + /// Go to the next value. + unsigned next_id_() const; + + void update_(); + + friend class nbh_iterator_base<G, E, E, self_>; + }; + +# ifndef MLN_INCLUDE_ONLY + + /*-------------------------------` + | vertex_nbh_vertex_fwd_iterator | + \-------------------------------*/ + + + template <typename G> + template <typename C> + inline + vertex_nbh_vertex_fwd_iterator<G>::vertex_nbh_vertex_fwd_iterator(const C& c) + : super_(c) + { + } + + template <typename G> + inline + bool + vertex_nbh_vertex_fwd_iterator<G>::is_valid_() const + { + return this->i_ < this->c_->nmax_nbh_vertices(); + } + + template <typename G> + inline + void + vertex_nbh_vertex_fwd_iterator<G>::invalidate_() + { + this->i_ = this->p_.g().v_nmax(); + } + + template <typename G> + inline + unsigned + vertex_nbh_vertex_fwd_iterator<G>::start_id_() const + { + return 0; + } + + template <typename G> + inline + unsigned + vertex_nbh_vertex_fwd_iterator<G>::next_id_() const + { + return this->i_ + 1; + } + + template <typename G> + inline + void + vertex_nbh_vertex_fwd_iterator<G>::update_() + { + this->p_.update_id(this->c_->ith_nbh_vertex(this->i_)); + } + + /*-------------------------------` + | vertex_nbh_vertex_bkd_iterator | + \-------------------------------*/ + + + template <typename G> + template <typename C> + inline + vertex_nbh_vertex_bkd_iterator<G>::vertex_nbh_vertex_bkd_iterator(const C& c) + : super_(c) + { + } + + template <typename G> + inline + bool + vertex_nbh_vertex_bkd_iterator<G>::is_valid_() const + { + return this->i_ < this->c_->nmax_nbh_vertices(); + } + + template <typename G> + inline + void + vertex_nbh_vertex_bkd_iterator<G>::invalidate_() + { + this->i_ = this->p_.g().v_nmax(); + } + + template <typename G> + inline + unsigned + vertex_nbh_vertex_bkd_iterator<G>::start_id_() const + { + return this->c_->nmax_nbh_vertices() - 1; + } + + template <typename G> + inline + unsigned + vertex_nbh_vertex_bkd_iterator<G>::next_id_() const + { + return this->i_ - 1; + } + + template <typename G> + inline + void + vertex_nbh_vertex_bkd_iterator<G>::update_() + { + this->p_.update_id(this->c_->ith_nbh_vertex(this->i_)); + } + + + /*-----------------------------` + | vertex_nbh_edge_fwd_iterator | + \-----------------------------*/ + + template <typename G> + template <typename C> + inline + vertex_nbh_edge_fwd_iterator<G>::vertex_nbh_edge_fwd_iterator(const C& c) + : super_(c) + { + } + + template <typename G> + inline + bool + vertex_nbh_edge_fwd_iterator<G>::is_valid_() const + { + return this->i_ < this->c_->nmax_nbh_edges(); + } + + template <typename G> + inline + void + vertex_nbh_edge_fwd_iterator<G>::invalidate_() + { + this->i_ = this->p_.g().e_nmax(); + } + + template <typename G> + inline + unsigned + vertex_nbh_edge_fwd_iterator<G>::start_id_() const + { + return 0; + } + + template <typename G> + inline + unsigned + vertex_nbh_edge_fwd_iterator<G>::next_id_() const + { + return this->i_ + 1; + } + + template <typename G> + inline + void + vertex_nbh_edge_fwd_iterator<G>::update_() + { + this->p_.update_id(this->c_->ith_nbh_edge(this->i_)); + } + + /*-----------------------------` + | vertex_nbh_edge_bkd_iterator | + \-----------------------------*/ + + template <typename G> + template <typename C> + inline + vertex_nbh_edge_bkd_iterator<G>::vertex_nbh_edge_bkd_iterator(const C& c) + : super_(c) + { + } + + template <typename G> + inline + bool + vertex_nbh_edge_bkd_iterator<G>::is_valid_() const + { + return this->i_ < this->c_->nmax_nbh_edges(); + } + + template <typename G> + inline + void + vertex_nbh_edge_bkd_iterator<G>::invalidate_() + { + this->i_ = this->p_.g().e_nmax(); + } + + template <typename G> + inline + unsigned + vertex_nbh_edge_bkd_iterator<G>::start_id_() const + { + return this->c_->nmax_nbh_edges() - 1; + } + + template <typename G> + inline + unsigned + vertex_nbh_edge_bkd_iterator<G>::next_id_() const + { + return this->i_ - 1; + } + + template <typename G> + inline + void + vertex_nbh_edge_bkd_iterator<G>::update_() + { + this->p_.update_id(this->c_->ith_nbh_edge(this->i_)); + } + + + + /*-----------------------------` + | edge_nbh_edge_fwd_iterator | + \-----------------------------*/ + + template <typename G> + template <typename C> + inline + edge_nbh_edge_fwd_iterator<G>::edge_nbh_edge_fwd_iterator(const C& c) + : super_(c) + { + } + + template <typename G> + inline + bool + edge_nbh_edge_fwd_iterator<G>::is_valid_() const + { + return this->i_ < this->c_->nmax_nbh_edges(); + } + + template <typename G> + inline + void + edge_nbh_edge_fwd_iterator<G>::invalidate_() + { + this->i_ = this->p_.g().e_nmax(); + } + + template <typename G> + inline + unsigned + edge_nbh_edge_fwd_iterator<G>::start_id_() const + { + return 0; + } + + template <typename G> + inline + unsigned + edge_nbh_edge_fwd_iterator<G>::next_id_() const + { + return this->i_ + 1; + } + + template <typename G> + inline + void + edge_nbh_edge_fwd_iterator<G>::update_() + { + // We shall encounter vertices which are part of the + // current edge. + // We do not want them to be part of the edge neighbors. + unsigned e_id = this->c_->ith_nbh_edge(this->i_); + while (e_id == this->c_->id()) + { + this->i_ = next_id_(); + e_id = this->c_->ith_nbh_edge(this->i_); + } + + this->p_.update_id(e_id); + } + + /*-----------------------------` + | edge_nbh_edge_bkd_iterator | + \-----------------------------*/ + + template <typename G> + template <typename C> + inline + edge_nbh_edge_bkd_iterator<G>::edge_nbh_edge_bkd_iterator(const C& c) + : super_(c) + { + } + + template <typename G> + inline + bool + edge_nbh_edge_bkd_iterator<G>::is_valid_() const + { + return this->i_ < this->c_->nmax_nbh_edges(); + } + + template <typename G> + inline + void + edge_nbh_edge_bkd_iterator<G>::invalidate_() + { + this->i_ = this->p_.g().e_nmax(); + } + + template <typename G> + inline + unsigned + edge_nbh_edge_bkd_iterator<G>::start_id_() const + { + return this->c_->nmax_nbh_edges() - 1; + } + + template <typename G> + inline + unsigned + edge_nbh_edge_bkd_iterator<G>::next_id_() const + { + return this->i_ - 1; + } + + template <typename G> + inline + void + edge_nbh_edge_bkd_iterator<G>::update_() + { + // We shall encounter vertices which are part of the + // current edge. + // We do not want them to be part of the edge neighbors. + unsigned e_id = this->c_->ith_nbh_edge(this->i_); + while (e_id == this->c_->id()) + { + this->i_ = next_id_(); + e_id = this->c_->ith_nbh_edge(this->i_); + } + + this->p_.update_id(e_id); + } + +# endif // !MLN_INCLUDE_ONLY + + } // End of namespace mln::internal + +} // End of namespace mln + + +#endif // !MLN_UTIL_INTERNAL_GRAPH_VERTEX_NBH_VERTEX_ITER_HH + diff --git a/milena/mln/util/internal/graph_nbh_iter_base.hh b/milena/mln/util/internal/graph_nbh_iter_base.hh new file mode 100644 index 0000000..8cfcdd6 --- /dev/null +++ b/milena/mln/util/internal/graph_nbh_iter_base.hh @@ -0,0 +1,175 @@ +// 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_UTIL_INTERNAL_GRAPH_NBH_ITER_BASE_HH +# define MLN_UTIL_INTERNAL_GRAPH_NBH_ITER_BASE_HH + +# include <mln/core/concept/proxy.hh> + +/// \file mln/util/internal/graph_nbh_iter_base.hh +/// \brief Base implementation for graph edge and vertex neighborhood iterator. + +namespace mln +{ + + namespace internal + { + + template <typename G, typename C, typename P, typename E> + class nbh_iterator_base + : public Proxy< E >, + public internal::proxy_impl< const P&, E > + { + public: + + /// Iterator interface. + /// \{ + /// Test if the iterator is valid. + bool is_valid() const; + /// Invalidate the iterator. + void invalidate(); + + /// Start an iteration. + void start(); + + /// Go to the next value. + void next(); + + /// Return current index + unsigned index() const; + /// \} + + /// Proxy. + /// \{ + /// Proxy subject + const P& subj_(); + /// \} + + protected: + /// Construction and assignment. + /// \{ + template <typename C2> + nbh_iterator_base(const C2& c); + /// \} + + template <typename C2> + void center_at(const C2& c); + + const C* c_; // Center + P p_; + unsigned i_; + }; + +# ifndef MLN_INCLUDE_ONLY + + template <typename G, typename C, typename P, typename E> + template <typename C2> + inline + nbh_iterator_base<G, C, P, E>::nbh_iterator_base(const C2& c) + : p_(c.g()), i_(0) + { + //FIXME: Check if typeof(e.g()) == G + center_at(c); + } + + template <typename G, typename C, typename P, typename E> + inline + bool + nbh_iterator_base<G, C, P, E>::is_valid() const + { + return exact(this)->is_valid_(); + } + + template <typename G, typename C, typename P, typename E> + inline + void + nbh_iterator_base<G, C, P, E>::invalidate() + { + exact(this)->invalidate_(); + } + + template <typename G, typename C, typename P, typename E> + inline + void + nbh_iterator_base<G, C, P, E>::start() + { + i_ = exact(this)->start_id_(); + if (is_valid()) + exact(this)->update_(); + } + + template <typename G, typename C, typename P, typename E> + inline + void + nbh_iterator_base<G, C, P, E>::next() + { + mln_precondition(is_valid()); + mln_precondition(c_->is_valid()); + + i_ = exact(this)->next_id_(); + if (is_valid()) + exact(this)->update_(); + } + + template <typename G, typename C, typename P, typename E> + inline + unsigned + nbh_iterator_base<G, C, P, E>::index() const + { + return i_; + } + + template <typename G, typename C, typename P, typename E> + inline + const P& + nbh_iterator_base<G, C, P, E>::subj_() + { + return p_; + } + + template <typename G, typename C, typename P, typename E> + template <typename C2> + inline + void + nbh_iterator_base<G, C, P, E>::center_at(const C2& c) + { + internal::get_adr(c_, c); + mln_precondition(c_ != 0); + + invalidate(); + } + +# endif // !MLN_INCLUDE_ONLY + + } // End of namespace mln::internal + +} // End of namespace mln + + +#endif // !MLN_UTIL_INTERNAL_GRAPH_NBH_ITER_BASE_HH + + diff --git a/milena/mln/util/internal/graph_vertex_iter.hh b/milena/mln/util/internal/graph_vertex_iter.hh deleted file mode 100644 index d77611f..0000000 --- a/milena/mln/util/internal/graph_vertex_iter.hh +++ /dev/null @@ -1,286 +0,0 @@ -// 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_UTIL_INTERNAL_GRAPH_VERTEX_ITER_HH -# define MLN_UTIL_INTERNAL_GRAPH_VERTEX_ITER_HH - -# include <mln/metal/const.hh> -# include <mln/core/concept/iterator.hh> -# include <mln/core/concept/proxy.hh> -# include <mln/util/internal/graph_base.hh> - -/// \file mln/util/internal/graph_vertex_iter.hh -/// \brief Implementation for graph vertex iterators. - -namespace mln -{ - - namespace internal - { - - template<typename G> - class vertex_fwd_iterator - : public Proxy< vertex_fwd_iterator<G> >, - public proxy_impl< const util::vertex<G>&, vertex_fwd_iterator<G> > - { - public: - /// Constructors. - /// \{ - vertex_fwd_iterator(); - vertex_fwd_iterator(const G& g); - /// \} - - /// Iterator interface. - /// \{ - /// Test if the iterator is valid. - bool is_valid() const; - /// Invalidate the iterator. - void invalidate(); - - /// Start an iteration. - void start(); - - /// Go to the next value. - void next(); - - /// Return current index - unsigned index() const; - /// \} - - void update_graph(const G& g); - - /// Proxy. - /// \{ - /// Proxy subject - const util::vertex<G>& subj_(); - /// \} - - protected: - util::vertex<G> v_; - }; - - template<typename G> - class vertex_bkd_iterator - : public Proxy< vertex_bkd_iterator<G> >, - public proxy_impl< const util::vertex<G>&, vertex_fwd_iterator<G> > - { - public: - /// Constructors. - /// \{ - vertex_bkd_iterator(); - vertex_bkd_iterator(const G& g); - /// \} - - /// Iterator interface. - /// \{ - /// Test if the iterator is valid. - bool is_valid() const; - /// Invalidate the iterator. - void invalidate(); - - /// Start an iteration. - void start(); - - /// Go to the next value. - void next(); - - void update_graph(const G& g); - - /// Return current index - unsigned index() const; - /// \} - - /// Proxy. - /// \{ - /// Proxy subject - const util::vertex<G>& subj_(); - /// \} - - protected: - util::vertex<G> v_; - }; - - -# ifndef MLN_INCLUDE_ONLY - - /*--------------------` - | vertex_fwd_iterator | - \--------------------*/ - - template<typename G> - inline - vertex_fwd_iterator<G>::vertex_fwd_iterator() - { - } - - template<typename G> - inline - vertex_fwd_iterator<G>::vertex_fwd_iterator(const G& g) - { - update_graph(g); - invalidate(); - } - - template<typename G> - inline - bool - vertex_fwd_iterator<G>::is_valid() const - { - return v_.is_valid(); - } - - template<typename G> - inline - void - vertex_fwd_iterator<G>::invalidate() - { - v_.update_id(v_.g().v_nmax()); - } - - template<typename G> - inline - void - vertex_fwd_iterator<G>::start() - { - v_.update_id(0); - } - - template<typename G> - inline - void - vertex_fwd_iterator<G>::next() - { - v_.update_id(v_.id() + 1); - } - - template<typename G> - inline - void - vertex_fwd_iterator<G>::update_graph(const G& g) - { - v_ = util::vertex<G>(g); - } - - template<typename G> - inline - unsigned - vertex_fwd_iterator<G>::index() const - { - return v_.id(); - } - - template<typename G> - inline - const util::vertex<G>& - vertex_fwd_iterator<G>::subj_() - { - return v_; - } - - - /*--------------------` - | vertex_bkd_iterator | - \--------------------*/ - - template<typename G> - inline - vertex_bkd_iterator<G>::vertex_bkd_iterator() - { - } - - template<typename G> - inline - vertex_bkd_iterator<G>::vertex_bkd_iterator(const G& g) - { - update_graph(g); - invalidate(); - } - - template<typename G> - inline - bool - vertex_bkd_iterator<G>::is_valid() const - { - return v_.is_valid(); - } - - template<typename G> - inline - void - vertex_bkd_iterator<G>::invalidate() - { - v_.update_id(v_.g().v_nmax()); - } - - template<typename G> - inline - void - vertex_bkd_iterator<G>::start() - { - v_.update_id(v_.g().v_nmax() - 1); - } - - template<typename G> - inline - void - vertex_bkd_iterator<G>::next() - { - v_.update_id(v_.id() - 1); - } - - template<typename G> - inline - void - vertex_bkd_iterator<G>::update_graph(const G& g) - { - v_ = util::vertex<G>(g); - } - - template<typename G> - inline - unsigned - vertex_bkd_iterator<G>::index() const - { - return v_.id(); - } - - template<typename G> - inline - const util::vertex<G>& - vertex_bkd_iterator<G>::subj_() - { - return v_; - } -# endif // !MLN_INCLUDE_ONLY - - } // End of namespace mln::internal - -} // End of namespace mln - - -#endif // !MLN_UTIL_INTERNAL_GRAPH_VERTEX_ITER_HH - diff --git a/milena/mln/util/internal/graph_vertex_nbh_edge_iter.hh b/milena/mln/util/internal/graph_vertex_nbh_edge_iter.hh deleted file mode 100644 index 634dc07..0000000 --- a/milena/mln/util/internal/graph_vertex_nbh_edge_iter.hh +++ /dev/null @@ -1,323 +0,0 @@ -// 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_UTIL_INTERNAL_GRAPH_VERTEX_NBH_EDGE_ITER_HH -# define MLN_UTIL_INTERNAL_GRAPH_VERTEX_NBH_EDGE_ITER_HH - -# include <mln/core/concept/proxy.hh> - -/// \file mln/util/internal/graph_vertex_nbh_edge_iter.hh -/// \brief Implementation for graph edge iterators centered to a vertex. - -namespace mln -{ - - namespace internal - { - - template <typename G> - class vertex_nbh_edge_fwd_iterator - : public Proxy< vertex_nbh_edge_fwd_iterator<G> >, - public internal::proxy_impl< const util::edge<G>&, vertex_nbh_edge_fwd_iterator<G> > - { - public: - /// Construction and assignment. - /// \{ - template <typename C> - vertex_nbh_edge_fwd_iterator(const C& c); - /// \} - - /// Iterator interface. - /// \{ - /// Test if the iterator is valid. - bool is_valid() const; - /// Invalidate the iterator. - void invalidate(); - - /// Start an iteration. - void start(); - - /// Go to the next value. - void next(); - - /// Return current index - unsigned index() const; - /// \} - - /// Proxy. - /// \{ - /// Proxy subject - const util::edge<G>& subj_(); - /// \} - - protected: - void update_(); - - template <typename C> - void center_at(const C& c); - - const util::vertex<G>* c_; // Center - util::edge<G> e_; - unsigned i_; - }; - - template <typename G> - class vertex_nbh_edge_bkd_iterator - : public Proxy< vertex_nbh_edge_bkd_iterator<G> >, - public proxy_impl< const util::edge<G>&, vertex_nbh_edge_bkd_iterator<G> > - { - public: - /// Constructors. - /// \{ - template <typename C> - vertex_nbh_edge_bkd_iterator(const C& c); - /// \} - - /// Iterator interface. - /// \{ - /// Test if the iterator is valid. - bool is_valid() const; - /// Invalidate the iterator. - void invalidate(); - - /// Start an iteration. - void start(); - - /// Go to the next value. - void next(); - - /// Return current index - unsigned index() const; - /// \} - - /// Proxy. - /// \{ - /// Proxy subject - const util::edge<G>& subj_(); - /// \} - - protected: - void update_(); - - template <typename C> - void center_at(const C& c); - - const util::vertex<G>* c_; //Center - util::edge<G> e_; - unsigned i_; - }; - - -# ifndef MLN_INCLUDE_ONLY - - template <typename G> - template <typename C> - inline - vertex_nbh_edge_fwd_iterator<G>::vertex_nbh_edge_fwd_iterator(const C& c) - : e_(c.g()), i_(0) - { - //FIXME: Check if typeof(v.g()) == G - center_at(c); - } - - template <typename G> - inline - bool - vertex_nbh_edge_fwd_iterator<G>::is_valid() const - { - return i_ < c_->nmax_nbh_edges(); - } - - template <typename G> - inline - void - vertex_nbh_edge_fwd_iterator<G>::invalidate() - { - i_ = e_.g().e_nmax(); - } - - template <typename G> - inline - void - vertex_nbh_edge_fwd_iterator<G>::start() - { - i_ = 0; - if (is_valid()) - update_(); - } - - template <typename G> - inline - void - vertex_nbh_edge_fwd_iterator<G>::next() - { - ++i_; - if (is_valid()) - update_(); - } - - template <typename G> - inline - unsigned - vertex_nbh_edge_fwd_iterator<G>::index() const - { - return i_; - } - - template <typename G> - inline - const util::edge<G>& - vertex_nbh_edge_fwd_iterator<G>::subj_() - { - return e_; - } - - template <typename G> - inline - void - vertex_nbh_edge_fwd_iterator<G>::update_() - { - mln_precondition(is_valid()); - mln_precondition(c_->is_valid()); - e_.update_id(c_->ith_nbh_edge(i_)); - } - - template <typename G> - template <typename C> - inline - void - vertex_nbh_edge_fwd_iterator<G>::center_at(const C& c) - { - internal::get_adr(c_, c); - mln_precondition(c_ != 0); - - invalidate(); - } - - - - - /*-----------------------------` - | vertex_nbh_edge_bkd_iterator | - \-----------------------------*/ - - - template <typename G> - template <typename C> - inline - vertex_nbh_edge_bkd_iterator<G>::vertex_nbh_edge_bkd_iterator(const C& c) - : e_(c.g()), i_(0) - { - //FIXME: Check if typeof(v.g()) == G - center_at(c); - } - - template <typename G> - inline - bool - vertex_nbh_edge_bkd_iterator<G>::is_valid() const - { - return i_ < c_->nmax_nbh_edges(); - } - - template <typename G> - inline - void - vertex_nbh_edge_bkd_iterator<G>::invalidate() - { - e_.update_id(e_.g().e_nmax()); - } - - template <typename G> - inline - void - vertex_nbh_edge_bkd_iterator<G>::start() - { - i_ = c_->nmax_nbh_edges() - 1; - if (is_valid()) - update_(); - } - - template <typename G> - inline - void - vertex_nbh_edge_bkd_iterator<G>::next() - { - --i_; - if (is_valid()) - update_(); - } - - template <typename G> - inline - unsigned - vertex_nbh_edge_bkd_iterator<G>::index() const - { - return i_; - } - - template <typename G> - inline - const util::edge<G>& - vertex_nbh_edge_bkd_iterator<G>::subj_() - { - return e_; - } - - template <typename G> - inline - void - vertex_nbh_edge_bkd_iterator<G>::update_() - { - mln_precondition(is_valid()); - mln_precondition(c_->is_valid()); - e_.update_id(c_->ith_nbh_edge(i_)); - } - - template <typename G> - template <typename C> - inline - void - vertex_nbh_edge_bkd_iterator<G>::center_at(const C& c) - { - internal::get_adr(c_, c); - mln_precondition(c_ != 0); - - invalidate(); - } - - - -# endif // !MLN_INCLUDE_ONLY - - } // End of namespace mln::internal - -} // End of namespace mln - - -#endif // !MLN_UTIL_INTERNAL_GRAPH_NBH_EDGE_ITER_HH - diff --git a/milena/mln/util/internal/graph_vertex_nbh_vertex_iter.hh b/milena/mln/util/internal/graph_vertex_nbh_vertex_iter.hh deleted file mode 100644 index 0dc87b5..0000000 --- a/milena/mln/util/internal/graph_vertex_nbh_vertex_iter.hh +++ /dev/null @@ -1,320 +0,0 @@ -// 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_UTIL_INTERNAL_GRAPH_VERTEX_NBH_VERTEX_ITER_HH -# define MLN_UTIL_INTERNAL_GRAPH_VERTEX_NBH_VERTEX_ITER_HH - -# include <mln/core/concept/proxy.hh> - -/// \file mln/util/internal/graph_vertex_nbh_vertex_iter.hh -/// \brief Implementation for graph vertex iterators centered to a vertex. - -namespace mln -{ - - namespace internal - { - - template <typename G> - class vertex_nbh_vertex_fwd_iterator - : public Proxy< vertex_nbh_vertex_fwd_iterator<G> >, - public internal::proxy_impl< const util::vertex<G>&, vertex_nbh_vertex_fwd_iterator<G> > - { - public: - /// Construction and assignment. - /// \{ - template <typename C> - vertex_nbh_vertex_fwd_iterator(const C& c); - /// \} - - /// 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 value. - void next(); - - /// Return current index - unsigned index() const; - - /// Proxy. - /// \{ - /// Proxy subject - const util::vertex<G>& subj_(); - /// \} - - protected: - void update_(); - - template <typename C> - void center_at(const C& c); - - const util::vertex<G>* c_; - util::vertex<G> v_; - unsigned i_; - }; - - template <typename G> - class vertex_nbh_vertex_bkd_iterator - : public Proxy< vertex_nbh_vertex_bkd_iterator<G> >, - public proxy_impl< const util::vertex<G>&, vertex_nbh_vertex_fwd_iterator<G> > - { - public: - /// Constructors. - /// \{ - template <typename C> - vertex_nbh_vertex_bkd_iterator(const C& v); - /// \} - - /// 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 value. - void next(); - - /// Return current index - unsigned index() const; - /// \} - - /// Proxy. - /// \{ - /// Proxy subject - const util::vertex<G>& subj_(); - /// \} - - protected: - void update_(); - - template <typename C> - void center_at(const C& c); - - const util::vertex<G>* c_; //Center - util::vertex<G> v_; - unsigned i_; - }; - - -# ifndef MLN_INCLUDE_ONLY - - - template <typename G> - template <typename C> - inline - vertex_nbh_vertex_fwd_iterator<G>::vertex_nbh_vertex_fwd_iterator(const C& c) - : v_(c.g()), i_(0) - { - //FIXME: Check if typeof(v.g()) == G - center_at(c); - } - - template <typename G> - inline - bool - vertex_nbh_vertex_fwd_iterator<G>::is_valid() const - { - return i_ < c_->nmax_nbh_vertices(); - } - - template <typename G> - inline - void - vertex_nbh_vertex_fwd_iterator<G>::invalidate() - { - i_ = v_.g().v_nmax(); - } - - template <typename G> - inline - void - vertex_nbh_vertex_fwd_iterator<G>::start() - { - i_ = 0; - if (is_valid()) - update_(); - } - - template <typename G> - inline - void - vertex_nbh_vertex_fwd_iterator<G>::next() - { - ++i_; - if (is_valid()) - update_(); - } - - template <typename G> - inline - unsigned - vertex_nbh_vertex_fwd_iterator<G>::index() const - { - return i_; - } - - template <typename G> - inline - const util::vertex<G>& - vertex_nbh_vertex_fwd_iterator<G>::subj_() - { - return v_; - } - - template <typename G> - inline - void - vertex_nbh_vertex_fwd_iterator<G>::update_() - { - mln_precondition(is_valid()); - mln_precondition(c_->is_valid()); - v_.update_id(c_->ith_nbh_vertex(i_)); - } - - template <typename G> - template <typename C> - inline - void - vertex_nbh_vertex_fwd_iterator<G>::center_at(const C& c) - { - internal::get_adr(c_, c); - mln_precondition(c_ != 0); - - invalidate(); - } - - - /*-------------------------------` - | vertex_nbh_vertex_bkd_iterator | - \-------------------------------*/ - - - template <typename G> - template <typename C> - inline - vertex_nbh_vertex_bkd_iterator<G>::vertex_nbh_vertex_bkd_iterator(const C& c) - : v_(c.g()), i_(0) - { - //FIXME: Check if typeof(v.g()) == G - center_at(c); - } - - template <typename G> - inline - bool - vertex_nbh_vertex_bkd_iterator<G>::is_valid() const - { - return i_ < c_->nmax_nbh_vertices(); - } - - template <typename G> - inline - void - vertex_nbh_vertex_bkd_iterator<G>::invalidate() - { - v_.update_id(v_.g().e_nmax()); - } - - template <typename G> - inline - void - vertex_nbh_vertex_bkd_iterator<G>::start() - { - i_ = c_->nmax_nbh_edges() - 1; - if (is_valid()) - update_(); - } - - template <typename G> - inline - void - vertex_nbh_vertex_bkd_iterator<G>::next() - { - --i_; - if (is_valid()) - update_(); - } - - template <typename G> - inline - unsigned - vertex_nbh_vertex_bkd_iterator<G>::index() const - { - return i_; - } - - template <typename G> - inline - const util::vertex<G>& - vertex_nbh_vertex_bkd_iterator<G>::subj_() - { - return v_; - } - - template <typename G> - inline - void - vertex_nbh_vertex_bkd_iterator<G>::update_() - { - mln_precondition(is_valid()); - mln_precondition(c_->is_valid()); - v_.update_id(c_->ith_nbh_vertex(i_)); - } - - template <typename G> - template <typename C> - inline - void - vertex_nbh_vertex_bkd_iterator<G>::center_at(const C& c) - { - internal::get_adr(c_, c); - mln_precondition(c_ != 0); - - invalidate(); - } - -# endif // !MLN_INCLUDE_ONLY - - } // End of namespace mln::internal - -} // End of namespace mln - - -#endif // !MLN_UTIL_INTERNAL_GRAPH_VERTEX_NBH_VERTEX_ITER_HH - -- 1.5.6.5