00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef MLN_UTIL_VERTEX_HH
00028 # define MLN_UTIL_VERTEX_HH
00029
00030 # include <iostream>
00031 # include <mln/util/graph_ids.hh>
00032 # include <mln/util/internal/vertex_impl.hh>
00033 # include <mln/core/concept/proxy.hh>
00034 # include <mln/core/concept/site.hh>
00035 # include <mln/util/graph_ids.hh>
00036 # include <mln/util/edge.hh>
00037
00041
00042
00043
00044 namespace mln
00045 {
00046
00047
00048 namespace util { template<typename G> class vertex; }
00049 namespace util { template<typename G> class edge; }
00050
00052 template <typename E>
00053 struct Vertex
00054 {
00055 };
00056
00057 template <>
00058 struct Vertex<void>
00059 {
00060 typedef Site<void> super;
00061 };
00062
00063
00064
00065 namespace util
00066 {
00067
00069
00070 template<typename G>
00071 class vertex
00072 : public Site< vertex<G> >,
00073 public internal::vertex_impl_<G>
00074 {
00075 public:
00077 typedef Vertex<void> Category;
00078
00080 typedef typename vertex_id_t::value_t id_value_t;
00081
00083 typedef vertex_id_t id_t;
00084
00086 typedef G graph_t;
00087
00090 vertex();
00091 explicit vertex(const G& g);
00092 vertex(const G& g, const id_value_t& id);
00093 vertex(const G& g, const vertex_id_t& id);
00095
00097 bool is_valid() const;
00099 void invalidate();
00100
00102 vertex_id_t other(const edge_id_t& id_e) const;
00103
00105 edge_id_t ith_nbh_edge(unsigned i) const;
00106
00110 unsigned nmax_nbh_edges() const;
00111
00113 vertex_id_t ith_nbh_vertex(unsigned i) const;
00114
00116 unsigned nmax_nbh_vertices() const;
00117
00119 edge<G> edge_with(const vertex<G>& v_id) const;
00120
00122 void change_graph(const G& g);
00123
00125 void update_id(const vertex_id_t& id);
00126
00128 const G& graph() const;
00129
00131 const vertex_id_t& id() const;
00132
00135 operator vertex_id_t() const;
00136
00137 protected:
00138 G g_;
00139 vertex_id_t id_;
00140 };
00141
00142
00144 template <typename G>
00145 std::ostream&
00146 operator<<(std::ostream& ostr, const vertex<G>& v);
00147
00150 template<typename G>
00151 bool
00152 operator==(const vertex<G>& v1, const vertex<G>& v2);
00153
00154
00156 template<typename G>
00157 bool
00158 operator<(const vertex<G>& lhs, const vertex<G>& rhs);
00159
00160
00161 }
00162
00163
00164
00165 namespace internal
00166 {
00167
00170
00171 template <typename G, typename E>
00172 struct subject_impl< const util::vertex<G>, E >
00173 {
00174
00175
00176
00177
00178
00179 const G& graph() const;
00180 const util::vertex_id_t& id() const;
00181
00182 util::vertex_id_t other(const util::edge_id_t& id_e) const;
00183 util::edge_id_t ith_nbh_edge(unsigned i) const;
00184 unsigned nmax_nbh_edges() const;
00185 util::vertex_id_t ith_nbh_vertex(unsigned i) const;
00186 unsigned nmax_nbh_vertices() const;
00187 util::edge<G> edge_with(const util::vertex<G>& v) const;
00188
00189 private:
00190 const E& exact_() const;
00191 };
00192
00193 template <typename G, typename E>
00194 struct subject_impl< util::vertex<G>, E > :
00195 subject_impl< const util::vertex<G>, E >
00196 {
00197 void invalidate();
00198 void change_graph(const G& g);
00199 void update_id(const util::vertex_id_t& id);
00200
00201 private:
00202 E& exact_();
00203 };
00204
00206
00207 }
00208
00209 }
00210
00211
00212
00213
00214 # ifndef MLN_INCLUDE_ONLY
00215
00216 namespace mln
00217 {
00218
00219 namespace util
00220 {
00221
00222 template <typename G>
00223 inline
00224 vertex<G>::vertex()
00225 {
00226 invalidate();
00227 }
00228
00229 template <typename G>
00230 inline
00231 vertex<G>::vertex(const G& g)
00232 : g_(g)
00233 {
00234 invalidate();
00235 }
00236
00237 template<typename G>
00238 inline
00239 vertex<G>::vertex(const G& g, const id_value_t& id)
00240 : g_(g), id_(id)
00241 {
00242 mln_assertion(is_valid());
00243 }
00244
00245 template<typename G>
00246 inline
00247 vertex<G>::vertex(const G& g, const vertex_id_t& id)
00248 : g_(g), id_(id)
00249 {
00250 mln_assertion(is_valid());
00251 }
00252
00253 template<typename G>
00254 inline
00255 bool
00256 vertex<G>::is_valid() const
00257 {
00258 return id_ != mln_max(unsigned) && g_.is_valid() && g_.has_v(id_);
00259 }
00260
00261 template<typename G>
00262 inline
00263 void
00264 vertex<G>::invalidate()
00265 {
00266 id_ = mln_max(unsigned);
00267 }
00268
00269 template<typename G>
00270 inline
00271 vertex_id_t
00272 vertex<G>::other(const edge_id_t& id_e) const
00273 {
00274 mln_precondition(g_.has_v(id_));
00275 mln_precondition(g_.has_e(id_e));
00276 mln_precondition(g_.v1(id_e) == id_ || g_.v2(id_e) == id_);
00277 return g_.v_other(id_e, id_);
00278 }
00279
00280 template<typename G>
00281 inline
00282 edge_id_t
00283 vertex<G>::ith_nbh_edge(unsigned i) const
00284 {
00285 mln_precondition(g_.has_v(id_));
00286 return g_.v_ith_nbh_edge(id_, i);
00287 }
00288
00289 template<typename G>
00290 inline
00291 unsigned
00292 vertex<G>::nmax_nbh_edges() const
00293 {
00294 mln_precondition(g_.has_v(id_));
00295 return g_.v_nmax_nbh_edges(id_);
00296 }
00297
00298 template<typename G>
00299 inline
00300 vertex_id_t
00301 vertex<G>::ith_nbh_vertex(unsigned i) const
00302 {
00303 mln_precondition(g_.has_v(id_));
00304 return g_.v_ith_nbh_vertex(id_, i);
00305 }
00306
00307 template<typename G>
00308 inline
00309 unsigned
00310 vertex<G>::nmax_nbh_vertices() const
00311 {
00312 mln_precondition(g_.has_v(id_));
00313 return g_.v_nmax_nbh_vertices(id_);
00314 }
00315
00316 template<typename G>
00317 inline
00318 edge<G>
00319 vertex<G>::edge_with(const vertex<G>& v) const
00320 {
00321 mln_precondition(g_.has_v(id_));
00322 mln_precondition(g_.has_v(v));
00323 return g_.edge(*this, v);
00324 }
00325
00326 template<typename G>
00327 inline
00328 void
00329 vertex<G>::change_graph(const G& g)
00330 {
00331 mln_precondition(g.is_valid());
00332 g_ = g;
00333 }
00334
00335 template<typename G>
00336 inline
00337 void
00338 vertex<G>::update_id(const vertex_id_t& id)
00339 {
00340 id_ = id;
00341 }
00342
00343 template<typename G>
00344 inline
00345 const G&
00346 vertex<G>::graph() const
00347 {
00348 return g_;
00349 }
00350
00351 template<typename G>
00352 inline
00353 const vertex_id_t&
00354 vertex<G>::id() const
00355 {
00356 return id_;
00357 }
00358
00359 template<typename G>
00360 inline
00361 vertex<G>::operator vertex_id_t() const
00362 {
00363 return id_;
00364 }
00365
00366
00367 template <typename G>
00368 inline
00369 std::ostream&
00370 operator<<(std::ostream& ostr, const vertex<G>& v)
00371 {
00372 return ostr << v.id();
00373 }
00374
00375 template<typename G>
00376 inline
00377 bool
00378 operator==(const vertex<G>& v1, const vertex<G>& v2)
00379 {
00380 return v1.id() == v2.id()
00381 && (v1.graph().is_subgraph_of(v2.graph())
00382 || v2.graph().is_subgraph_of(v1.graph()));
00383 }
00384
00385 template<typename G>
00386 inline
00387 bool
00388 operator<(const vertex<G>& lhs, const vertex<G>& rhs)
00389 {
00390 return lhs.id() < rhs.id();
00391 }
00392
00393 }
00394
00395
00396 namespace internal
00397 {
00398
00399 template <typename G, typename E>
00400 inline
00401 const E&
00402 subject_impl< const util::vertex<G>, E >::exact_() const
00403 {
00404 return internal::force_exact<const E>(*this);
00405 }
00406
00407 template <typename G, typename E>
00408 inline
00409 const G&
00410 subject_impl< const util::vertex<G>, E >::graph() const
00411 {
00412 return exact_().get_subject().graph();
00413 }
00414
00415 template <typename G, typename E>
00416 inline
00417 const util::vertex_id_t&
00418 subject_impl< const util::vertex<G>, E >::id() const
00419 {
00420 return exact_().get_subject().id();
00421 };
00422
00423
00424
00425 template <typename G, typename E>
00426 inline
00427 util::vertex_id_t
00428 subject_impl< const util::vertex<G>, E >::other(const util::edge_id_t& id_e) const
00429 {
00430 return exact_().get_subject().other(id_e);
00431 }
00432
00433 template <typename G, typename E>
00434 inline
00435 util::edge_id_t
00436 subject_impl< const util::vertex<G>, E >::ith_nbh_edge(unsigned i) const
00437 {
00438 return exact_().get_subject().ith_nbh_edge(i);
00439 }
00440
00441 template <typename G, typename E>
00442 inline
00443 unsigned
00444 subject_impl< const util::vertex<G>, E >::nmax_nbh_edges() const
00445 {
00446 return exact_().get_subject().nmax_nbh_edges();
00447 }
00448
00449 template <typename G, typename E>
00450 inline
00451 util::vertex_id_t
00452 subject_impl< const util::vertex<G>, E >::ith_nbh_vertex(unsigned i) const
00453 {
00454 return exact_().get_subject().ith_nbh_vertex(i);
00455 }
00456
00457 template <typename G, typename E>
00458 inline
00459 unsigned
00460 subject_impl< const util::vertex<G>, E >::nmax_nbh_vertices() const
00461 {
00462 return exact_().get_subject().nmax_nbh_vertices();
00463 }
00464
00465 template <typename G, typename E>
00466 inline
00467 util::edge<G>
00468 subject_impl< const util::vertex<G>, E >::edge_with(const util::vertex<G>& v) const
00469 {
00470 return exact_().get_subject().edge_with(v);
00471 }
00472
00473
00474 template <typename G, typename E>
00475 inline
00476 E&
00477 subject_impl< util::vertex<G>, E >::exact_()
00478 {
00479 return internal::force_exact<E>(*this);
00480 }
00481
00482 template <typename G, typename E>
00483 inline
00484 void
00485 subject_impl< util::vertex<G>, E >::invalidate()
00486 {
00487 exact_().get_subject().invalidate();
00488 }
00489
00490 template <typename G, typename E>
00491 inline
00492 void
00493 subject_impl< util::vertex<G>, E >::change_graph(const G& g)
00494 {
00495 exact_().get_subject().change_graph(g);
00496 }
00497
00498 template <typename G, typename E>
00499 inline
00500 void
00501 subject_impl< util::vertex<G>, E >::update_id(const util::vertex_id_t& id)
00502 {
00503 exact_().get_subject().update_id(id);
00504 };
00505
00506 }
00507
00508 }
00509
00510 # endif // ! MLN_INCLUDE_ONLY
00511
00512
00513 #endif // ! MLN_UTIL_VERTEX_HH