
* mln/core/image/graph_window_piter.hh: update comments. * mln/core/internal/graph_window_base.hh: fix the site typedef. * mln/core/site_set/p_vertices.hh, * mln/core/site_set/p_edges.hh: add a default constructor. Holds the graph and not a pointer anymore. * mln/core/site_set/p_vertices_psite.hh, * mln/core/site_set/p_edges_psite.hh: add new accessors and a specialization of subject_impl. * mln/debug/draw_graph.hh: add a new prototype to draw a graph from a p_edges. * mln/util/vertex.hh, * mln/util/edge.hh: add a new conversion operator towards a graph element id. * mln/util/internal/graph_nbh_iter.hh, * mln/util/internal/graph_iter.hh: some renaming. * mln/util/internal/graph_nbh_iter_base.hh, * mln/util/internal/graph_iter_base.hh: add new accessors. --- milena/ChangeLog | 29 +++++ milena/mln/core/image/graph_window_piter.hh | 4 +- milena/mln/core/internal/graph_window_base.hh | 3 +- milena/mln/core/site_set/p_edges.hh | 28 ++++-- milena/mln/core/site_set/p_edges_psite.hh | 92 ++++++++++++++++- milena/mln/core/site_set/p_vertices.hh | 32 +++--- milena/mln/core/site_set/p_vertices_psite.hh | 52 +++++++++- milena/mln/debug/draw_graph.hh | 24 +++++ milena/mln/util/edge.hh | 10 ++ milena/mln/util/internal/graph_iter.hh | 16 +-- milena/mln/util/internal/graph_iter_base.hh | 21 ++++ milena/mln/util/internal/graph_nbh_iter.hh | 12 +- milena/mln/util/internal/graph_nbh_iter_base.hh | 125 +++++++++++++++++------ milena/mln/util/vertex.hh | 10 ++ 14 files changed, 377 insertions(+), 81 deletions(-) diff --git a/milena/ChangeLog b/milena/ChangeLog index 4d6d70f..0541e7e 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,34 @@ 2008-12-31 Guillaume Lazzara <z@lrde.epita.fr> + Fix/improve graph related classes. + + * mln/core/image/graph_window_piter.hh: update comments. + + * mln/core/internal/graph_window_base.hh: fix the site typedef. + + * mln/core/site_set/p_vertices.hh, + * mln/core/site_set/p_edges.hh: add a default constructor. Holds the + graph and not a pointer anymore. + + * mln/core/site_set/p_vertices_psite.hh, + * mln/core/site_set/p_edges_psite.hh: add new accessors and a + specialization of subject_impl. + + * mln/debug/draw_graph.hh: add a new prototype to draw a graph from a + p_edges. + + * mln/util/vertex.hh, + * mln/util/edge.hh: add a new conversion operator towards a graph + element id. + + * mln/util/internal/graph_nbh_iter.hh, + * mln/util/internal/graph_iter.hh: some renaming. + + * mln/util/internal/graph_nbh_iter_base.hh, + * mln/util/internal/graph_iter_base.hh: add new accessors. + +2008-12-31 Guillaume Lazzara <z@lrde.epita.fr> + Various small fixes. * mln/accu/count_adjacent_vertices.hh: add missing is_valid(). diff --git a/milena/mln/core/image/graph_window_piter.hh b/milena/mln/core/image/graph_window_piter.hh index a6b29e3..0bd341e 100644 --- a/milena/mln/core/image/graph_window_piter.hh +++ b/milena/mln/core/image/graph_window_piter.hh @@ -77,11 +77,11 @@ namespace mln /// Go to the next point. void do_next_(); - /// Set the reference psite. + /// Do some work while setting the reference site. template <typename Pref> void center_at_(const Pref& c); - /// Set the reference psite. + /// Do some work while setting the reference site. template <typename I2> void center_at_(const p_graph_piter<S, I2>& c); diff --git a/milena/mln/core/internal/graph_window_base.hh b/milena/mln/core/internal/graph_window_base.hh index a72472c..8af7d65 100644 --- a/milena/mln/core/internal/graph_window_base.hh +++ b/milena/mln/core/internal/graph_window_base.hh @@ -37,6 +37,7 @@ namespace mln { + /// \tparam P Site type. template <typename P, typename E> class graph_window_base : public Window<E> { @@ -46,7 +47,7 @@ namespace mln /// Associated types. /// \{ /// The type of site corresponding to the window. - typedef mln_site(P) site; + typedef P site; // FIXME: This is a dummy value. typedef void dpsite; diff --git a/milena/mln/core/site_set/p_edges.hh b/milena/mln/core/site_set/p_edges.hh index b1d46f2..a987e73 100644 --- a/milena/mln/core/site_set/p_edges.hh +++ b/milena/mln/core/site_set/p_edges.hh @@ -87,6 +87,8 @@ namespace mln /// \param gr The graph upon which the graph edge psite set is built. /// \param f the function mapping edges and sites. p_edges(const G& gr, const F& f); + /// Default constructor. + p_edges(); /// Associated types. /// \{ @@ -106,7 +108,7 @@ namespace mln typedef fwd_piter piter; /// \} - /// \brief Return The number of points (sites) of the set, i.e., + /// Return The number of points (sites) of the set, i.e., /// the number of \em edges. unsigned nsites() const; @@ -138,12 +140,12 @@ namespace mln private: - const G* g_; + G g_; F f_; }; - /// \brief Comparison between two mln::p_edges's. + /// Comparison between two mln::p_edges's. /// /// Two mln::p_edges's are considered equal if they share the /// same graph. @@ -152,7 +154,7 @@ namespace mln operator==(const p_edges<G, F>& lhs, const p_edges<G, F>& rhs); - /// \brief Inclusion of a mln::p_edges in another one. + /// Inclusion of a mln::p_edges in another one. /// /// \todo Refine this later, when we are able to express subgraph /// relations. @@ -171,7 +173,13 @@ namespace mln template <typename G, typename F> inline p_edges<G, F>::p_edges(const G& g, const F& f) - : g_ (&g), f_(f) + : g_ (g), f_(f) + { + } + + template <typename G, typename F> + inline + p_edges<G, F>::p_edges() { } @@ -188,7 +196,7 @@ namespace mln unsigned p_edges<G, F>::nedges() const { - return this->g_->e_nmax(); + return this->g_.e_nmax(); } template <typename G, typename F> @@ -196,7 +204,7 @@ namespace mln bool p_edges<G, F>::is_valid() const { - return g_ != 0; + return true;/* FIXME: g.is_valid(); */ } template <typename G, typename F> @@ -204,7 +212,7 @@ namespace mln void p_edges<G, F>::invalidate() { - g_ = 0; + /* FIXME: g.invalidate(); */ } template <typename G, typename F> @@ -223,7 +231,7 @@ namespace mln p_edges<G, F>::has(const util::edge<G2>& e) const { mln_precondition(is_valid()); - return e.graph().is_subgraph_of(*g_) && g_->has(e) && e.is_valid(); + return e.graph().is_subgraph_of(g_) && g_.has(e) && e.is_valid(); } template <typename G, typename F> @@ -242,7 +250,7 @@ namespace mln p_edges<G, F>::graph() const { mln_precondition(is_valid()); - return *g_; + return g_; } template <typename G, typename F> diff --git a/milena/mln/core/site_set/p_edges_psite.hh b/milena/mln/core/site_set/p_edges_psite.hh index 8742b61..902910d 100644 --- a/milena/mln/core/site_set/p_edges_psite.hh +++ b/milena/mln/core/site_set/p_edges_psite.hh @@ -41,6 +41,8 @@ namespace mln // Forward declaration. template <typename G, typename F> class p_edges; + namespace util { template <typename G> class vertex; } + namespace internal { template <typename T, typename E> struct subject_impl; } template <typename G, typename F> @@ -63,11 +65,39 @@ namespace mln /// \{ /// Return the underlying edge. const util::edge<G>& e() const; + util::vertex<G> v1() const; + util::vertex<G> v2() const; /// \} }; + namespace internal + { + + /// Subject_impl (Proxy) + + template <typename G, typename F, typename E> + struct subject_impl< const p_edges_psite<G,F>&, E > + : subject_impl< const graph_psite_base< p_edges<G,F>, + p_edges_psite<G,F> >&, E > + { + const util::edge<G>& e() const; + util::vertex<G> v1() const; + util::vertex<G> v2() const; + private: + const E& exact_() const; + }; + + template <typename G, typename F, typename E> + struct subject_impl< p_edges_psite<G,F>&, E > + : subject_impl< const p_edges_psite<G,F>&, E >, + subject_impl< graph_psite_base< p_edges<G,F>, + p_edges_psite<G,F> >&, E > + { + }; + + } // end of namespace mln::internal # ifndef MLN_INCLUDE_ONLY @@ -76,21 +106,21 @@ namespace mln p_edges_psite<G, F>::p_edges_psite() { } - + template <typename G, typename F> inline p_edges_psite<G, F>::p_edges_psite(const p_edges<G,F>& s) : super_(s) { } - + template <typename G, typename F> inline p_edges_psite<G, F>::p_edges_psite(const p_edges<G,F>& s, unsigned id) : super_(s, id) { } - + template <typename G, typename F> inline const util::edge<G>& @@ -99,6 +129,62 @@ namespace mln return this->elt_; } + template <typename G, typename F> + inline + util::vertex<G> + p_edges_psite<G, F>::v1() const + { + return this->elt_.graph().vertex(this->elt_.v1()); + } + + template <typename G, typename F> + inline + util::vertex<G> + p_edges_psite<G, F>::v2() const + { + return this->elt_.graph().vertex(this->elt_.v2()); + } + + + namespace internal + { + + /// subject_impl (Proxy) + + template <typename G, typename F, typename E> + inline + const E& + subject_impl< const p_edges_psite<G,F>&, E >::exact_() const + { + return internal::force_exact<const E>(*this); + } + + template <typename G, typename F, typename E> + inline + const util::edge<G>& + subject_impl< const p_edges_psite<G,F>&, E >::e() const + { + return exact_().get_subject().e(); + } + + template <typename G, typename F, typename E> + inline + util::vertex<G> + subject_impl< const p_edges_psite<G,F>&, E >::v1() const + { + return exact_().get_subject().v1(); + } + + template <typename G, typename F, typename E> + inline + util::vertex<G> + subject_impl< const p_edges_psite<G,F>&, E >::v2() const + { + return exact_().get_subject().v2(); + } + + } // end of namespace mln::internal + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln diff --git a/milena/mln/core/site_set/p_vertices.hh b/milena/mln/core/site_set/p_vertices.hh index adbe55d..0ebab63 100644 --- a/milena/mln/core/site_set/p_vertices.hh +++ b/milena/mln/core/site_set/p_vertices.hh @@ -145,9 +145,9 @@ namespace mln /// Return the value associated to an element of this site set. /// \{ - const mln_result(F)& operator()(const psite& p) const; - const mln_result(F)& operator()(const util::vertex<G>& p) const; - const mln_result(F)& operator()(unsigned id_v) const; + mln_result(F) operator()(const psite& p) const; + mln_result(F) operator()(const util::vertex<G>& p) const; + mln_result(F) operator()(unsigned id_v) const; /// \} /// Accessors. @@ -159,7 +159,7 @@ namespace mln /// \} private: - const G* g_; + G g_; F f_; }; @@ -202,7 +202,7 @@ namespace mln template <typename G, typename F> inline p_vertices<G,F>::p_vertices(const G& g, const F& f) - : g_ (&g), f_(f) + : g_ (g), f_(f) { } @@ -219,7 +219,7 @@ namespace mln unsigned p_vertices<G,F>::nvertices() const { - return this->g_->v_nmax(); + return this->g_.v_nmax(); } template <typename G, typename F> @@ -227,7 +227,7 @@ namespace mln bool p_vertices<G,F>::is_valid() const { - return g_ != 0; + return true; /* FIXME: g_.is_valid() */; } template <typename G, typename F> @@ -235,7 +235,7 @@ namespace mln void p_vertices<G,F>::invalidate() { - g_ = 0; + /* FIXME: g_.invalidate() ;*/ } template <typename G, typename F> @@ -256,7 +256,7 @@ namespace mln mln_precondition(is_valid()); return // Check whether P is compatible with this psite set. - (p.graph() == *g_) && + (p.graph() == g_) && // Check that the vertex id of P belongs to the range of valid // vertex ids. (p.is_valid()); @@ -274,7 +274,7 @@ namespace mln template <typename G, typename F> inline - const mln_result(F)& + mln_result(F) p_vertices<G,F>::operator()(const psite& p) const { mln_precondition(g_.has(p.v())); @@ -283,19 +283,19 @@ namespace mln template <typename G, typename F> inline - const mln_result(F)& + mln_result(F) p_vertices<G,F>::operator()(const util::vertex<G>& v) const { - mln_precondition(g_->has_v(v)); + mln_precondition(g_.has_v(v)); return (*this)(v.id()); } template <typename G, typename F> inline - const mln_result(F)& + mln_result(F) p_vertices<G,F>::operator()(unsigned id_v) const { - mln_precondition(g_->has_v(id_v)); + mln_precondition(g_.has_v(id_v)); return f_(id_v); } @@ -305,7 +305,7 @@ namespace mln p_vertices<G,F>::graph() const { mln_precondition(is_valid()); - return *g_; + return g_; } template <typename G, typename F> @@ -320,7 +320,7 @@ namespace mln bool operator==(const p_vertices<G,F>& lhs, const p_vertices<G,F>& rhs) { - return (*lhs.g_) == (*rhs.g_); + return (lhs.g_) == (rhs.g_); } template <typename G, typename F> diff --git a/milena/mln/core/site_set/p_vertices_psite.hh b/milena/mln/core/site_set/p_vertices_psite.hh index 5a5da0d..883eb5c 100644 --- a/milena/mln/core/site_set/p_vertices_psite.hh +++ b/milena/mln/core/site_set/p_vertices_psite.hh @@ -42,12 +42,11 @@ namespace mln // Forward declaration. template <typename G, typename F> class p_vertices; - + namespace internal { template <typename Subject, typename E> struct subject_impl; } template <typename G, typename F> class p_vertices_psite : - public internal::graph_psite_base< p_vertices<G,F>, p_vertices_psite<G,F> > { typedef p_vertices_psite<G,F> self_; @@ -63,6 +62,31 @@ namespace mln }; + namespace internal + { + + /// Subject_impl (Proxy) + + template <typename G, typename F, typename E> + struct subject_impl< const p_vertices_psite<G,F>&, E > + : subject_impl< const graph_psite_base< p_vertices<G,F>, + p_vertices_psite<G,F> >&, E > + { + const util::vertex<G>& v() const; + + private: + const E& exact_() const; + }; + + template <typename G, typename F, typename E> + struct subject_impl< p_vertices_psite<G,F>&, E > + : subject_impl< const p_vertices_psite<G,F>&, E >, + subject_impl< graph_psite_base< p_vertices<G,F>, + p_vertices_psite<G,F> >&, E > + { + }; + + } // end of namespace mln::internal # ifndef MLN_INCLUDE_ONLY @@ -94,6 +118,30 @@ namespace mln return this->elt_; } + + namespace internal + { + + /// subject_impl (Proxy) + + template <typename G, typename F, typename E> + inline + const E& + subject_impl< const p_vertices_psite<G,F>&, E >::exact_() const + { + return internal::force_exact<const E>(*this); + } + + template <typename G, typename F, typename E> + inline + const util::vertex<G>& + subject_impl< const p_vertices_psite<G,F>&, E >::v() const + { + return exact_().get_subject().v(); + } + + } // end of namespace mln::internal + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln diff --git a/milena/mln/debug/draw_graph.hh b/milena/mln/debug/draw_graph.hh index 114f57b..abc96a4 100644 --- a/milena/mln/debug/draw_graph.hh +++ b/milena/mln/debug/draw_graph.hh @@ -88,6 +88,30 @@ namespace mln inline void draw_graph(Image<I>& ima, + const p_edges<G, F>& pe, + mln_value(I) vertex_v, + mln_value(I) edge_v) + { + // Draw edges. + typedef p_edges<G, F> pe_t; + mln_piter(pe_t) p(pe); + for_all(p) + { + if (exact(ima).has(p.first()) && exact(ima).has(p.second())) + draw::line(exact(ima), p.first(), p.second(), edge_v); + if (exact(ima).has(p.first())) + exact(ima)(p.first()) = vertex_v; + if (exact(ima).has(p.second())) + exact(ima)(p.second()) = vertex_v; + } + + } + + + template <typename I, typename G, typename F> + inline + void + draw_graph(Image<I>& ima, const p_vertices<G, F>& pv, mln_value(I) vertex_v, mln_value(I) edge_v) diff --git a/milena/mln/util/edge.hh b/milena/mln/util/edge.hh index 57d4e49..e98370b 100644 --- a/milena/mln/util/edge.hh +++ b/milena/mln/util/edge.hh @@ -76,6 +76,9 @@ namespace mln /// Set id_ with \p id; void update_id(unsigned id); + /// Conversion to the edge id. + operator unsigned() const; + /// Return a reference to the graph holding this edge. const G& graph() const; @@ -219,6 +222,13 @@ namespace mln template <typename G> inline + edge<G>::operator unsigned() const + { + return id_; + } + + template <typename G> + inline const G& edge<G>::graph() const { diff --git a/milena/mln/util/internal/graph_iter.hh b/milena/mln/util/internal/graph_iter.hh index 1e89c5c..6da2e3c 100644 --- a/milena/mln/util/internal/graph_iter.hh +++ b/milena/mln/util/internal/graph_iter.hh @@ -68,7 +68,6 @@ namespace mln /// Called in next(); unsigned next_id_() const; - using super_::p_; friend class graph_iter_base<G, util::vertex<G>, vertex_fwd_iterator<G> >; }; @@ -97,7 +96,6 @@ namespace mln /// Called in next(); unsigned next_id_() const; - using super_::p_; friend class graph_iter_base<G, util::vertex<G>, vertex_bkd_iterator<G> >; }; @@ -126,7 +124,6 @@ namespace mln /// Called in next(); unsigned next_id_() const; - using super_::p_; friend class graph_iter_base<G, util::edge<G>, edge_fwd_iterator<G> >; }; @@ -155,7 +152,6 @@ namespace mln /// Called in next(); unsigned next_id_() const; - using super_::p_; friend class graph_iter_base<G, util::edge<G>, edge_bkd_iterator<G> >; }; @@ -195,7 +191,7 @@ namespace mln unsigned vertex_fwd_iterator<G>::next_id_() const { - return p_.id() + 1; + return this->p_.id() + 1; } @@ -222,7 +218,7 @@ namespace mln unsigned vertex_bkd_iterator<G>::start_id_() const { - return p_.graph().v_nmax() - 1; + return this->p_.graph().v_nmax() - 1; } template <typename G> @@ -230,7 +226,7 @@ namespace mln unsigned vertex_bkd_iterator<G>::next_id_() const { - return p_.id() - 1; + return this->p_.id() - 1; } @@ -265,7 +261,7 @@ namespace mln unsigned edge_fwd_iterator<G>::next_id_() const { - return p_.id() + 1; + return this->p_.id() + 1; } @@ -292,7 +288,7 @@ namespace mln unsigned edge_bkd_iterator<G>::start_id_() const { - return p_.graph().e_nmax() - 1; + return this->p_.graph().e_nmax() - 1; } template <typename G> @@ -300,7 +296,7 @@ namespace mln unsigned edge_bkd_iterator<G>::next_id_() const { - return p_.id() - 1; + return this->p_.id() - 1; } # endif // ! MLN_INCLUDE_ONLY diff --git a/milena/mln/util/internal/graph_iter_base.hh b/milena/mln/util/internal/graph_iter_base.hh index cad716e..10cbe64 100644 --- a/milena/mln/util/internal/graph_iter_base.hh +++ b/milena/mln/util/internal/graph_iter_base.hh @@ -69,11 +69,17 @@ namespace mln /// Conversion operator. Returns the element id. operator unsigned() const; + + /// Conversion operator. Returns the graph element. + operator const Elt&() const; /// \} /// Proxy subject const Elt& subj_(); + /// Return the element pointed by this iterator. + const Elt& p_hook_() const; + protected: graph_iter_base(const G& g); @@ -143,12 +149,27 @@ namespace mln template <typename G, typename Elt, typename E> inline + graph_iter_base<G, Elt, E>::operator const Elt&() const + { + return p_; + } + + template <typename G, typename Elt, typename E> + inline const Elt& graph_iter_base<G, Elt, E>::subj_() { return p_; } + template <typename G, typename Elt, typename E> + inline + const Elt& + graph_iter_base<G, Elt, E>::p_hook_() const + { + return p_; + } + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln::internal diff --git a/milena/mln/util/internal/graph_nbh_iter.hh b/milena/mln/util/internal/graph_nbh_iter.hh index d06a008..b99de7b 100644 --- a/milena/mln/util/internal/graph_nbh_iter.hh +++ b/milena/mln/util/internal/graph_nbh_iter.hh @@ -331,7 +331,7 @@ namespace mln void vertex_nbh_vertex_fwd_iterator<G>::update_() { - this->p_.update_id(this->c_->ith_nbh_vertex(this->i_)); + this->elt_.update_id(this->c_->ith_nbh_vertex(this->i_)); } /*-------------------------------` @@ -381,7 +381,7 @@ namespace mln void vertex_nbh_vertex_bkd_iterator<G>::update_() { - this->p_.update_id(this->c_->ith_nbh_vertex(this->i_)); + this->elt_.update_id(this->c_->ith_nbh_vertex(this->i_)); } @@ -432,7 +432,7 @@ namespace mln void vertex_nbh_edge_fwd_iterator<G>::update_() { - this->p_.update_id(this->c_->ith_nbh_edge(this->i_)); + this->elt_.update_id(this->c_->ith_nbh_edge(this->i_)); } /*-----------------------------` @@ -482,7 +482,7 @@ namespace mln void vertex_nbh_edge_bkd_iterator<G>::update_() { - this->p_.update_id(this->c_->ith_nbh_edge(this->i_)); + this->elt_.update_id(this->c_->ith_nbh_edge(this->i_)); } @@ -545,7 +545,7 @@ namespace mln e_id = this->c_->ith_nbh_edge(this->i_); } - this->p_.update_id(e_id); + this->elt_.update_id(e_id); } /*-----------------------------` @@ -605,7 +605,7 @@ namespace mln e_id = this->c_->ith_nbh_edge(this->i_); } - this->p_.update_id(e_id); + this->elt_.update_id(e_id); } # endif // !MLN_INCLUDE_ONLY diff --git a/milena/mln/util/internal/graph_nbh_iter_base.hh b/milena/mln/util/internal/graph_nbh_iter_base.hh index a28be8b..2654055 100644 --- a/milena/mln/util/internal/graph_nbh_iter_base.hh +++ b/milena/mln/util/internal/graph_nbh_iter_base.hh @@ -31,18 +31,22 @@ # include <mln/core/concept/proxy.hh> /// \file mln/util/internal/graph_nbh_iter_base.hh +/// /// Base implementation for graph edge and vertex neighborhood iterator. namespace mln { + // Forward declaration. + template <typename S> class p_indexed_psite; + namespace internal { - template <typename G, typename C, typename P, typename E> + template <typename G, typename C, typename Elt, typename E> class nbh_iterator_base : public Proxy< E >, - public internal::proxy_impl< const P&, E > + public internal::proxy_impl< const Elt&, E > { public: @@ -65,16 +69,28 @@ namespace mln /// Conversion operator. Returns the element ID. operator unsigned() const; + /// The psite around which this iterator moves. + const C& center() const; + /// Make \p c the center of this iterator. + template <typename S> + void center_at(const p_indexed_psite<S>& c); + template <typename C2> void center_at(const C2& c); + /// Change the graph targeted by this iterator. + void change_target(const G& g); + + /// Hook to the current location. + const Elt& elt_hook_() const; + /// \} /// Proxy. /// \{ /// Proxy subject - const P& subj_(); + const Elt& subj_(); /// \} protected: @@ -86,58 +102,58 @@ namespace mln /// \} const C* c_; // Center - P p_; + Elt elt_; unsigned i_; }; # ifndef MLN_INCLUDE_ONLY - template <typename G, typename C, typename P, typename E> + template <typename G, typename C, typename Elt, typename E> inline - nbh_iterator_base<G, C, P, E>::nbh_iterator_base() + nbh_iterator_base<G,C,Elt,E>::nbh_iterator_base() { } - template <typename G, typename C, typename P, typename E> + template <typename G, typename C, typename Elt, typename E> template <typename C2> inline - nbh_iterator_base<G, C, P, E>::nbh_iterator_base(const C2& c) - : p_(c.graph()), i_(0) + nbh_iterator_base<G,C,Elt,E>::nbh_iterator_base(const C2& c) + : elt_(c.graph()), i_(0) { //FIXME: Check if typeof(c.graph()) == G center_at(c); } - template <typename G, typename C, typename P, typename E> + template <typename G, typename C, typename Elt, typename E> inline bool - nbh_iterator_base<G, C, P, E>::is_valid() const + nbh_iterator_base<G,C,Elt,E>::is_valid() const { return exact(this)->is_valid_(); } - template <typename G, typename C, typename P, typename E> + template <typename G, typename C, typename Elt, typename E> inline void - nbh_iterator_base<G, C, P, E>::invalidate() + nbh_iterator_base<G,C,Elt,E>::invalidate() { i_ = mln_max(unsigned); } - template <typename G, typename C, typename P, typename E> + template <typename G, typename C, typename Elt, typename E> inline void - nbh_iterator_base<G, C, P, E>::start() + nbh_iterator_base<G,C,Elt,E>::start() { i_ = exact(this)->start_id_(); if (is_valid()) exact(this)->update_(); } - template <typename G, typename C, typename P, typename E> + template <typename G, typename C, typename Elt, typename E> inline void - nbh_iterator_base<G, C, P, E>::next() + nbh_iterator_base<G,C,Elt,E>::next() { mln_precondition(is_valid()); mln_precondition(c_->is_valid()); @@ -147,42 +163,89 @@ namespace mln exact(this)->update_(); } - template <typename G, typename C, typename P, typename E> + template <typename G, typename C, typename Elt, typename E> inline unsigned - nbh_iterator_base<G, C, P, E>::index() const + nbh_iterator_base<G,C,Elt,E>::index() const { return i_; } - template <typename G, typename C, typename P, typename E> + template <typename G, typename C, typename Elt, typename E> + inline + nbh_iterator_base<G,C,Elt,E>::operator unsigned() const + { + return elt_.id(); + } + + template <typename G, typename C, typename Elt, typename E> inline - nbh_iterator_base<G, C, P, E>::operator unsigned() const + const C& + nbh_iterator_base<G,C,Elt,E>::center() const { - return p_.id(); + mln_precondition(c_ != 0); + return *c_; } - template <typename G, typename C, typename P, typename E> + template <typename G, typename C, typename Elt, typename E> inline - const P& - nbh_iterator_base<G, C, P, E>::subj_() + const Elt& + nbh_iterator_base<G,C,Elt,E>::subj_() { - return p_; + return elt_; } - template <typename G, typename C, typename P, typename E> + template <typename G, typename C, typename Elt, typename E> + template <typename S> + inline + void + nbh_iterator_base<G,C,Elt,E>::center_at(const p_indexed_psite<S>& c) + { + //FIXME: p_indexed_psite does not have a conversion operator towards a + // p_edges/vertices_psite or a vertex/edge. + c_ = & static_cast< const C& >(c.unproxy_()); + + //FIXME: c_->graph() may not be the right graph! + // The target may not be initialized before this call... + // See core/neighb.hh in center_at(), i.center_at(). + elt_.change_graph(c_->graph()); + + invalidate(); + } + + template <typename G, typename C, typename Elt, typename E> template <typename C2> inline void - nbh_iterator_base<G, C, P, E>::center_at(const C2& c) + nbh_iterator_base<G,C,Elt,E>::center_at(const C2& c) { - internal::get_adr(c_, c); - mln_postcondition(c_ != 0); - p_.change_graph(c.graph()); + mlc_converts_to(C2, const C&)::check(); + c_ = & static_cast< const C& >(exact(c)); + + //FIXME: c_->graph() may not be the right graph! + // The target may not be initialized before this call... + // See core/neighb.hh in center_at(), i.center_at(). + elt_.change_graph(c_->graph()); invalidate(); } + template <typename G, typename C, typename Elt, typename E> + inline + void + nbh_iterator_base<G,C,Elt,E>::change_target(const G& g) + { + elt_.change_graph(g); + } + + template <typename G, typename C, typename Elt, typename E> + inline + const Elt& + nbh_iterator_base<G,C,Elt,E>::elt_hook_() const + { + return elt_; + } + # endif // !MLN_INCLUDE_ONLY } // End of namespace mln::internal diff --git a/milena/mln/util/vertex.hh b/milena/mln/util/vertex.hh index 197dcab..fcb6f5b 100644 --- a/milena/mln/util/vertex.hh +++ b/milena/mln/util/vertex.hh @@ -94,6 +94,9 @@ namespace mln /// Returns the vertex id. unsigned id() const; + /// Conversion to the vertex id. + operator unsigned() const; + protected: G g_; unsigned id_; @@ -292,6 +295,13 @@ namespace mln return id_; } + template<typename G> + inline + vertex<G>::operator unsigned() const + { + return id_; + } + template <typename G> inline -- 1.5.6.5