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

p_edges.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_CORE_SITE_SET_P_EDGES_HH
00027 # define MLN_CORE_SITE_SET_P_EDGES_HH
00028 
00032 
00033 # include <mln/core/concept/function.hh>
00034 # include <mln/core/concept/graph.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_edges_psite.hh>
00038 # include <mln/util/graph.hh>
00039 # include <mln/util/internal/id2element.hh>
00040 
00041 # include <mln/metal/equal.hh>
00042 
00043 
00044 namespace mln
00045 {
00046 
00047   // Forward declaration.
00048   template <typename G, typename F> struct p_edges;
00049 
00050 
00051   namespace trait
00052   {
00053     template <typename G, typename F>
00054       struct site_set_< p_edges<G, F> >
00055       {
00056         // FIXME: I don't know what to use yet!
00057         typedef trait::site_set::nsites::known   nsites;
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   } // end of namespace mln::trait
00063 
00064 
00068   //
00069   template <typename G, typename F = util::internal::id2element<G,util::edge<G> > >
00070   class p_edges
00071     : public internal::site_set_base_< mln_result(F), p_edges<G, F> >
00072   {
00073 
00074     typedef p_edges<G, F> self_;
00075     typedef internal::site_set_base_< mln_result(F), self_ > super_;
00076 
00077   public:
00078 
00080     typedef G graph_t;
00081 
00083     typedef F fun_t;
00084 
00086     typedef util::edge<G> edge;
00087 
00089     typedef util::edge<G> graph_element;
00090 
00094     p_edges();
00095 
00099     p_edges(const Graph<G>& gr);
00100 
00105     p_edges(const Graph<G>& gr, const Function<F>& f);
00106 
00112     template <typename F2>
00113     p_edges(const Graph<G>& gr, const Function<F2>& f);
00115 
00119     typedef mln_site(super_) element;
00120 
00122     typedef p_edges_psite<G, F> psite;
00123 
00125     typedef p_graph_piter< self_, mln_edge_fwd_iter(G) > fwd_piter;
00126 
00128     typedef p_graph_piter< self_, mln_edge_bkd_iter(G) > bkd_piter;
00129 
00131     typedef fwd_piter piter;
00133 
00136     unsigned nsites() const;
00137 
00139     unsigned nedges() const;
00140 
00142     bool is_valid() const;
00144     void invalidate();
00145 
00147     bool has(const psite& p) const;
00148 
00150     template <typename G2>
00151     bool has(const util::edge<G2>& e) const;
00152 
00156 
00157     // FIXME: Dummy.
00158     std::size_t memory_size() const;
00159 
00163     const G& graph() const;
00165     const F& function() const;
00167 
00168   private:
00169 
00170     G g_;
00171     F f_;
00172   };
00173 
00174 
00179   template <typename G, typename F>
00180   bool
00181   operator==(const p_edges<G, F>& lhs, const p_edges<G, F>& rhs);
00182 
00183 
00188   template <typename G, typename F>
00189   bool
00190   operator<=(const p_edges<G, F>& lhs, const p_edges<G, F>& rhs);
00191 
00192 } // end of mln
00193 
00194 
00195 # ifndef MLN_INCLUDE_ONLY
00196 
00197 namespace mln
00198 {
00199 
00200 
00201   template <typename G, typename F>
00202   inline
00203   p_edges<G, F>::p_edges()
00204   {
00205   }
00206 
00207   template <typename G, typename F>
00208   inline
00209   p_edges<G, F>::p_edges(const Graph<G>& g)
00210   {
00211     typedef util::internal::id2element<G,util::edge<G> > F_REF;
00212     mlc_equal(F, F_REF)::check();
00213 
00214     mln_precondition(exact(g).is_valid());
00215     g_ = exact(g);
00216     f_ = util::internal::id2element< G, util::edge<G> >(g);
00217   }
00218 
00219   template <typename G, typename F>
00220   inline
00221   p_edges<G, F>::p_edges(const Graph<G>& g, const Function<F>& f)
00222   {
00223     mln_precondition(exact(g).is_valid());
00224     g_ = exact(g);
00225     f_ = exact(f);
00226   }
00227 
00228   template <typename G, typename F>
00229   template <typename F2>
00230   inline
00231   p_edges<G, F>::p_edges(const Graph<G>& g, const Function<F2>& f)
00232   {
00233     mln_precondition(exact(g).is_valid());
00234     mlc_converts_to(F2,F)::check();
00235 
00236     g_ = exact(g);
00237     convert::from_to(f, f_);
00238   }
00239 
00240 
00241   template <typename G, typename F>
00242   inline
00243   unsigned
00244   p_edges<G, F>::nsites() const
00245   {
00246     return nedges();
00247   }
00248 
00249   template <typename G, typename F>
00250   inline
00251   unsigned
00252   p_edges<G, F>::nedges() const
00253   {
00254     return this->g_.e_nmax();
00255   }
00256 
00257   template <typename G, typename F>
00258   inline
00259   bool
00260   p_edges<G, F>::is_valid() const
00261   {
00262     return g_.is_valid();
00263   }
00264 
00265   template <typename G, typename F>
00266   inline
00267   void
00268   p_edges<G, F>::invalidate()
00269   {
00270     g_.invalidate();
00271   }
00272 
00273   template <typename G, typename F>
00274   inline
00275   bool
00276   p_edges<G, F>::has(const psite& p) const
00277   {
00278     mln_precondition(is_valid());
00279     return has(p.e());
00280   }
00281 
00282   template <typename G, typename F>
00283   template <typename G2>
00284   inline
00285   bool
00286   p_edges<G, F>::has(const util::edge<G2>& e) const
00287   {
00288     mln_precondition(is_valid());
00289     return e.graph().is_subgraph_of(g_) && g_.has(e) && e.is_valid();
00290   }
00291 
00292 //  template <typename G, typename F>
00293 //  inline
00294 //  bool
00295 //  p_edges<G,F>::has(unsigned edge_id) const
00296 //  {
00297 //    mln_precondition(is_valid());
00298 //    util::edge<G> e(g_, edge_id);
00299 //    return has(e);
00300 //  }
00301 
00302   template <typename G, typename F>
00303   inline
00304   std::size_t
00305   p_edges<G, F>::memory_size() const
00306   {
00307     // FIXME: Dummy; implement (see other site sets).
00308     abort();
00309     return 0;
00310   }
00311 
00312   template <typename G, typename F>
00313   inline
00314   const G&
00315   p_edges<G, F>::graph() const
00316   {
00317     mln_precondition(is_valid());
00318     return g_;
00319   }
00320 
00321   template <typename G, typename F>
00322   inline
00323   const F&
00324   p_edges<G, F>::function() const
00325   {
00326     return f_;
00327   }
00328 
00329   template <typename G, typename F>
00330   bool
00331   operator==(const p_edges<G, F>& lhs, const p_edges<G, F>& rhs)
00332   {
00333     return lhs.graph() == rhs.graph();
00334   }
00335 
00336   template <typename G, typename F>
00337   bool
00338   operator<=(const p_edges<G, F>& lhs, const p_edges<G, F>& rhs)
00339   {
00340     return lhs == rhs;
00341   }
00342 
00343 } // end of mln
00344 
00345 # endif // ! MLN_INCLUDE_ONLY
00346 
00347 #endif // ! MLN_CORE_SITE_SET_P_EDGES_HH

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