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

p_vertices.hh

00001 
00002 // Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (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     : f_(0)
00222   {
00223   }
00224 
00225   template <typename G, typename F>
00226   inline
00227   p_vertices<G,F>::p_vertices(const Graph<G>& g)
00228   {
00229     typedef util::internal::id2element<G,util::vertex<G> > F_REF;
00230     mlc_equal(F, F_REF)::check();
00231 
00232     mln_precondition(exact(g).is_valid());
00233     g_ = exact(g);
00234     f_ = util::internal::id2element< G, util::vertex<G> >(g);
00235   }
00236 
00237   template <typename G, typename F>
00238   inline
00239   p_vertices<G,F>::p_vertices(const Graph<G>& g, const Function<F>& f)
00240   {
00241     mln_precondition(exact(g).is_valid());
00242     g_ = exact(g);
00243     f_ = exact(f);
00244   }
00245 
00246   template <typename G, typename F>
00247   template <typename F2>
00248   inline
00249   p_vertices<G,F>::p_vertices(const Graph<G>& g, const Function<F2>& f)
00250   {
00251     mln_precondition(exact(g).is_valid());
00252     mlc_converts_to(F2,F)::check();
00253 
00254     g_ = exact(g);
00255     convert::from_to(f, f_);
00256   }
00257 
00258   template <typename G, typename F>
00259   template <typename F2>
00260   inline
00261   p_vertices<G,F>::p_vertices(const p_vertices<G,F2>& other)
00262   {
00263     mln_precondition(other.is_valid());
00264     mlc_converts_to(F2,F)::check();
00265 
00266     g_ = other.graph();
00267     convert::from_to(other.function(), f_);
00268   }
00269 
00270   template <typename G, typename F>
00271   inline
00272   unsigned
00273   p_vertices<G,F>::nsites() const
00274   {
00275     return nvertices();
00276   }
00277 
00278   template <typename G, typename F>
00279   inline
00280   unsigned
00281   p_vertices<G,F>::nvertices() const
00282   {
00283     return this->g_.v_nmax();
00284   }
00285 
00286   template <typename G, typename F>
00287   inline
00288   bool
00289   p_vertices<G,F>::is_valid() const
00290   {
00291     return g_.is_valid();
00292   }
00293 
00294   template <typename G, typename F>
00295   inline
00296   void
00297   p_vertices<G,F>::invalidate()
00298   {
00299     g_.invalidate();
00300   }
00301 
00302   template <typename G, typename F>
00303   inline
00304   bool
00305   p_vertices<G,F>::has(const psite& p) const
00306   {
00307     mln_precondition(is_valid());
00308     return has(p.v());
00309   }
00310 
00311   template <typename G, typename F>
00312   template <typename G2>
00313   inline
00314   bool
00315   p_vertices<G,F>::has(const util::vertex<G2>& v) const
00316   {
00317     mln_precondition(is_valid());
00318     return
00319       // Check whether if the graph is 'compatible'.
00320       v.graph().is_subgraph_of(g_) &&
00321       g_.has(v) &&
00322       // Check that the vertex id of P belongs to the range of valid
00323       // vertex ids.
00324       (v.is_valid());
00325   }
00326 
00327 //  template <typename G, typename F>
00328 //  inline
00329 //  bool
00330 //  p_vertices<G,F>::has(unsigned vertex_id) const
00331 //  {
00332 //    mln_precondition(is_valid());
00333 //    util::vertex<G> v(g_, vertex_id);
00334 //    return has(v);
00335 //  }
00336 
00337   template <typename G, typename F>
00338   inline
00339   std::size_t
00340   p_vertices<G,F>::memory_size() const
00341   {
00342     // FIXME: Dummy; implement (see other site sets).
00343     abort();
00344     return 0;
00345   }
00346 
00347   template <typename G, typename F>
00348   inline
00349   mln_result(F)
00350   p_vertices<G,F>::operator()(const psite& p) const
00351   {
00352     mln_precondition(g_.has(p.v()));
00353     return (*this)(p.v().id());
00354   }
00355 
00356   template <typename G, typename F>
00357   inline
00358   mln_result(F)
00359   p_vertices<G,F>::operator()(const util::vertex<G>& v) const
00360   {
00361     mln_precondition(g_.has_v(v));
00362     return (*this)(v.id());
00363   }
00364 
00365   template <typename G, typename F>
00366   inline
00367   mln_result(F)
00368   p_vertices<G,F>::operator()(unsigned id_v) const
00369   {
00370     mln_precondition(g_.has_v(id_v));
00371     return f_(id_v);
00372   }
00373 
00374   template <typename G, typename F>
00375   inline
00376   const G&
00377   p_vertices<G,F>::graph() const
00378   {
00379     mln_precondition(is_valid());
00380     return g_;
00381   }
00382 
00383   template <typename G, typename F>
00384   inline
00385   const F&
00386   p_vertices<G,F>::function() const
00387   {
00388     return f_;
00389   }
00390 
00391   template <typename G, typename F>
00392   bool
00393   operator==(const p_vertices<G,F>& lhs, const p_vertices<G,F>& rhs)
00394   {
00395     return (lhs.graph()) == (rhs.graph());
00396   }
00397 
00398   template <typename G, typename F>
00399   bool
00400   operator<=(const p_vertices<G,F>& lhs, const p_vertices<G,F>& rhs)
00401   {
00402     return lhs == rhs;
00403   }
00404 
00405 # endif // ! MLN_INCLUDE_ONLY
00406 
00407 } // end of mln
00408 
00409 
00410 #endif // ! MLN_CORE_SITE_SET_P_VERTICES_HH

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