$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends 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_;
77 
78  public:
79 
81  typedef G graph_t;
82 
84  typedef F fun_t;
85 
88 
91 
94 
96  p_edges();
97 
101  p_edges(const Graph<G>& gr);
102 
107  p_edges(const Graph<G>& gr, const Function<F>& f);
108 
114  template <typename F2>
115  p_edges(const Graph<G>& gr, const Function<F2>& f);
116 
118 
121 
123  typedef mln_site(super_) element;
124 
126  typedef p_edges_psite<G, F> psite;
127 
129  typedef p_graph_piter< self_, mln_edge_fwd_iter(G) > fwd_piter;
130 
132  typedef p_graph_piter< self_, mln_edge_bkd_iter(G) > bkd_piter;
133 
135  typedef fwd_piter piter;
136 
138 
141  unsigned nsites() const;
142 
144  unsigned nedges() const;
145 
147  bool is_valid() const;
149  void invalidate();
150 
152  bool has(const psite& p) const;
153 
155  template <typename G2>
156  bool has(const util::edge<G2>& e) const;
157 
161 
162  // FIXME: Dummy.
163  std::size_t memory_size() const;
164 
167 
169  const G& graph() const;
171  const F& function() const;
172 
174 
175  private:
176 
177  G g_;
178  F f_;
179  };
180 
181 
186  template <typename G, typename F>
187  bool
188  operator==(const p_edges<G, F>& lhs, const p_edges<G, F>& rhs);
189 
190 
195  template <typename G, typename F>
196  bool
197  operator<=(const p_edges<G, F>& lhs, const p_edges<G, F>& rhs);
198 
199 } // end of mln
200 
201 
202 # ifndef MLN_INCLUDE_ONLY
203 
204 namespace mln
205 {
206 
207 
208  template <typename G, typename F>
209  inline
211  {
212  }
213 
214  template <typename G, typename F>
215  inline
217  {
219  mlc_equal(F, F_REF)::check();
220 
221  mln_precondition(exact(g).is_valid());
222  g_ = exact(g);
224  }
225 
226  template <typename G, typename F>
227  inline
228  p_edges<G, F>::p_edges(const Graph<G>& g, const Function<F>& f)
229  {
230  mln_precondition(exact(g).is_valid());
231  g_ = exact(g);
232  f_ = exact(f);
233  }
234 
235  template <typename G, typename F>
236  template <typename F2>
237  inline
238  p_edges<G, F>::p_edges(const Graph<G>& g, const Function<F2>& f)
239  {
240  mln_precondition(exact(g).is_valid());
241  mlc_converts_to(F2,F)::check();
242 
243  g_ = exact(g);
244  convert::from_to(f, f_);
245  }
246 
247 
248  template <typename G, typename F>
249  inline
250  unsigned
251  p_edges<G, F>::nsites() const
252  {
253  return nedges();
254  }
255 
256  template <typename G, typename F>
257  inline
258  unsigned
259  p_edges<G, F>::nedges() const
260  {
261  return this->g_.e_nmax();
262  }
263 
264  template <typename G, typename F>
265  inline
266  bool
268  {
269  return g_.is_valid();
270  }
271 
272  template <typename G, typename F>
273  inline
274  void
276  {
277  g_.invalidate();
278  }
279 
280  template <typename G, typename F>
281  inline
282  bool
283  p_edges<G, F>::has(const psite& p) const
284  {
285  mln_precondition(is_valid());
286  return has(p.e());
287  }
288 
289  template <typename G, typename F>
290  template <typename G2>
291  inline
292  bool
293  p_edges<G, F>::has(const util::edge<G2>& e) const
294  {
295  mln_precondition(is_valid());
296  return e.graph().is_subgraph_of(g_) && g_.has(e) && e.is_valid();
297  }
298 
299 // template <typename G, typename F>
300 // inline
301 // bool
302 // p_edges<G,F>::has(unsigned edge_id) const
303 // {
304 // mln_precondition(is_valid());
305 // util::edge<G> e(g_, edge_id);
306 // return has(e);
307 // }
308 
309  template <typename G, typename F>
310  inline
311  std::size_t
313  {
314  // FIXME: Dummy; implement (see other site sets).
315  abort();
316  return 0;
317  }
318 
319  template <typename G, typename F>
320  inline
321  const G&
322  p_edges<G, F>::graph() const
323  {
324  mln_precondition(is_valid());
325  return g_;
326  }
327 
328  template <typename G, typename F>
329  inline
330  const F&
332  {
333  return f_;
334  }
335 
336  template <typename G, typename F>
337  bool
338  operator==(const p_edges<G, F>& lhs, const p_edges<G, F>& rhs)
339  {
340  return lhs.graph() == rhs.graph();
341  }
342 
343  template <typename G, typename F>
344  bool
345  operator<=(const p_edges<G, F>& lhs, const p_edges<G, F>& rhs)
346  {
347  return lhs == rhs;
348  }
349 
350 } // end of mln
351 
352 # endif // ! MLN_INCLUDE_ONLY
353 
354 #endif // ! MLN_CORE_SITE_SET_P_EDGES_HH