https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Cleanup basic graph class and related materials.
* mln/core/site_set/p_graph_piter.hh: Upgrade doc style.
(operator<<): Remove; useless.
* mln/core/site_set/p_vertices.hh
(vertex, graph_element): New typedefs.
(graph_t): Remove; use explicitly G instead.
* mln/core/site_set/p_edges.hh
(edge, graph_element): New typedefs.
(graph_t): Remove; use explicitly G instead.
* mln/util/graph.hh: Layout.
* mln/util/internal/graph_base.hh (graph_id): Fix return type.
That avoids a warning at compile-time.
* mln/core/concept/graph.hh: Update.
* mln/util/internal/graph_iter.hh: Layout.
* mln/util/internal/graph_edge.hh: Upgrade doc style.
(operator<<): Fix missing const.
(edge::edge): Prefer invalidate over id_ set to 0.
(FIXME): New.
(invalidate): Set id_ to unsigned max value; less error-prone.
(graph_t): Use instead explicit...
(G): ...parameter type.
* mln/util/internal/graph_edge_psite.hh: Upgrade doc style.
(target_t, edge_t): Use instead the explicit...
(p_edges, util::edge): ...types.
* mln/util/internal/graph_vertex.hh
(vertex::vertex): Prefer invalidate over id_ set to 0.
(FIXME): New.
(invalidate): Set id_ to unsigned max value; less error-prone.
(graph_t): Use instead explicit...
(G): ...parameter type.
Fix doc.
* mln/util/internal/graph_psite_base.hh: Fix doc.
(V, P): Remove these useless parameters, now deduce from S.
(v_): Rename this attribute as...
(elt_): ...this; more explicit name.
(target): Prefer to use the explicit...
(S): ...type.
(t_): Rename as...
(s_): ...this; consistent with other classes.
(q_subject): Remove; obsolete.
(to_site): Remove; inherited.
(operator<<): Remove; useless.
(operator graph_element): New conversion operator.
(site_set, graph, subj_): Fix missing precondition.
* mln/util/internal/graph_vertex_psite.hh: Fix doc.
(target_t, vertex_t): Prefer to use explicit...
(p_vertices, util::vertex): ...types.
* mln/util/internal/graph_iter_base.hh
(P): Rename this parameter as...
(Elt): ...this; more explicit.
(invalidate): Fix missing postcondition.
(next): Fix missing precondition.
core/concept/graph.hh | 2
core/site_set/p_edges.hh | 28 +++--
core/site_set/p_graph_piter.hh | 34 ++----
core/site_set/p_vertices.hh | 43 +++++---
util/graph.hh | 12 +-
util/internal/graph_base.hh | 6 -
util/internal/graph_edge.hh | 50 ++++-----
util/internal/graph_edge_psite.hh | 53 +++------
util/internal/graph_iter.hh | 6 -
util/internal/graph_iter_base.hh | 59 +++++------
util/internal/graph_psite_base.hh | 193 +++++++++++++++++-------------------
util/internal/graph_vertex.hh | 41 ++++---
util/internal/graph_vertex_psite.hh | 48 ++++----
13 files changed, 291 insertions(+), 284 deletions(-)
Index: mln/core/site_set/p_graph_piter.hh
--- mln/core/site_set/p_graph_piter.hh (revision 2886)
+++ mln/core/site_set/p_graph_piter.hh (working copy)
@@ -30,15 +30,17 @@
# define MLN_CORE_SITE_SET_P_GRAPH_PITER_HH
/// \file mln/core/site_set/p_graph_piter.hh
-/// \brief Definition of point iterator on graph-based point set.
+///
+/// Definition of point iterator on graph-based point set.
# include <mln/core/internal/site_set_iterator_base.hh>
-//# include <mln/core/site_set/p_graph.hh>
-//# include <mln/core/image/graph_psite.hh>
+
+
namespace mln
{
- // Fwd decls.
+
+ // Forward declaration.
template <typename S, typename I> class graph_psite;
@@ -46,7 +48,7 @@
| p_graph_piter<S,I>. |
`------------------------*/
- /// \brief Generic iterator on point sites of a mln::S.
+ /// Generic iterator on point sites of a mln::S.
template <typename S, typename I>
class p_graph_piter
: public internal::site_set_iterator_base< S,
@@ -57,7 +59,8 @@
typedef I iter;
public:
- /// Construction and assignment.
+
+ /// Constructors.
/// \{
p_graph_piter();
p_graph_piter(const S& pv);
@@ -77,10 +80,12 @@
/// \}
private:
+
/// Update the psite corresponding to this iterator.
void update_();
private:
+
/// The psite corresponding to this iterator.
using super_::p_;
@@ -89,11 +94,6 @@
};
- /// Print an mln::p_graph_piter<S,I>.
- template <typename S, typename I>
- inline
- std::ostream&
- operator<<(std::ostream& ostr, const p_graph_piter<S,I>& p);
# ifndef MLN_INCLUDE_ONLY
@@ -164,19 +164,9 @@
p_.update_id(iter_.id());
}
-
-
- template <typename S, typename I>
- inline
- std::ostream&
- operator<<(std::ostream& ostr, const p_graph_piter<S,I>& p)
- {
- return ostr << p.unproxy_();
- }
-
# endif // ! MLN_INCLUDE_ONLY
-} // end of mln
+} // end of namespace mln
#endif // ! MLN_CORE_SITE_SET_P_GRAPH_PITER_HH
Index: mln/core/site_set/p_vertices.hh
--- mln/core/site_set/p_vertices.hh (revision 2886)
+++ mln/core/site_set/p_vertices.hh (working copy)
@@ -29,7 +29,8 @@
# define MLN_CORE_SITE_SET_P_VERTICES_HH
/// \file mln/core/site_set/p_vertices.hh
- /// \brief Definition of a point set based on a graph.
+///
+/// Definition of a point set based on a graph.
# include <mln/core/internal/site_set_base.hh>
# include <mln/core/site_set/p_graph_piter.hh>
@@ -41,11 +42,14 @@
//# include <mln/core/image/graph_psite.hh>
//# include <mln/core/site_set/p_vertices_piter.hh>
+
namespace mln
{
+
// Forward declaration.
template <typename G, typename F> struct p_vertices;
+
namespace trait
{
template <typename G, typename F>
@@ -60,33 +64,41 @@
} // end of namespace mln::trait
+
template <typename G, typename F>
class p_vertices
- : public internal::site_set_base_< typename F::result, p_vertices<G, F>
>
+ : public internal::site_set_base_< mln_result(F), p_vertices<G, F> >
{
- typedef util::vertex<G> vertex_t;
typedef p_vertices<G, F> self_;
- typedef internal::site_set_base_< typename F::result, self_ > super_;
+ typedef internal::site_set_base_< mln_result(F), self_ > super_;
public:
- /// Type of the graph this site set is based on.
- typedef G graph_t;
+ /// Type of graph vertex.
+ typedef util::vertex<G> vertex;
- /// \brief Construct a graph psite set from a graph of points.
- /// \{
+
+ /// Type of graph element this site set focuses on.
+ typedef util::vertex<G> graph_element;
+
+
+ /// Constructor without argument.
p_vertices();
+ /// Construct a graph psite set from a graph of points.
/// \param gr The graph upon which the graph psite set is built.
/// \param f the function which maps a vertex to a site.
- p_vertices(const graph_t& gr, const F& f);
+ p_vertices(const G& gr, const F& f);
/// \}
+
/// Associated types.
/// \{
+
/// Element associated type.
typedef mln_site(super_) element;
+
/// Point_Site associated type.
typedef internal::vertex_psite<G, F> psite;
@@ -98,8 +110,10 @@
/// Site_Iterator associated type.
typedef fwd_piter piter;
+
/// \}
+
/// \brief Return The number of points (sites) of the set, i.e.,
/// the number of \em vertices.
///
@@ -109,8 +123,9 @@
/// Return The number of vertices in the graph.
unsigned nvertices() const;
- /// Is this site set valid?
+ /// Test this site set validity.
bool is_valid() const;
+
/// Invalidate this site set.
void invalidate();
@@ -134,13 +149,13 @@
/// Accessors.
/// \{
/// Return the graph associated to this site set (const version)
- const graph_t& graph() const;
+ const G& graph() const;
/// Return the association function.
const F& function() const;
/// \}
private:
- mlc_const(graph_t)* g_;
+ const G* g_;
F f_;
};
@@ -182,7 +197,7 @@
template <typename G, typename F>
inline
- p_vertices<G, F>::p_vertices(const graph_t& g, const F& f)
+ p_vertices<G, F>::p_vertices(const G& g, const F& f)
: g_ (&g), f_(f)
{
}
@@ -282,7 +297,7 @@
template <typename G, typename F>
inline
- const typename p_vertices<G, F>::graph_t&
+ const G&
p_vertices<G, F>::graph() const
{
mln_precondition(is_valid());
Index: mln/core/site_set/p_edges.hh
--- mln/core/site_set/p_edges.hh (revision 2886)
+++ mln/core/site_set/p_edges.hh (working copy)
@@ -58,27 +58,32 @@
template <typename G, typename F>
class p_edges
- : public internal::site_set_base_< typename F::result, p_edges<G, F> >
+ : public internal::site_set_base_< mln_result(F), p_edges<G, F> >
{
- typedef util::edge<G> edge_t;
typedef p_edges<G, F> self_;
- typedef internal::site_set_base_< typename F::result, self_ > super_;
+ typedef internal::site_set_base_< mln_result(F), self_ > super_;
public:
- /// Type of the graph this site set is based on.
- typedef G graph_t;
- /// \brief Construct a graph edge psite set from a graph and a function.
+ /// Type of graph edge.
+ typedef util::edge<G> edge;
+
+ /// Type of graph element this site set focuses on.
+ typedef util::edge<G> graph_element;
+
+
+ /// Construct a graph edge psite set from a graph and a function.
///
/// \param gr The graph upon which the graph edge psite set is built.
/// \param f the function mapping edges and sites.
- p_edges(const graph_t& gr, const F& f);
+ p_edges(const G& gr, const F& f);
/// Associated types.
/// \{
/// Element associated type.
typedef mln_site(super_) element;
+
/// Point_Site associated type.
typedef internal::edge_psite<G, F> psite;
@@ -117,13 +122,14 @@
/// Accessors.
/// \{
/// Return the graph associated to this site set
- const graph_t& graph() const;
+ const G& graph() const;
/// Return the mapping function.
const F& function() const;
/// \}
private:
- mlc_const(graph_t)* g_;
+
+ const G* g_;
F f_;
};
@@ -155,7 +161,7 @@
template <typename G, typename F>
inline
- p_edges<G, F>::p_edges(const graph_t& g, const F& f)
+ p_edges<G, F>::p_edges(const G& g, const F& f)
: g_ (&g), f_(f)
{
}
@@ -223,7 +229,7 @@
template <typename G, typename F>
inline
- const typename p_edges<G, F>::graph_t&
+ const G&
p_edges<G, F>::graph() const
{
mln_precondition(is_valid());
Index: mln/core/concept/graph.hh
--- mln/core/concept/graph.hh (revision 2886)
+++ mln/core/concept/graph.hh (working copy)
@@ -109,7 +109,7 @@
//typedef mln_bkd_piter(E) bkd_piter;
// Check methods
- const void * const(E::*m1)() const = & E::graph_id;
+ const void* (E::*m1)() const = & E::graph_id;
m1 = 0;
unsigned (E::*m2)(unsigned id_e, unsigned id_v) const = & E::v_other;
m2 = 0;
Index: mln/util/graph.hh
--- mln/util/graph.hh (revision 2886)
+++ mln/util/graph.hh (working copy)
@@ -30,19 +30,21 @@
# define MLN_UTIL_GRAPH_HH
/// \file mln/util/graph.hh
-/// Definitions of undirected graphs.
+///
+/// Definition of a basic undirected graph.
# include <mln/util/internal/graph_base.hh>
# include <mln/util/internal/graph_iter.hh>
# include <mln/util/internal/graph_nbh_iter.hh>
# include <mln/util/ord_pair.hh>
+
namespace mln
{
namespace util
{
- /// Fwd declaration.
+ /// Forward declaration.
class graph;
}
@@ -134,6 +136,8 @@
graph();
+
+
/// Vertex oriented.
/// \{
/// Shortcuts factoring the insertion of vertices and edges.
@@ -173,7 +177,6 @@
-
/// Edge oriented.
/// \{
/// Add an edge.
@@ -219,6 +222,9 @@
} // end of namespace mln
+
+
+
# ifndef MLN_INCLUDE_ONLY
namespace mln
Index: mln/util/internal/graph_iter.hh
--- mln/util/internal/graph_iter.hh (revision 2886)
+++ mln/util/internal/graph_iter.hh (working copy)
@@ -148,6 +148,8 @@
friend class graph_iter_base<G, util::edge<G>, edge_bkd_iterator<G>
>;
};
+
+
# ifndef MLN_INCLUDE_ONLY
/*--------------------`
@@ -290,9 +292,9 @@
# endif // !MLN_INCLUDE_ONLY
- } // End of namespace mln::internal
+ } // end of namespace mln::internal
-} // End of namespace mln
+} // end of namespace mln
#endif // !MLN_UTIL_INTERNAL_GRAPH_ITER_HH
Index: mln/util/internal/graph_edge.hh
--- mln/util/internal/graph_edge.hh (revision 2886)
+++ mln/util/internal/graph_edge.hh (working copy)
@@ -28,11 +28,12 @@
#ifndef MLN_UTIL_INTERNAL_GRAPH_EDGE_HH
# define MLN_UTIL_INTERNAL_GRAPH_EDGE_HH
+/// \file mln/util/internal/graph_edge.hh
+///
+/// Definition of a graph edge.
+
# include <mln/util/internal/graph_edge_impl.hh>
-/*! \file mln/util/internal/graph_edge.hh
- * \brief Definition of a graph edge.
- */
namespace mln
{
@@ -44,22 +45,23 @@
| Edge. |
`-------*/
- /// \brief Edge of a graph \p G.
+ /// Edge of a graph \p G.
template <typename G>
class edge : public internal::edge_impl_<G>
{
- typedef mlc_unconst(G) graph_t;
-
public:
+
+ /// Graph associated type.
+ typedef G graph_t;
+
/// Constructors
/// \{
edge();
- explicit edge(const graph_t& g);
- edge(const graph_t& g, unsigned id);
+ explicit edge(const G& g);
+ edge(const G& g, unsigned id);
/// \}
-
/// Misc.
/// \{
/// Return whether is points to a known edge.
@@ -74,14 +76,13 @@
void update_id(unsigned id);
/// Return a reference to the graph holding this edge.
- const graph_t& graph() const;
+ const G& graph() const;
/// Set g_ with \p g;
- void change_graph(const graph_t& g);
+ void change_graph(const G& g);
/// \}
-
/// Vertex and edges oriented.
/// \{
/// Return the vertex id of this edge which is different from \p id_v.
@@ -105,13 +106,13 @@
/// \}
private:
- graph_t g_;
+ G g_;
unsigned id_;
};
template <typename G>
std::ostream&
- operator<<(std::ostream& ostr, edge<G>& p);
+ operator<<(std::ostream& ostr, const edge<G>& p);
template <typename G>
bool
@@ -174,23 +175,24 @@
template <typename G>
inline
edge<G>::edge()
- : id_(0)
{
+ invalidate();
}
template <typename G>
inline
- edge<G>::edge(const graph_t& g)
- : g_(g), id_(g.e_nmax())
+ edge<G>::edge(const G& g)
+ : g_(g)
{
+ invalidate();
}
template <typename G>
inline
- edge<G>::edge(const graph_t& g, unsigned id)
+ edge<G>::edge(const G& g, unsigned id)
: g_(g), id_(id)
{
- mln_precondition(g.has_e(id));
+ mln_precondition(/* FIXME: g_.is_valid() && */ g.has_e(id));
}
template <typename G>
@@ -211,7 +213,7 @@
template <typename G>
inline
- const typename edge<G>::graph_t&
+ const typename edge<G>::G&
edge<G>::graph() const
{
return g_;
@@ -220,7 +222,7 @@
template <typename G>
inline
void
- edge<G>::change_graph(const graph_t& g)
+ edge<G>::change_graph(const G& g)
{
g_ = g;
}
@@ -230,7 +232,7 @@
bool
edge<G>::is_valid() const
{
- return g_.has_e(id_);
+ return /* FIXME: g_.is_valid() && */ g_.has_e(id_);
}
template <typename G>
@@ -238,7 +240,7 @@
void
edge<G>::invalidate()
{
- id_ = g_.e_nmax();
+ id_ = mln_max(unsigned);
}
@@ -289,7 +291,7 @@
template <typename G>
std::ostream&
- operator<<(std::ostream& ostr, edge<G>& p)
+ operator<<(std::ostream& ostr, const edge<G>& p)
{
return ostr << p.id();
}
Index: mln/util/internal/graph_edge_psite.hh
--- mln/util/internal/graph_edge_psite.hh (revision 2886)
+++ mln/util/internal/graph_edge_psite.hh (working copy)
@@ -28,67 +28,56 @@
#ifndef MLN_UTIL_INTERNAL_GRAPH_EDGE_PSITE_HH
# define MLN_UTIL_INTERNAL_GRAPH_EDGE_PSITE_HH
-# include <mln/core/concept/pseudo_site.hh>
+/// \file mln/util/internal/graph_edge_psite.hh
+///
+/// Implementation of p_edges psite.
+
# include <mln/util/internal/graph_psite_base.hh>
# include <mln/util/internal/graph_edge.hh>
+
namespace mln
{
+ // Forward declaration.
template <typename G, typename F> class p_edges;
-} // end of namespace mln
-
-/// \file mln/util/internal/graph_edge_psite.hh
-/// \brief Implementation of p_edges psite.
-
-namespace mln
-{
namespace internal
{
+
template <typename G, typename F>
class edge_psite :
- public graph_psite_base<util::edge<G>, typename F::result,
- p_edges<G, F>,
+ public graph_psite_base< p_edges<G,F>,
edge_psite<G, F> >
{
typedef edge_psite<G, F> self_;
- typedef p_edges<G, F> target_t;
- typedef graph_psite_base<util::edge<G>, typename F::result, target_t,
self_> super_;
- typedef util::edge<G> edge_t;
+ typedef graph_psite_base<p_edges<G,F>, self_> super_;
public:
- /// Associated Types
- /// \{
- /// Site type, the return type of the mapping function \p F here.
- typedef typename F::result site;
- /// \}
/// Constructors
/// \{
edge_psite();
- edge_psite(const target_t& t);
- edge_psite(const target_t& t, unsigned);
+ edge_psite(const p_edges<G,F>& s);
+ edge_psite(const p_edges<G,F>& s, unsigned);
/// \}
/// Accessors
/// \{
/// Return the underlying edge.
- const edge_t& e() const;
+ const util::edge<G>& e() const;
/// \}
-
- protected:
- /// The underlying edge (inherited).
- using super_::v_;
};
- } // end of namespace internal
+
+ } // end of namespace mln::internal
} // end of namespace mln
+
# ifndef MLN_INCLUDE_ONLY
namespace mln
@@ -105,24 +94,24 @@
template <typename G, typename F>
inline
- edge_psite<G, F>::edge_psite(const target_t& t)
- : super_(t)
+ edge_psite<G, F>::edge_psite(const p_edges<G,F>& s)
+ : super_(s)
{
}
template <typename G, typename F>
inline
- edge_psite<G, F>::edge_psite(const target_t& t, unsigned id)
- : super_(t, id)
+ edge_psite<G, F>::edge_psite(const p_edges<G,F>& s, unsigned id)
+ : super_(s, id)
{
}
template <typename G, typename F>
inline
- const typename edge_psite<G, F>::edge_t&
+ const util::edge<G>&
edge_psite<G, F>::e() const
{
- return v_;
+ return this->v_;
}
} // end of namespace internal
Index: mln/util/internal/graph_base.hh
--- mln/util/internal/graph_base.hh (revision 2886)
+++ mln/util/internal/graph_base.hh (working copy)
@@ -83,7 +83,7 @@
/// Misc. methods
/// \{
/// Returns the graph id, the "this" pointer.
- const void * const graph_id() const;
+ const void* graph_id() const;
/// \}
/// Vertex oriented methods
@@ -158,10 +158,10 @@
template<typename E>
inline
- const void * const
+ const void*
graph_base<E>::graph_id() const
{
- return static_cast<const void * const>(data_.ptr_);
+ return static_cast<const void*>(data_.ptr_);
}
/*-------------------------.
Index: mln/util/internal/graph_vertex.hh
--- mln/util/internal/graph_vertex.hh (revision 2886)
+++ mln/util/internal/graph_vertex.hh (working copy)
@@ -31,7 +31,10 @@
# include <mln/util/internal/graph_vertex_impl.hh>
/// \file mln/util/internal/graph_vertex.hh
-/// \brief Implementation of a graph vertex.
+///
+/// Implementation of a graph vertex.
+
+
namespace mln
{
@@ -39,19 +42,20 @@
namespace util
{
- /// \brief Vertex of a graph \p G.
+ /// Vertex of a graph \p G.
template<typename G>
class vertex : public internal::vertex_impl_<G>
{
- typedef mlc_unconst(G) graph_t;
-
public:
+ /// Graph associated type.
+ typedef G graph_t;
+
/// Constructors.
/// \{
vertex();
- explicit vertex(const graph_t& g);
- vertex(const graph_t& g, unsigned id);
+ explicit vertex(const G& g);
+ vertex(const G& g, unsigned id);
/// \}
/// Check whether the vertex is still part of the graph.
@@ -78,17 +82,17 @@
/// Change the parent graph of that vertex.
void change_graph(const G& g);
- /// Update vertex id.
+ /// Update the vertex id.
void update_id(unsigned id);
/// Returns the graph pointer this vertex belongs to.
- const graph_t& graph() const;
+ const G& graph() const;
- /// Returns vertex id.
+ /// Returns the vertex id.
unsigned id() const;
protected:
- graph_t g_;
+ G g_;
unsigned id_;
};
@@ -173,23 +177,24 @@
template <typename G>
inline
vertex<G>::vertex()
- : id_(0)
{
+ invalidate();
}
template <typename G>
inline
- vertex<G>::vertex(const graph_t& g)
- : g_(g), id_(g_.v_nmax())
+ vertex<G>::vertex(const G& g)
+ : g_(g)
{
+ invalidate();
}
template<typename G>
inline
- vertex<G>::vertex(const graph_t& g, unsigned id)
+ vertex<G>::vertex(const G& g, unsigned id)
: g_(g), id_(id)
{
- mln_precondition(g_.has_v(id));
+ mln_precondition(/* FIXME: g_.is_valid() && */ g_.has_v(id));
}
template<typename G>
@@ -197,7 +202,7 @@
bool
vertex<G>::is_valid() const
{
- return g_.has_v(id_);
+ return /* FIXME: g_.is_valid() && */ g_.has_v(id_);
}
template<typename G>
@@ -205,7 +210,7 @@
void
vertex<G>::invalidate()
{
- id_ = g_.v_nmax();
+ id_ = mln_max(unsigned);
}
@@ -274,7 +279,7 @@
template<typename G>
inline
- const typename vertex<G>::graph_t&
+ const typename vertex<G>::G&
vertex<G>::graph() const
{
return g_;
Index: mln/util/internal/graph_psite_base.hh
--- mln/util/internal/graph_psite_base.hh (revision 2886)
+++ mln/util/internal/graph_psite_base.hh (working copy)
@@ -28,6 +28,10 @@
#ifndef MLN_UTIL_INTERNAL_GRAPH_PSITE_BASE_HH
# define MLN_UTIL_INTERNAL_GRAPH_PSITE_BASE_HH
+/// \file mln/util/internal/graph_psite_base.hh
+///
+/// Base implementation for graph based psites.
+
# include <mln/core/concept/pseudo_site.hh>
namespace mln
@@ -37,8 +41,6 @@
} // end of namespace mln
-/// \file mln/util/internal/graph_psite_base.hh
-/// \brief Base implementation for graph based psites.
namespace mln
{
@@ -46,41 +48,43 @@
namespace internal
{
- template <typename V, typename P, typename S, typename E>
- class graph_psite_base : public mln::Pseudo_Site<E>,
- public internal::proxy_impl<const P&, E>
+ template <typename S, typename E>
+ class graph_psite_base : public internal::pseudo_site_base_< const
mln_site(S)&,
+ E >
{
- typedef Pseudo_Site< graph_psite_base<V, P, S, E> > super;
- typedef typename S::graph_t graph_t;
+ typedef Pseudo_Site< graph_psite_base<S,E> > super;
public:
- /// Associated types.
- /// \{
- typedef P site;
+
+ // This associated type is important to know that this particular
+ // pseudo site knows the site set it refers to.
typedef S target;
- /// \}
+
+ // As a Proxy:
+ const mln_site(S)& subj_();
+
/// Setters.
/// \{
/// Change the targe site set.
- void change_target(const target& new_target);
+ void change_target(const S& new_target);
/// Update the underlying element's id.
/// This element can be an edge, a vertex...
- void update_id(unsigned v_id);
+ void update_id(unsigned elt_id);
/// \}
/// Getters.
/// \{
/// Return the target (the site set).
- const target* target_() const; // Hook to the target.
+ const S* target_() const; // Hook to the target.
/// Return the site set (the target).
- const target& site_set() const;
+ const S& site_set() const;
/// Return the graph associated to the target of this psite.
- const graph_t& graph() const;
+ const typename S::graph_t& graph() const;
- /// Return the graph associated to the target of this psite.
+ /// Return the id of the graph element designated by this psite.
unsigned id() const;
/// \}
@@ -90,38 +94,30 @@
/// Invalidate this psite.
void invalidate();
- /// Pseudo site Interface
- /// \{
- /// Subject type.
- typedef const site& q_subject;
- /// Return the subject.
- const site& subj_();
- /// Return the underlying site.
- const site& to_site() const;
- /// \}
+ /// Conversion towards the graph element (vertex or edge).
+ operator const typename S::graph_element&() const;
protected:
+
/// Constructors.
+
/// \{
graph_psite_base();
/// \p t A site set.
/// \sa p_vertices, p_edges.
- graph_psite_base(const target& t);
+ graph_psite_base(const S& s);
/// \p t A site set.
/// \sa p_vertices, p_edges.
/// \p id The id of the element associated to this psite.
- graph_psite_base(const target& t, unsigned id);
+ graph_psite_base(const S& , unsigned id);
/// \}
- mlc_const(target)* t_;
- V v_;
+ const S* s_;
+ typename S::graph_element elt_;
};
- template <typename V, typename P, typename S, typename E>
- std::ostream&
- operator<<(std::ostream& ostr, graph_psite_base<V, P, S, E>& p);
- /// Comparison of two mln::graph_psite_base<V, P, S, E> instances.
+ /// Comparison of two mln::graph_psite_base<S,E> instances.
/// \{
/* FIXME: Shouldn't those comparisons be part of a much general
mechanism? */
@@ -130,17 +126,17 @@
///
/// \pre Arguments \a lhs and \a rhs must belong to the same
/// mln::p_vertices.
- template <typename V, typename P, typename S, typename E>
+ template <typename S, typename E>
bool
- operator==(const graph_psite_base<V, P, S, E>& lhs, const
graph_psite_base<V, P, S, E>& rhs);
+ operator==(const graph_psite_base<S,E>& lhs, const
graph_psite_base<S,E>& rhs);
/// \brief Is \a lhs not equal to \a rhs?
///
/// \pre Arguments \a lhs and \a rhs must belong to the same
/// mln::p_vertices.
- template <typename V, typename P, typename S, typename E>
+ template <typename S, typename E>
bool
- operator!=(const graph_psite_base<V, P, S, E>& lhs, const
graph_psite_base<V, P, S, E>& rhs);
+ operator!=(const graph_psite_base<S,E>& lhs, const
graph_psite_base<S,E>& rhs);
/// \brief Is \a lhs ``less'' than \a rhs?
///
@@ -148,9 +144,9 @@
///
/// \pre Arguments \a lhs and \a rhs must belong to the same
/// mln::p_vertices.
- template <typename V, typename P, typename S, typename E>
+ template <typename S, typename E>
bool
- operator< (const graph_psite_base<V, P, S, E>& lhs, const
graph_psite_base<V, P, S, E>& rhs);
+ operator< (const graph_psite_base<S,E>& lhs, const
graph_psite_base<S,E>& rhs);
/// \}
} // end of namespace internal
@@ -158,6 +154,7 @@
} // end of namespace mln
+
# ifndef MLN_INCLUDE_ONLY
namespace mln
@@ -166,143 +163,137 @@
namespace internal
{
- template <typename V, typename P, typename S, typename E>
+ template <typename S, typename E>
inline
- graph_psite_base<V, P, S, E>::graph_psite_base()
- : t_(0)
+ graph_psite_base<S,E>::graph_psite_base()
+ : s_(0)
{
}
- template <typename V, typename P, typename S, typename E>
+ template <typename S, typename E>
inline
- graph_psite_base<V, P, S, E>::graph_psite_base(const target& t)
- : t_(0)
+ graph_psite_base<S,E>::graph_psite_base(const S& s)
{
- change_target(t);
+ change_target(s);
}
- template <typename V, typename P, typename S, typename E>
+ template <typename S, typename E>
inline
- graph_psite_base<V, P, S, E>::graph_psite_base(const target& t, unsigned
id)
- : t_(0)
+ graph_psite_base<S,E>::graph_psite_base(const S& s, unsigned id)
{
- change_target(t);
+ change_target(s);
update_id(id);
}
- template <typename V, typename P, typename S, typename E>
+ template <typename S, typename E>
inline
void
- graph_psite_base<V, P, S, E>::change_target(const target& new_target)
+ graph_psite_base<S,E>::change_target(const S& new_target)
{
- t_ = &new_target;
- v_.change_graph(new_target.graph());
+ s_ = & new_target;
+ elt_.change_graph(new_target.graph());
}
- template <typename V, typename P, typename S, typename E>
+ template <typename S, typename E>
inline
void
- graph_psite_base<V, P, S, E>::update_id(unsigned id)
+ graph_psite_base<S,E>::update_id(unsigned id)
{
- v_.update_id(id);
+ elt_.update_id(id);
}
- template <typename v, typename p, typename s, typename e>
+ template <typename S, typename E>
inline
- const typename graph_psite_base<v, p, s, e>::target*
- graph_psite_base<v, p, s, e>::target_() const
+ const S*
+ graph_psite_base<S,E>::target_() const
{
- return t_;
+ return s_;
}
- template <typename v, typename p, typename s, typename e>
+ template <typename S, typename E>
inline
- const typename graph_psite_base<v, p, s, e>::target&
- graph_psite_base<v, p, s, e>::site_set() const
+ const S&
+ graph_psite_base<S,E>::site_set() const
{
- return *t_;
+ mln_precondition(s_ != 0);
+ return *s_;
}
- template <typename v, typename p, typename s, typename e>
+ template <typename S, typename E>
inline
- const typename graph_psite_base<v, p, s, e>::graph_t&
- graph_psite_base<v, p, s, e>::graph() const
+ const typename S::graph_t&
+ graph_psite_base<S,E>::graph() const
{
- return t_->graph();
+ mln_precondition(s_ != 0);
+ return s_->graph();
}
- template <typename v, typename p, typename s, typename e>
+ template <typename S, typename E>
inline
unsigned
- graph_psite_base<v, p, s, e>::id() const
+ graph_psite_base<S,E>::id() const
{
- return v_.id();
+ return elt_.id();
}
- template <typename V, typename P, typename S, typename E>
+ template <typename S, typename E>
inline
bool
- graph_psite_base<V, P, S, E>::is_valid() const
+ graph_psite_base<S,E>::is_valid() const
{
- return t_ != 0 && t_->is_valid() && v_.is_valid();
+ return s_ != 0 && s_->is_valid() && elt_.is_valid();
}
- template <typename V, typename P, typename S, typename E>
+ template <typename S, typename E>
inline
void
- graph_psite_base<V, P, S, E>::invalidate()
+ graph_psite_base<S,E>::invalidate()
{
- t_ = 0;
- v_.invalidate();
+ s_ = 0;
+ elt_.invalidate();
}
- template <typename V, typename P, typename S, typename E>
+ template <typename S, typename E>
inline
- const typename graph_psite_base<V, P, S, E>::site&
- graph_psite_base<V, P, S, E>::subj_()
+ const mln_site(S)&
+ graph_psite_base<S,E>::subj_()
{
- return to_site();
+ mln_precondition(s_ != 0);
+ return s_->function()(elt_.id());
}
- template <typename V, typename P, typename S, typename E>
+ template <typename S, typename E>
inline
- const typename graph_psite_base<V, P, S, E>::site&
- graph_psite_base<V, P, S, E>::to_site() const
+ graph_psite_base<S,E>::operator const typename S::graph_element&() const
{
- return t_->function()(v_.id());
+ mln_precondition(is_valid());
+ return elt_;
}
- template <typename V, typename P, typename S, typename E>
- std::ostream&
- operator<<(std::ostream& ostr, graph_psite_base<V, P, S, E>&
p)
- {
- return ostr << p.unproxy_();
- }
-
/*--------------.
| Comparisons. |
`--------------*/
- template <typename V, typename P, typename S, typename E>
+ template <typename S, typename E>
bool
- operator==(const graph_psite_base<V, P, S, E>& lhs, const
graph_psite_base<V, P, S, E>& rhs)
+ operator==(const graph_psite_base<S,E>& lhs, const
graph_psite_base<S,E>& rhs)
{
mln_assertion(lhs.target_() == rhs.target_());
return lhs.id() == rhs.id();
}
- template <typename V, typename P, typename S, typename E>
+ template <typename S, typename E>
bool
- operator!=(const graph_psite_base<V, P, S, E>& lhs, const
graph_psite_base<V, P, S, E>& rhs)
+ operator!=(const graph_psite_base<S,E>& lhs, const
graph_psite_base<S,E>& rhs)
{
mln_assertion(lhs.target_() == rhs.target_());
return lhs.id() != rhs.id();
}
- template <typename V, typename P, typename S, typename E>
+ template <typename S, typename E>
bool
- operator< (const graph_psite_base<V, P, S, E>& lhs, const
graph_psite_base<V, P, S, E>& rhs)
+ operator< (const graph_psite_base<S,E>& lhs, const
graph_psite_base<S,E>& rhs)
{
mln_assertion(lhs.target_() == rhs.target_());
return lhs.id() < rhs.id();
Index: mln/util/internal/graph_vertex_psite.hh
--- mln/util/internal/graph_vertex_psite.hh (revision 2886)
+++ mln/util/internal/graph_vertex_psite.hh (working copy)
@@ -28,55 +28,51 @@
#ifndef MLN_UTIL_INTERNAL_GRAPH_VERTEX_PSITE_HH
# define MLN_UTIL_INTERNAL_GRAPH_VERTEX_PSITE_HH
+/// \file mln/util/internal/graph_vertex_psite.hh
+///
+/// Implementation of p_vertices psite.
+
# include <mln/core/concept/pseudo_site.hh>
# include <mln/util/internal/graph_psite_base.hh>
# include <mln/util/internal/graph_vertex.hh>
+
namespace mln
{
+ // Forward declaration.
template <typename G, typename F> class p_vertices;
-} // end of namespace mln
-
-/// \file mln/util/internal/graph_vertex_psite.hh
-/// \brief Implementation of p_vertices psite.
-
-namespace mln
-{
namespace internal
{
+
template <typename G, typename F>
class vertex_psite :
- public graph_psite_base<util::vertex<G>, typename F::result,
- p_vertices<G, F>,
+ public graph_psite_base< p_vertices<G,F>,
vertex_psite<G, F> >
{
typedef vertex_psite<G, F> self_;
- typedef p_vertices<G, F> target_t;
- typedef graph_psite_base<util::vertex<G>, typename F::result, target_t,
self_> super_;
- typedef util::vertex<G> vertex_t;
+ typedef graph_psite_base<p_vertices<G,F>, self_> super_;
public:
- typedef typename F::result site;
vertex_psite();
- vertex_psite(const target_t& t);
- vertex_psite(const target_t& t, unsigned id);
+ vertex_psite(const p_vertices<G,F>& s);
+ vertex_psite(const p_vertices<G,F>& s, unsigned id);
- const vertex_t& v() const;
-
- protected:
- using super_::v_;
+ const util::vertex<G>& v() const;
};
- } // end of namespace internal
+
+ } // end of namespace mln::internal
} // end of namespace mln
+
+
# ifndef MLN_INCLUDE_ONLY
namespace mln
@@ -93,24 +89,24 @@
template <typename G, typename F>
inline
- vertex_psite<G, F>::vertex_psite(const target_t& t)
- : super_(t)
+ vertex_psite<G, F>::vertex_psite(const p_vertices<G,F>& s)
+ : super_(s)
{
}
template <typename G, typename F>
inline
- vertex_psite<G, F>::vertex_psite(const target_t& t, unsigned i)
- : super_(t, i)
+ vertex_psite<G, F>::vertex_psite(const p_vertices<G,F>& s, unsigned
i)
+ : super_(s, i)
{
}
template <typename G, typename F>
inline
- const typename vertex_psite<G, F>::vertex_t&
+ const util::vertex<G>&
vertex_psite<G, F>::v() const
{
- return v_;
+ return this->v_;
}
} // end of namespace internal
Index: mln/util/internal/graph_iter_base.hh
--- mln/util/internal/graph_iter_base.hh (revision 2886)
+++ mln/util/internal/graph_iter_base.hh (working copy)
@@ -28,12 +28,17 @@
#ifndef MLN_UTIL_INTERNAL_GRAPH_ITER_BASE_HH
# define MLN_UTIL_INTERNAL_GRAPH_ITER_BASE_HH
+/// \file mln/util/internal/graph_iter_base.hh
+///
+/// Base implementation for graph iterators.
+///
+/// \todo Have special types for ids (vertex_id) to disambiguate the
+/// conversion op.
+
# 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
{
@@ -41,10 +46,10 @@
namespace internal
{
- template <typename G, typename P, typename E>
+ template <typename G, typename Elt, typename E>
class graph_iter_base
: public Proxy< E >,
- public internal::proxy_impl< const P&, E >
+ public internal::proxy_impl< const Elt&, E >
{
public:
/// Iterator interface
@@ -67,80 +72,80 @@
operator unsigned() const;
/// \}
- /// Proxy.
- /// \{
/// Proxy subject
- const P& subj_();
- /// \}
+ const Elt& subj_();
protected:
graph_iter_base(const G& g);
- P p_;
+ Elt p_;
};
+
# ifndef MLN_INCLUDE_ONLY
- template <typename G, typename P, typename E>
+ template <typename G, typename Elt, typename E>
inline
- graph_iter_base<G, P, E>::graph_iter_base(const G& g)
- : p_(P(g))
+ graph_iter_base<G, Elt, E>::graph_iter_base(const G& g)
+ : p_(Elt(g))
{
invalidate();
}
- template <typename G, typename P, typename E>
+ template <typename G, typename Elt, typename E>
inline
bool
- graph_iter_base<G, P, E>::is_valid() const
+ graph_iter_base<G, Elt, E>::is_valid() const
{
return p_.is_valid();
}
- template <typename G, typename P, typename E>
+ template <typename G, typename Elt, typename E>
inline
void
- graph_iter_base<G, P, E>::invalidate()
+ graph_iter_base<G, Elt, E>::invalidate()
{
p_.invalidate();
+ mln_postcondition(! is_valid());
}
- template <typename G, typename P, typename E>
+ template <typename G, typename Elt, typename E>
inline
void
- graph_iter_base<G, P, E>::start()
+ graph_iter_base<G, Elt, E>::start()
{
p_.update_id(exact(this)->start_id_());
}
- template <typename G, typename P, typename E>
+ template <typename G, typename Elt, typename E>
inline
void
- graph_iter_base<G, P, E>::next()
+ graph_iter_base<G, Elt, E>::next()
{
+ mln_precondition(is_valid());
p_.update_id(exact(this)->next_id_());
}
- template <typename G, typename P, typename E>
+ template <typename G, typename Elt, typename E>
inline
unsigned
- graph_iter_base<G, P, E>::index() const
+ graph_iter_base<G, Elt, E>::index() const
{
return p_.id();
}
- template <typename G, typename P, typename E>
+ template <typename G, typename Elt, typename E>
inline
- graph_iter_base<G, P, E>::operator unsigned() const
+ graph_iter_base<G, Elt, E>::operator unsigned() const
{
return p_.id();
}
- template <typename G, typename P, typename E>
+ template <typename G, typename Elt, typename E>
inline
- const P&
- graph_iter_base<G, P, E>::subj_()
+ const Elt&
+ graph_iter_base<G, Elt, E>::subj_()
{
return p_;
}