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

p_vertices.hh

00001 // Copyright (C) 2008, 2009 EPITA Research and Development Laboratory
00002 // (LRDE)
00003 //
00004 // This file is part of Olena.
00005 //
00006 // Olena is free software: you can redistribute it and/or modify it under
00007 // the terms of the GNU General Public License as published by the Free
00008 // Software Foundation, version 2 of the License.
00009 //
00010 // Olena is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00017 //
00018 // As a special exception, you may use this file as part of a free
00019 // software project without restriction.  Specifically, if other files
00020 // instantiate templates or use macros or inline functions from this
00021 // file, or you compile this file and link it with other files to produce
00022 // an executable, this file does not by itself cause the resulting
00023 // executable to be covered by the GNU General Public License.  This
00024 // exception does not however invalidate any other reasons why the
00025 // executable file might be covered by the GNU General Public License.
00026 
00027 #ifndef MLN_CORE_SITE_SET_P_VERTICES_HH
00028 # define MLN_CORE_SITE_SET_P_VERTICES_HH
00029 
00033 
00034 # include <mln/core/concept/function.hh>
00035 # include <mln/core/internal/site_set_base.hh>
00036 # include <mln/core/site_set/p_graph_piter.hh>
00037 # include <mln/core/site_set/p_vertices_psite.hh>
00038 # include <mln/util/graph.hh>
00039 # include <mln/util/internal/id2element.hh>
00040 
00041 
00042 
00043 namespace mln
00044 {
00045 
00046   // Forward declaration.
00047   template <typename G, typename F> struct p_vertices;
00048 
00049 
00050   namespace trait
00051   {
00052 
00053     template <typename G, typename F>
00054       struct site_set_< p_vertices<G,F> >
00055       {
00056         typedef trait::site_set::nsites::known   nsites;
00057         // FIXME: !
00058         typedef trait::site_set::bbox::unknown   bbox;
00059         typedef trait::site_set::contents::fixed contents;
00060         typedef trait::site_set::arity::unique   arity;
00061       };
00062 
00063   } // end of namespace mln::trait
00064 
00065 
00069   //
00070   template <typename G, typename F = util::internal::id2element<G,util::vertex<G> > >
00071   class p_vertices
00072     : public internal::site_set_base_< mln_result(F), p_vertices<G,F> >
00073   {
00074 
00075     typedef p_vertices<G,F> self_;
00076     typedef internal::site_set_base_< mln_result(F), self_ > super_;
00077 
00078   public:
00079 
00081     typedef G graph_t;
00082 
00084     typedef F fun_t;
00085 
00087     typedef util::vertex<G> vertex;
00088 
00089 
00091     typedef util::vertex<G> graph_element;
00092 
00093 
00095     p_vertices();
00096 
00100     p_vertices(const Graph<G>& gr);
00101 
00105     p_vertices(const Graph<G>& gr, const Function<F>& f);
00106 
00111     template <typename F2>
00112     p_vertices(const Graph<G>& gr, const Function<F2>& f);
00114 
00116     template <typename F2>
00117     p_vertices(const p_vertices<G,F2>& other);
00118 
00121 
00123     typedef mln_site(super_) element;
00124 
00126     typedef p_vertices_psite<G,F> psite;
00127 
00129     typedef p_graph_piter< self_, mln_vertex_fwd_iter(G) > fwd_piter;
00130 
00132     typedef p_graph_piter< self_, mln_vertex_bkd_iter(G) > bkd_piter;
00133 
00135     typedef fwd_piter piter;
00136 
00138 
00139 
00144     unsigned nsites() const;
00145 
00147     unsigned nvertices() const;
00148 
00150     bool is_valid() const;
00151 
00153     void invalidate();
00154 
00156     bool has(const psite& p) const;
00157 
00159     template <typename G2>
00160     bool has(const util::vertex<G2>& v) const;
00161 
00165 
00166     // FIXME: Dummy.
00167     std::size_t memory_size() const;
00168 
00171     mln_result(F) operator()(const psite& p) const;
00172     mln_result(F) operator()(const util::vertex<G>& p) const;
00173     mln_result(F) operator()(unsigned id_v) const;
00175 
00179     const G& graph() const;
00181     const F& function() const;
00183 
00184   private:
00185     G g_;
00186     F f_;
00187   };
00188 
00189 
00194   template <typename G, typename F>
00195   bool
00196   operator==(const p_vertices<G,F>& lhs, const p_vertices<G,F>& rhs);
00197 
00198 
00199   /* FIXME: Extend the `ord' mechanism instead of this ill-defined
00200      pseudo-order. */
00201 
00210   template <typename G, typename F>
00211   bool
00212   operator<=(const p_vertices<G,F>& lhs, const p_vertices<G,F>& rhs);
00213 
00214 
00215 
00216 # ifndef MLN_INCLUDE_ONLY
00217 
00218   template <typename G, typename F>
00219   inline
00220   p_vertices<G,F>::p_vertices()
00221   {
00222   }
00223 
00224   template <typename G, typename F>
00225   inline
00226   p_vertices<G,F>::p_vertices(const Graph<G>& g)
00227   {
00228     typedef util::internal::id2element<G,util::vertex<G> > F_REF;
00229     mlc_equal(F, F_REF)::check();
00230 
00231     mln_precondition(exact(g).is_valid());
00232     g_ = exact(g);
00233     f_ = util::internal::id2element< G, util::vertex<G> >(g);
00234   }
00235 
00236   template <typename G, typename F>
00237   inline
00238   p_vertices<G,F>::p_vertices(const Graph<G>& g, const Function<F>& f)
00239   {
00240     mln_precondition(exact(g).is_valid());
00241     g_ = exact(g);
00242     f_ = exact(f);
00243   }
00244 
00245   template <typename G, typename F>
00246   template <typename F2>
00247   inline
00248   p_vertices<G,F>::p_vertices(const Graph<G>& g, const Function<F2>& f)
00249   {
00250     mln_precondition(exact(g).is_valid());
00251     mlc_converts_to(F2,F)::check();
00252 
00253     g_ = exact(g);
00254     convert::from_to(f, f_);
00255   }
00256 
00257   template <typename G, typename F>
00258   template <typename F2>
00259   inline
00260   p_vertices<G,F>::p_vertices(const p_vertices<G,F2>& other)
00261   {
00262     mln_precondition(other.is_valid());
00263     mlc_converts_to(F2,F)::check();
00264 
00265     g_ = other.graph();
00266     convert::from_to(other.function(), f_);
00267   }
00268 
00269   template <typename G, typename F>
00270   inline
00271   unsigned
00272   p_vertices<G,F>::nsites() const
00273   {
00274     return nvertices();
00275   }
00276 
00277   template <typename G, typename F>
00278   inline
00279   unsigned
00280   p_vertices<G,F>::nvertices() const
00281   {
00282     return this->g_.v_nmax();
00283   }
00284 
00285   template <typename G, typename F>
00286   inline
00287   bool
00288   p_vertices<G,F>::is_valid() const
00289   {
00290     return g_.is_valid();
00291   }
00292 
00293   template <typename G, typename F>
00294   inline
00295   void
00296   p_vertices<G,F>::invalidate()
00297   {
00298     g_.invalidate();
00299   }
00300 
00301   template <typename G, typename F>
00302   inline
00303   bool
00304   p_vertices<G,F>::has(const psite& p) const
00305   {
00306     mln_precondition(is_valid());
00307     return has(p.v());
00308   }
00309 
00310   template <typename G, typename F>
00311   template <typename G2>
00312   inline
00313   bool
00314   p_vertices<G,F>::has(const util::vertex<G2>& v) const
00315   {
00316     mln_precondition(is_valid());
00317     return
00318       // Check whether if the graph is 'compatible'.
00319       v.graph().is_subgraph_of(g_) &&
00320       g_.has(v) &&
00321       // Check that the vertex id of P belongs to the range of valid
00322       // vertex ids.
00323       (v.is_valid());
00324   }
00325 
00326 //  template <typename G, typename F>
00327 //  inline
00328 //  bool
00329 //  p_vertices<G,F>::has(unsigned vertex_id) const
00330 //  {
00331 //    mln_precondition(is_valid());
00332 //    util::vertex<G> v(g_, vertex_id);
00333 //    return has(v);
00334 //  }
00335 
00336   template <typename G, typename F>
00337   inline
00338   std::size_t
00339   p_vertices<G,F>::memory_size() const
00340   {
00341     // FIXME: Dummy; implement (see other site sets).
00342     abort();
00343     return 0;
00344   }
00345 
00346   template <typename G, typename F>
00347   inline
00348   mln_result(F)
00349   p_vertices<G,F>::operator()(const psite& p) const
00350   {
00351     mln_precondition(g_.has(p.v()));
00352     return (*this)(p.v().id());
00353   }
00354 
00355   template <typename G, typename F>
00356   inline
00357   mln_result(F)
00358   p_vertices<G,F>::operator()(const util::vertex<G>& v) const
00359   {
00360     mln_precondition(g_.has_v(v));
00361     return (*this)(v.id());
00362   }
00363 
00364   template <typename G, typename F>
00365   inline
00366   mln_result(F)
00367   p_vertices<G,F>::operator()(unsigned id_v) const
00368   {
00369     mln_precondition(g_.has_v(id_v));
00370     return f_(id_v);
00371   }
00372 
00373   template <typename G, typename F>
00374   inline
00375   const G&
00376   p_vertices<G,F>::graph() const
00377   {
00378     mln_precondition(is_valid());
00379     return g_;
00380   }
00381 
00382   template <typename G, typename F>
00383   inline
00384   const F&
00385   p_vertices<G,F>::function() const
00386   {
00387     return f_;
00388   }
00389 
00390   template <typename G, typename F>
00391   bool
00392   operator==(const p_vertices<G,F>& lhs, const p_vertices<G,F>& rhs)
00393   {
00394     return (lhs.graph()) == (rhs.graph());
00395   }
00396 
00397   template <typename G, typename F>
00398   bool
00399   operator<=(const p_vertices<G,F>& lhs, const p_vertices<G,F>& rhs)
00400   {
00401     return lhs == rhs;
00402   }
00403 
00404 # endif // ! MLN_INCLUDE_ONLY
00405 
00406 } // end of mln
00407 
00408 
00409 #endif // ! MLN_CORE_SITE_SET_P_VERTICES_HH

Generated on Tue Oct 4 2011 15:24:18 for Milena (Olena) by  doxygen 1.7.1