
* mln/core/image/graph_psite.hh (mln::graph_psite<P>): Inherit from internal::pseudo_site_base_. (mln::graph_psite<P>::super_) (mln::graph_psite<P>::mesh) (mln::graph_psite<P>::point) (mln::graph_psite<P>::dpoint) (mln::graph_psite<P>::coord): Remove typedefs. (mln::graph_psite<P>::dim): Remove enum. (mln::graph_psite<P>::target): New typedef. (mln::graph_psite<P>::graph_psite(const self_&)) (mln::graph_psite<P>::operator=(const self_&)): Remove. (mln::graph_psite<P>::to_psite) (mln::graph_psite<P>::to_point) (mln::graph_psite<P>::operator[]): Remove methods. (mln::graph_psite<P>::graph_psite) (mln::graph_psite<P>::graph_psite(const p_graph<P>&, util::vertex_id)): Update ctors. (mln::graph_psite<P>::is_valid): Update. (mln::graph_psite<P>::invalidate) (mln::graph_psite<P>::update_) (mln::graph_psite<P>::site_set) (mln::graph_psite<P>::target_) (mln::graph_psite<P>::change_target) (mln::graph_psite<P>::subj_): New methods. (mln::graph_psite<P>::id): Rename accessor as... (mln::graph_psite<P>::vertex_id): ...this. (mln::graph_psite<P>::change_vertex_id) (mln::graph_psite<P>::inc_vertex_id) (mln::graph_psite<P>::dec_vertex_id): New methods. (mln::graph_psite<P>::p_): New attribute. (operator!=(const graph_psite<P>&, const graph_psite<P>&)) (operator<<(std::ostream&, const graph_psite<P>&)): New operators. (operator==(const graph_psite<P>&, const graph_psite<P>&)) (operator< (const graph_psite<P>&, const graph_psite<P>&)): Update operators. --- milena/ChangeLog | 47 +++++++ milena/mln/core/image/graph_psite.hh | 227 ++++++++++++++++++++++++--------- 2 files changed, 212 insertions(+), 62 deletions(-) diff --git a/milena/ChangeLog b/milena/ChangeLog index 746a34a..323a1fe 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,52 @@ 2008-09-22 Roland Levillain <roland@lrde.epita.fr> + Update site of mln::p_graph. + + * mln/core/image/graph_psite.hh (mln::graph_psite<P>): Inherit + from internal::pseudo_site_base_. + (mln::graph_psite<P>::super_) + (mln::graph_psite<P>::mesh) + (mln::graph_psite<P>::point) + (mln::graph_psite<P>::dpoint) + (mln::graph_psite<P>::coord): + Remove typedefs. + (mln::graph_psite<P>::dim): Remove enum. + (mln::graph_psite<P>::target): New typedef. + (mln::graph_psite<P>::graph_psite(const self_&)) + (mln::graph_psite<P>::operator=(const self_&)): + Remove. + (mln::graph_psite<P>::to_psite) + (mln::graph_psite<P>::to_point) + (mln::graph_psite<P>::operator[]): + Remove methods. + (mln::graph_psite<P>::graph_psite) + (mln::graph_psite<P>::graph_psite(const p_graph<P>&, util::vertex_id)): + Update ctors. + (mln::graph_psite<P>::is_valid): + Update. + (mln::graph_psite<P>::invalidate) + (mln::graph_psite<P>::update_) + (mln::graph_psite<P>::site_set) + (mln::graph_psite<P>::target_) + (mln::graph_psite<P>::change_target) + (mln::graph_psite<P>::subj_): + New methods. + (mln::graph_psite<P>::id): Rename accessor as... + (mln::graph_psite<P>::vertex_id): ...this. + (mln::graph_psite<P>::change_vertex_id) + (mln::graph_psite<P>::inc_vertex_id) + (mln::graph_psite<P>::dec_vertex_id): + New methods. + (mln::graph_psite<P>::p_): New attribute. + (operator!=(const graph_psite<P>&, const graph_psite<P>&)) + (operator<<(std::ostream&, const graph_psite<P>&)): + New operators. + (operator==(const graph_psite<P>&, const graph_psite<P>&)) + (operator< (const graph_psite<P>&, const graph_psite<P>&)): + Update operators. + +2008-09-22 Roland Levillain <roland@lrde.epita.fr> + Update site set mln::p_graph. * mln/core/site_set/p_graph.hh diff --git a/milena/mln/core/image/graph_psite.hh b/milena/mln/core/image/graph_psite.hh index ef0fedb..0a70497 100644 --- a/milena/mln/core/image/graph_psite.hh +++ b/milena/mln/core/image/graph_psite.hh @@ -29,64 +29,102 @@ # define MLN_CORE_IMAGE_GRAPH_PSITE_HH /// \file mln/core/image/graph_psite.hh -/// \brief Definition of a graph-based point site. +/// \brief Definition of a graph-based psite. -# include <mln/core/concept/point_site.hh> +# include <mln/core/internal/pseudo_site_base.hh> # include <mln/core/site_set/p_graph.hh> +/* FIXME: This class shares a lot with line_graph_psite. Factor as + much as possible. */ + +// FIXME: Rename graph_psite as p_graph_psite, and move this +// to core/site_set. + namespace mln { // Forward declaration. template <typename P> class p_graph; + template <typename P> class graph_psite; /// \brief Point site associated to a mln::graph_image. + /// + /// \arg \p P The type of the site. template <typename P> - class graph_psite : public Point_Site< graph_psite<P> > + class graph_psite + : public internal::pseudo_site_base_< const P&, graph_psite<P> > { typedef graph_psite<P> self_; - typedef Point_Site<self_> super_; public: - typedef mln_mesh(P) mesh; - enum { dim = P::dim }; - typedef P point; - typedef mln_dpoint(P) dpoint; - typedef mln_coord(P) coord; + // This associated type is important to know that this particular + // pseudo site knows the site set it refers to. + typedef p_graph<P> target; /// Construction and assignment. /// \{ graph_psite(); graph_psite(const p_graph<P>& pg_, util::vertex_id id); - graph_psite(const self_& rhs); - self_& operator= (const self_& rhs); /// \} - /// Access to psite. - const self_& to_psite() const; + /// Psite manipulators. + /// \{ + /// Is this psite valid? + bool is_valid() const; + /// Invalidate this psite. + void invalidate(); + /// \} - /// Access to point. + /// Site set manipulators. /// \{ - const point& to_point() const; - coord operator[](unsigned id) const; + /// \brief Get the site set (shortcut for *target()). + /// \pre Member plg_ is non null. + const target& site_set() const; + + /// Get a pointer to the target site_set. + const target* target_() const; + /// Set the target site_set. + void change_target(const target& new_target); /// \} - /// Return the p_graph this point site belongs to. - const p_graph<P>& pg() const; + /// Proxy manipulators. + /// \{ + /// Return the site corresponding to this psite. + const P& subj_(); + /// \} + + /// Vertex id manipulators. + //// \{ /// Return the vertex id of this point site. - util::vertex_id id() const; + util::vertex_id vertex_id() const; + /// Set the vertex id of this point site. + void change_vertex_id(const util::vertex_id& id); + /// Increment the vertex id of this point site. + void inc_vertex_id(); + /// Increment the vertex id of this point site. + void dec_vertex_id(); + /// \} - /// Is this psite valid? - bool is_valid() const; + private: + /// Site-related members. + /// \{ + /// Update the site corresponding to this psite. + void update_(); + // The site corresponding to this psite. + P p_; + /// \} private: + /// Graph-related members. + /// \{ /// The p_graph this point site belongs to. - const p_graph<P>* pg_; + const target* pg_; /// The id of the vertex this psite is pointing towards. util::vertex_id id_; + /// \} }; @@ -103,6 +141,14 @@ namespace mln bool operator==(const graph_psite<P>& lhs, const graph_psite<P>& rhs); + /// \brief Is \a lhs not equal to \a rhs? + /// + /// \pre Arguments \a lhs and \a rhs must belong to the same + /// mln::p_graph. + template <typename P> + bool + operator!=(const graph_psite<P>& lhs, const graph_psite<P>& rhs); + /// \brief Is \a lhs ``less'' than \a rhs? /// /// This comparison is required by algorithms sorting psites. @@ -115,97 +161,134 @@ namespace mln /// \} + template <typename P> + inline + std::ostream& + operator<<(std::ostream& ostr, const graph_psite<P>& p); + + # ifndef MLN_INCLUDE_ONLY template <typename P> inline graph_psite<P>::graph_psite() - // Dummy initializations. - : super_(), - pg_(0), - id_(-1) + : pg_(0) { } template <typename P> inline graph_psite<P>::graph_psite(const p_graph<P>& g, util::vertex_id id) - : super_(), - pg_(&g), + // FIXME: Use change_target instead. + : pg_(&g), id_(id) { + update_(); } template <typename P> inline - graph_psite<P>::graph_psite(const graph_psite<P>& rhs) - : super_(rhs), - pg_(rhs.pg_), - id_(rhs.id_) + bool + graph_psite<P>::is_valid() const { + /* FIXME: Instead of `plg_->gr_->nvertices()', we should have + something like `run_->has_edge_id(id_)' (see the implementation of + p_run_psite. */ + return pg_ && id_ < pg_->gr_->nvertices(); } template <typename P> inline - graph_psite<P>& - graph_psite<P>::operator= (const graph_psite<P>& rhs) + void + graph_psite<P>::invalidate() { - if (&rhs == this) - return *this; - pg_ = rhs.pg_; - id_ = rhs.id_; - return *this; + /* FIXME: Instead of `plg_->gr_->nvertices()', we should have + something like `run_->has_edge_id(id_)' (see the implementation of + p_run_psite. */ + id_ = pg_->gr_->nvertices(); } template <typename P> inline - bool - graph_psite<P>::is_valid() const + const p_graph<P>& + graph_psite<P>::site_set() const { - return pg_ && id_ < pg_->gr_->nvertices(); + mln_precondition(target_()); + return *target_(); } template <typename P> inline - const graph_psite<P>& - graph_psite<P>::to_psite() const + const p_graph<P>* + graph_psite<P>::target_() const { - return *this; + return pg_; } template <typename P> inline + void + graph_psite<P>::change_target(const p_graph<P>& new_target) + { + pg_ = &new_target; + invalidate(); + } + + // FIXME: Write or extend a test to exercise this method. + template <typename P> + inline const P& - graph_psite<P>::to_point() const + graph_psite<P>::subj_() { - return pg().point_from_id(id_); + return p_; } template <typename P> inline - mln_coord(P) - graph_psite<P>::operator[](unsigned i) const + util::vertex_id + graph_psite<P>::vertex_id() const { - mln_assertion(is_valid()); - return to_point()[i]; + return id_; } template <typename P> inline - const p_graph<P>& - graph_psite<P>::pg() const + void + graph_psite<P>::change_vertex_id(const util::vertex_id& id) { - mln_assertion(pg_); - return *pg_; + id_ = id; + if (is_valid()) + update_(); } template <typename P> inline - util::vertex_id - graph_psite<P>::id() const + void + graph_psite<P>::inc_vertex_id() { - return id_; + ++id_.to_equiv(); + if (is_valid()) + update_(); + } + + template <typename P> + inline + void + graph_psite<P>::dec_vertex_id() + { + --id_.to_equiv(); + if (is_valid()) + update_(); + } + + template <typename P> + inline + void + graph_psite<P>::update_() + { + mln_precondition(is_valid()); + p_ = site_set().point_from_id(id_); } @@ -217,19 +300,39 @@ namespace mln bool operator==(const graph_psite<P>& lhs, const graph_psite<P>& rhs) { - mln_assertion(&lhs.pg() == &rhs.pg()); - return lhs.id() == rhs.id(); + mln_assertion(lhs.target_() == rhs.target_()); + return lhs.vertex_id() == rhs.vertex_id(); + } + + template <typename P> + bool + operator!=(const graph_psite<P>& lhs, const graph_psite<P>& rhs) + { + mln_assertion(lhs.target_() == rhs.target_()); + return lhs.vertex_id() != rhs.vertex_id(); } template <typename P> bool operator< (const graph_psite<P>& lhs, const graph_psite<P>& rhs) { - mln_assertion(&lhs.pg() == &rhs.pg()); - return lhs.id() < rhs.id(); + mln_assertion(lhs.target_() == rhs.target_()); + return lhs.vertex_id() < rhs.vertex_id(); } + /*------------------. + | Pretty-printing. | + `------------------*/ + + template <typename P> + inline + std::ostream& + operator<<(std::ostream& ostr, const graph_psite<P>& p) + { + return ostr << p.unproxy_(); + } + # endif // ! MLN_INCLUDE_ONLY -- 1.5.6.5