27 #ifndef MLN_UTIL_INTERNAL_GRAPH_BASE_HH
28 # define MLN_UTIL_INTERNAL_GRAPH_BASE_HH
40 # include <mln/core/concept/object.hh>
41 # include <mln/core/concept/graph.hh>
42 # include <mln/core/concept/proxy.hh>
43 # include <mln/core/internal/data.hh>
45 # include <mln/util/edge.hh>
46 # include <mln/util/vertex.hh>
47 # include <mln/util/ord_pair.hh>
48 # include <mln/util/tracked_ptr.hh>
65 class graph_base :
public Graph<E>
70 typedef util::vertex<E> vertex_t;
72 typedef util::edge<E> edge_t;
75 typedef std::vector<edge_id_t> vertex_data_t;
78 typedef ord_pair<vertex_id_t> edge_data_t;
84 const void* id()
const;
90 bool has(
const util::vertex<E>& v)
const;
97 bool has(
const util::edge<E>& e)
const;
107 bool is_valid()
const;
118 void print_debug(std::ostream& ostr)
const;
121 const util::tracked_ptr< mln::internal::data<E> >& data_hook_()
const;
126 util::tracked_ptr< mln::internal::data<E> > data_;
137 template <
typename E>
139 operator==(
const util::internal::graph_base<E>& lhs,
140 const util::internal::graph_base<E>& rhs);
142 # ifndef MLN_INCLUDE_ONLY
156 graph_base<E>::graph_base()
167 graph_base<E>::id()
const
169 return static_cast<const void*
>(data_.ptr_);
179 graph_base<E>::v_other(
const edge_id_t& id_e,
const vertex_id_t& id_v)
const
181 const E *g = exact(
this);
182 mln_precondition(g->has_e(id_e));
183 mln_precondition(g->has_v(id_v));
184 mln_precondition(g->v1(id_e) == id_v
185 || g->v2(id_e) == id_v);
187 if (g->v1(id_e) == id_v)
199 graph_base<E>::has(
const util::vertex<E>& v)
const
201 return exact(
this)->has_v(v.id());
211 graph_base<E>::has(
const util::edge<E>& e)
const
213 return exact(
this)->has_e(e.id());
217 template <
typename E>
220 graph_base<E>::is_valid()
const
225 template <
typename E>
228 graph_base<E>::invalidate()
241 graph_base<E>::print_debug (std::ostream& ostr)
const
243 const E *g = exact(
this);
245 ostr <<
"graph: " << std::endl;
246 for (
unsigned v = 0; v < g->v_nmax(); ++v)
248 ostr <<
"vertex: " << v << std::endl <<
" -- adjacent vertices: ";
249 for (
unsigned n = 0; n < g->v_nmax_nbh_vertices(v); ++n)
250 ostr << g->v_ith_nbh_vertex(v, n) <<
" ";
255 ostr <<
"edges:" << std::endl;
256 for (
unsigned i = 0; i < g->e_nmax(); ++i)
257 ostr <<
"edge " << i <<
": ("
265 const util::tracked_ptr< mln::internal::data<E> >&
266 graph_base<E>::data_hook_()
const
275 # endif // ! MLN_INCLUDE_ONLY
277 template <
typename E>
280 operator==(
const util::internal::graph_base<E>& lhs,
281 const util::internal::graph_base<E>& rhs)
283 return lhs.id() == rhs.id();
288 #endif // ! MLN_UTIL_INTERNAL_GRAPH_BASE_HH