• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

vertex.hh

00001 // Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE)
00002 //
00003 // This file is part of Olena.
00004 //
00005 // Olena is free software: you can redistribute it and/or modify it under
00006 // the terms of the GNU General Public License as published by the Free
00007 // Software Foundation, version 2 of the License.
00008 //
00009 // Olena is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 // As a special exception, you may use this file as part of a free
00018 // software project without restriction.  Specifically, if other files
00019 // instantiate templates or use macros or inline functions from this
00020 // file, or you compile this file and link it with other files to produce
00021 // an executable, this file does not by itself cause the resulting
00022 // executable to be covered by the GNU General Public License.  This
00023 // exception does not however invalidate any other reasons why the
00024 // executable file might be covered by the GNU General Public License.
00025 
00026 #ifndef MLN_UTIL_VERTEX_HH
00027 # define MLN_UTIL_VERTEX_HH
00028 
00029 # include <iostream>
00030 # include <mln/util/graph_ids.hh>
00031 # include <mln/util/internal/vertex_impl.hh>
00032 # include <mln/core/concept/proxy.hh>
00033 # include <mln/core/concept/site.hh>
00034 # include <mln/util/graph_ids.hh>
00035 # include <mln/util/edge.hh>
00036 
00040 
00041 
00042 
00043 namespace mln
00044 {
00045 
00046   // Forward declaration.
00047   namespace util { template<typename G> class vertex; }
00048   namespace util { template<typename G> class edge; }
00049 
00051   template <typename E>
00052   struct Vertex
00053   {
00054   };
00055 
00056   template <>
00057   struct Vertex<void>
00058   {
00059     typedef Site<void> super;
00060   };
00061 
00062 
00063 
00064   namespace util
00065   {
00066 
00068 
00069     template<typename G>
00070     class vertex
00071       : public Site< vertex<G> >,
00072         public internal::vertex_impl_<G>
00073     {
00074     public:
00076       typedef Vertex<void> Category;
00077 
00079       typedef typename vertex_id_t::value_t id_value_t;
00080 
00082       typedef vertex_id_t id_t;
00083 
00085       typedef G graph_t;
00086 
00089       vertex();
00090       explicit vertex(const G& g);
00091       vertex(const G& g, const id_value_t& id);
00092       vertex(const G& g, const vertex_id_t& id);
00094 
00096       bool is_valid() const;
00098       void invalidate();
00099 
00101       vertex_id_t other(const edge_id_t& id_e) const;
00102 
00104       edge_id_t ith_nbh_edge(unsigned i) const;
00105 
00109       unsigned nmax_nbh_edges() const;
00110 
00112       vertex_id_t ith_nbh_vertex(unsigned i) const;
00113 
00115       unsigned nmax_nbh_vertices() const;
00116 
00118       edge<G> edge_with(const vertex<G>& v_id) const;
00119 
00121       void change_graph(const G& g);
00122 
00124       void update_id(const vertex_id_t& id);
00125 
00127       const G& graph() const;
00128 
00130       const vertex_id_t& id() const;
00131 
00134       operator vertex_id_t() const;
00135 
00136     protected:
00137       G g_;
00138       vertex_id_t id_;
00139     };
00140 
00141 
00143     template <typename G>
00144     std::ostream&
00145     operator<<(std::ostream& ostr, const vertex<G>& v);
00146 
00149     template<typename G>
00150     bool
00151     operator==(const vertex<G>& v1, const vertex<G>& v2);
00152 
00153 
00155     template<typename G>
00156     bool
00157     operator<(const vertex<G>& lhs, const vertex<G>& rhs);
00158 
00159 
00160   } // end of namespace mln::util
00161 
00162 
00163 
00164   namespace internal
00165   {
00166 
00169 
00170     template <typename G, typename E>
00171     struct subject_impl< const util::vertex<G>, E >
00172     {
00173 //      Can't be provided since there is an ambiguity with the iterator's
00174 //      member.
00175 //
00176 //      bool is_valid() const;
00177 
00178       const G& graph() const;
00179       const util::vertex_id_t& id() const;
00180 
00181       util::vertex_id_t other(const util::edge_id_t& id_e) const;
00182       util::edge_id_t ith_nbh_edge(unsigned i) const;
00183       unsigned nmax_nbh_edges() const;
00184       util::vertex_id_t ith_nbh_vertex(unsigned i) const;
00185       unsigned nmax_nbh_vertices() const;
00186       util::edge<G> edge_with(const util::vertex<G>& v) const;
00187 
00188     private:
00189       const E& exact_() const;
00190     };
00191 
00192     template <typename G, typename E>
00193     struct subject_impl<       util::vertex<G>, E > :
00194       subject_impl< const util::vertex<G>, E >
00195     {
00196       void invalidate();
00197       void change_graph(const G& g);
00198       void update_id(const util::vertex_id_t& id);
00199 
00200     private:
00201       E& exact_();
00202     };
00203 
00205 
00206   } // end of namespace mln::internal
00207 
00208 } // end of namespace mln
00209 
00210 
00211 
00212 
00213 # ifndef MLN_INCLUDE_ONLY
00214 
00215 namespace mln
00216 {
00217 
00218   namespace util
00219   {
00220 
00221     template <typename G>
00222     inline
00223     vertex<G>::vertex()
00224     {
00225       invalidate();
00226     }
00227 
00228     template <typename G>
00229     inline
00230     vertex<G>::vertex(const G& g)
00231       : g_(g)
00232     {
00233       invalidate();
00234     }
00235 
00236     template<typename G>
00237     inline
00238     vertex<G>::vertex(const G& g, const id_value_t& id)
00239       : g_(g), id_(id)
00240     {
00241       mln_assertion(is_valid());
00242     }
00243 
00244     template<typename G>
00245     inline
00246     vertex<G>::vertex(const G& g, const vertex_id_t& id)
00247       : g_(g), id_(id)
00248     {
00249       mln_assertion(is_valid());
00250     }
00251 
00252     template<typename G>
00253     inline
00254     bool
00255     vertex<G>::is_valid() const
00256     {
00257       return id_ != mln_max(unsigned) && g_.is_valid() && g_.has_v(id_);
00258     }
00259 
00260     template<typename G>
00261     inline
00262     void
00263     vertex<G>::invalidate()
00264     {
00265       id_ = mln_max(unsigned);
00266     }
00267 
00268     template<typename G>
00269     inline
00270     vertex_id_t
00271     vertex<G>::other(const edge_id_t& id_e) const
00272     {
00273       mln_precondition(g_.has_v(id_));
00274       mln_precondition(g_.has_e(id_e));
00275       mln_precondition(g_.v1(id_e) == id_ || g_.v2(id_e) == id_);
00276       return g_.v_other(id_e, id_);
00277     }
00278 
00279     template<typename G>
00280     inline
00281     edge_id_t
00282     vertex<G>::ith_nbh_edge(unsigned i) const
00283     {
00284       mln_precondition(g_.has_v(id_));
00285       return g_.v_ith_nbh_edge(id_, i);
00286     }
00287 
00288     template<typename G>
00289     inline
00290     unsigned
00291     vertex<G>::nmax_nbh_edges() const
00292     {
00293       mln_precondition(g_.has_v(id_));
00294       return g_.v_nmax_nbh_edges(id_);
00295     }
00296 
00297     template<typename G>
00298     inline
00299     vertex_id_t
00300     vertex<G>::ith_nbh_vertex(unsigned i) const
00301     {
00302       mln_precondition(g_.has_v(id_));
00303       return g_.v_ith_nbh_vertex(id_, i);
00304     }
00305 
00306     template<typename G>
00307     inline
00308     unsigned
00309     vertex<G>::nmax_nbh_vertices() const
00310     {
00311       mln_precondition(g_.has_v(id_));
00312       return g_.v_nmax_nbh_vertices(id_);
00313     }
00314 
00315     template<typename G>
00316     inline
00317     edge<G>
00318     vertex<G>::edge_with(const vertex<G>& v) const
00319     {
00320       mln_precondition(g_.has_v(id_));
00321       mln_precondition(g_.has_v(v));
00322       return g_.edge(*this, v);
00323     }
00324 
00325     template<typename G>
00326     inline
00327     void
00328     vertex<G>::change_graph(const G& g)
00329     {
00330       g_ = g;
00331     }
00332 
00333     template<typename G>
00334     inline
00335     void
00336     vertex<G>::update_id(const vertex_id_t& id)
00337     {
00338       id_ = id;
00339     }
00340 
00341     template<typename G>
00342     inline
00343     const G&
00344     vertex<G>::graph() const
00345     {
00346       return g_;
00347     }
00348 
00349     template<typename G>
00350     inline
00351     const vertex_id_t&
00352     vertex<G>::id() const
00353     {
00354       return id_;
00355     }
00356 
00357     template<typename G>
00358     inline
00359     vertex<G>::operator vertex_id_t() const
00360     {
00361       return id_;
00362     }
00363 
00364 
00365     template <typename G>
00366     inline
00367     std::ostream&
00368     operator<<(std::ostream& ostr, const vertex<G>& v)
00369     {
00370       return ostr << v.id();
00371     }
00372 
00373     template<typename G>
00374     inline
00375     bool
00376     operator==(const vertex<G>& v1, const vertex<G>& v2)
00377     {
00378       return v1.id() == v2.id()
00379               && (v1.graph().is_subgraph_of(v2.graph())
00380                   || v2.graph().is_subgraph_of(v1.graph()));
00381     }
00382 
00383     template<typename G>
00384     inline
00385     bool
00386     operator<(const vertex<G>& lhs, const vertex<G>& rhs)
00387     {
00388       return lhs.id() < rhs.id();
00389     }
00390 
00391   } // end of namespace mln::util
00392 
00393 
00394   namespace internal
00395   {
00396 
00397     template <typename G, typename E>
00398     inline
00399     const E&
00400     subject_impl< const util::vertex<G>, E >::exact_() const
00401     {
00402       return internal::force_exact<const E>(*this);
00403     }
00404 
00405     template <typename G, typename E>
00406     inline
00407     const G&
00408     subject_impl< const util::vertex<G>, E >::graph() const
00409     {
00410       return exact_().get_subject().graph();
00411     }
00412 
00413     template <typename G, typename E>
00414     inline
00415     const util::vertex_id_t&
00416     subject_impl< const util::vertex<G>, E >::id() const
00417     {
00418       return exact_().get_subject().id();
00419     };
00420 
00421 
00422 
00423     template <typename G, typename E>
00424     inline
00425     util::vertex_id_t
00426     subject_impl< const util::vertex<G>, E >::other(const util::edge_id_t& id_e) const
00427     {
00428       return exact_().get_subject().other(id_e);
00429     }
00430 
00431     template <typename G, typename E>
00432     inline
00433     util::edge_id_t
00434     subject_impl< const util::vertex<G>, E >::ith_nbh_edge(unsigned i) const
00435     {
00436       return exact_().get_subject().ith_nbh_edge(i);
00437     }
00438 
00439     template <typename G, typename E>
00440     inline
00441     unsigned
00442     subject_impl< const util::vertex<G>, E >::nmax_nbh_edges() const
00443     {
00444       return exact_().get_subject().nmax_nbh_edges();
00445     }
00446 
00447     template <typename G, typename E>
00448     inline
00449     util::vertex_id_t
00450     subject_impl< const util::vertex<G>, E >::ith_nbh_vertex(unsigned i) const
00451     {
00452       return exact_().get_subject().ith_nbh_vertex(i);
00453     }
00454 
00455     template <typename G, typename E>
00456     inline
00457     unsigned
00458     subject_impl< const util::vertex<G>, E >::nmax_nbh_vertices() const
00459     {
00460       return exact_().get_subject().nmax_nbh_vertices();
00461     }
00462 
00463     template <typename G, typename E>
00464     inline
00465     util::edge<G>
00466     subject_impl< const util::vertex<G>, E >::edge_with(const util::vertex<G>& v) const
00467     {
00468       return exact_().get_subject().edge_with(v);
00469     }
00470 
00471 
00472     template <typename G, typename E>
00473     inline
00474     E&
00475     subject_impl<       util::vertex<G>, E >::exact_()
00476     {
00477       return internal::force_exact<E>(*this);
00478     }
00479 
00480     template <typename G, typename E>
00481     inline
00482     void
00483     subject_impl<       util::vertex<G>, E >::invalidate()
00484     {
00485       exact_().get_subject().invalidate();
00486     }
00487 
00488     template <typename G, typename E>
00489     inline
00490     void
00491     subject_impl<       util::vertex<G>, E >::change_graph(const G& g)
00492     {
00493       exact_().get_subject().change_graph(g);
00494     }
00495 
00496     template <typename G, typename E>
00497     inline
00498     void
00499     subject_impl<       util::vertex<G>, E >::update_id(const util::vertex_id_t& id)
00500     {
00501       exact_().get_subject().update_id(id);
00502     };
00503 
00504   } // end of namespace mln::internal
00505 
00506 } // end of namespace mln
00507 
00508 # endif // ! MLN_INCLUDE_ONLY
00509 
00510 
00511 #endif // ! MLN_UTIL_VERTEX_HH

Generated on Thu Sep 8 2011 18:33:02 for Milena (Olena) by  doxygen 1.7.1