Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
p_edges.hh
1 // Copyright (C) 2008, 2009, 2011 EPITA Research and Development
2 // Laboratory (LRDE)
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #ifndef MLN_CORE_SITE_SET_P_EDGES_HH
28 # define MLN_CORE_SITE_SET_P_EDGES_HH
29 
33 
34 # include <mln/core/concept/function.hh>
35 # include <mln/core/concept/graph.hh>
36 # include <mln/core/internal/site_set_base.hh>
37 # include <mln/core/site_set/p_graph_piter.hh>
38 # include <mln/core/site_set/p_edges_psite.hh>
39 # include <mln/util/graph.hh>
40 # include <mln/util/internal/id2element.hh>
41 
42 # include <mln/metal/equal.hh>
43 
44 
45 namespace mln
46 {
47 
48  // Forward declaration.
49  template <typename G, typename F> class p_edges;
50 
51 
52  namespace trait
53  {
54  template <typename G, typename F>
55  struct site_set_< p_edges<G, F> >
56  {
57  // FIXME: I don't know what to use yet!
58  typedef trait::site_set::nsites::known nsites;
59  typedef trait::site_set::bbox::unknown bbox;
60  typedef trait::site_set::contents::fixed contents;
61  typedef trait::site_set::arity::unique arity;
62  };
63  } // end of namespace mln::trait
64 
65 
69  //
70  template <typename G, typename F = util::internal::id2element<G,util::edge<G> > >
71  class p_edges
72  : public internal::site_set_base_< mln_result(F), p_edges<G, F> >
73  {
74 
75  typedef p_edges<G, F> self_;
76  typedef internal::site_set_base_< mln_result(F), self_ > super_;
77 
78  public:
79 
81  typedef G graph_t;
82 
84  typedef F fun_t;
85 
88 
91 
95  p_edges();
96 
100  p_edges(const Graph<G>& gr);
101 
106  p_edges(const Graph<G>& gr, const Function<F>& f);
107 
113  template <typename F2>
114  p_edges(const Graph<G>& gr, const Function<F2>& f);
116 
120  typedef mln_site(super_) element;
121 
123  typedef p_edges_psite<G, F> psite;
124 
126  typedef p_graph_piter< self_, mln_edge_fwd_iter(G) > fwd_piter;
127 
129  typedef p_graph_piter< self_, mln_edge_bkd_iter(G) > bkd_piter;
130 
132  typedef fwd_piter piter;
134 
137  unsigned nsites() const;
138 
140  unsigned nedges() const;
141 
143  bool is_valid() const;
145  void invalidate();
146 
148  bool has(const psite& p) const;
149 
151  template <typename G2>
152  bool has(const util::edge<G2>& e) const;
153 
157 
158  // FIXME: Dummy.
159  std::size_t memory_size() const;
160 
164  const G& graph() const;
166  const F& function() const;
168 
169  private:
170 
171  G g_;
172  F f_;
173  };
174 
175 
180  template <typename G, typename F>
181  bool
182  operator==(const p_edges<G, F>& lhs, const p_edges<G, F>& rhs);
183 
184 
189  template <typename G, typename F>
190  bool
191  operator<=(const p_edges<G, F>& lhs, const p_edges<G, F>& rhs);
192 
193 } // end of mln
194 
195 
196 # ifndef MLN_INCLUDE_ONLY
197 
198 namespace mln
199 {
200 
201 
202  template <typename G, typename F>
203  inline
205  {
206  }
207 
208  template <typename G, typename F>
209  inline
211  {
212  typedef util::internal::id2element<G,util::edge<G> > F_REF;
213  mlc_equal(F, F_REF)::check();
214 
215  mln_precondition(exact(g).is_valid());
216  g_ = exact(g);
217  f_ = util::internal::id2element< G, util::edge<G> >(g);
218  }
219 
220  template <typename G, typename F>
221  inline
223  {
224  mln_precondition(exact(g).is_valid());
225  g_ = exact(g);
226  f_ = exact(f);
227  }
228 
229  template <typename G, typename F>
230  template <typename F2>
231  inline
233  {
234  mln_precondition(exact(g).is_valid());
235  mlc_converts_to(F2,F)::check();
236 
237  g_ = exact(g);
238  convert::from_to(f, f_);
239  }
240 
241 
242  template <typename G, typename F>
243  inline
244  unsigned
246  {
247  return nedges();
248  }
249 
250  template <typename G, typename F>
251  inline
252  unsigned
254  {
255  return this->g_.e_nmax();
256  }
257 
258  template <typename G, typename F>
259  inline
260  bool
262  {
263  return g_.is_valid();
264  }
265 
266  template <typename G, typename F>
267  inline
268  void
270  {
271  g_.invalidate();
272  }
273 
274  template <typename G, typename F>
275  inline
276  bool
277  p_edges<G, F>::has(const psite& p) const
278  {
279  mln_precondition(is_valid());
280  return has(p.e());
281  }
282 
283  template <typename G, typename F>
284  template <typename G2>
285  inline
286  bool
288  {
289  mln_precondition(is_valid());
290  return e.graph().is_subgraph_of(g_) && g_.has(e) && e.is_valid();
291  }
292 
293 // template <typename G, typename F>
294 // inline
295 // bool
296 // p_edges<G,F>::has(unsigned edge_id) const
297 // {
298 // mln_precondition(is_valid());
299 // util::edge<G> e(g_, edge_id);
300 // return has(e);
301 // }
302 
303  template <typename G, typename F>
304  inline
305  std::size_t
307  {
308  // FIXME: Dummy; implement (see other site sets).
309  abort();
310  return 0;
311  }
312 
313  template <typename G, typename F>
314  inline
315  const G&
317  {
318  mln_precondition(is_valid());
319  return g_;
320  }
321 
322  template <typename G, typename F>
323  inline
324  const F&
326  {
327  return f_;
328  }
329 
330  template <typename G, typename F>
331  bool
332  operator==(const p_edges<G, F>& lhs, const p_edges<G, F>& rhs)
333  {
334  return lhs.graph() == rhs.graph();
335  }
336 
337  template <typename G, typename F>
338  bool
339  operator<=(const p_edges<G, F>& lhs, const p_edges<G, F>& rhs)
340  {
341  return lhs == rhs;
342  }
343 
344 } // end of mln
345 
346 # endif // ! MLN_INCLUDE_ONLY
347 
348 #endif // ! MLN_CORE_SITE_SET_P_EDGES_HH