$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
core/concept/site_set.hh
1 // Copyright (C) 2007, 2008, 2009, 2011, 2012, 2013 EPITA Research and
2 // Development 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_CONCEPT_SITE_SET_HH
28 # define MLN_CORE_CONCEPT_SITE_SET_HH
29 
35 
36 # include <set>
37 
38 # include <mln/core/concept/site_iterator.hh>
39 # include <mln/trait/site_sets.hh>
40 # include <mln/metal/not_equal.hh>
41 # include <mln/metal/is_a.hh>
42 # include <mln/metal/is_unqualif.hh>
43 # include <mln/util/ord.hh>
44 
45 
46 namespace mln
47 {
48 
49  // Forward declaration.
50  template <typename E> struct Site_Set;
51 
52 
55  template <>
56  struct Site_Set<void>
57  {
59  };
61 
62 
71  template <typename E>
72  struct Site_Set : public Object<E>
73  {
75 
76  /*
77  typedef element;
78 
79  typedef site;
80  typedef psite;
81 
82  typedef fwd_piter;
83  typedef bkd_piter;
84 
85  bool has(const psite& p) const;
86  bool is_valid() const;
87 
88  std::size_t memory_size() const;
89  */
90 
91  protected:
92  Site_Set();
93  };
94 
95 
100  template <typename S, typename P, typename C_>
101  void
102  from_to_(const Site_Set<S>& from, std::set<P,C_>& to);
103 
104 } // end of namespace mln
105 
106 namespace std
107 {
108 
113  template <typename P, typename C_, typename S>
114  void
115  from_to_(const set<P,C_>& from, mln::Site_Set<S>& to);
116 
117 } // end of namespace std
118 
119 
120 namespace mln
121 {
122 
123  namespace trait
124  {
125 
126  template <typename S>
127  struct set_unary_< op::ord, Site_Set, S >
128  {
129  // No definition here.
130 
131  // That prevents from calling the inclusion operator ("op<")
132  // which is clearly not the expected ordering...
133 
134  // Consequently site sets have to define the way they are
135  // ordered.
136  };
137 
138  } // end of namespace mln::trait
139 
140 } // end of namespace mln
141 
142 # ifndef MLN_INCLUDE_ONLY
143 
144 namespace mln
145 {
146 
147  namespace internal
148  {
149 
150  // nsites: known or unknown.
151 
152  template <typename trait_nsites, typename E>
153  struct site_set_nsites_check
154  {
155  static void run() { /* No requirement. */ }
156  };
157 
158  template <typename E>
159  struct site_set_nsites_check< mln::trait::site_set::nsites::known, E >
160  {
161  static void run()
162  {
163  unsigned (E::*m)() const = & E::nsites;
164  (void) m;
165  }
166  };
167 
168  // bbox: unknown, lazy, or straight.
169 
170  template <typename trait_bbox, typename E>
171  struct site_set_bbox_check
172  {
173  static void run()
174  {
175  typedef typename E::q_box q_box;
176  q_box (E::*m)() const = & E::bbox;
177  (void) m;
178  }
179  };
180 
181  template <typename E>
182  struct site_set_bbox_check< mln::trait::site_set::bbox::unknown, E >
183  {
184  static void run() { /* No requirement. */ }
185  };
186 
187  // contents: fixed, growing, or free.
188 
189  template <typename trait_contents, typename E>
190  struct site_set_contents_check;
191 
192  template <typename E>
193  struct site_set_contents_check< mln::trait::site_set::contents::fixed, E >
194  {
195  static void run() { /* No requirement. */ }
196  };
197 
198  template <typename E>
199  struct site_set_contents_check< mln::trait::site_set::contents::growing, E >
200  {
201  static void run()
202  {
203  typedef typename E::i_element i_element;
204  mlc_equal(mlc_unqualif(i_element), i_element)::check();
205  void (E::*m1)(const i_element&) = & E::insert;
206  (void) m1;
207  void (E::*m2)() = & E::clear;
208  (void) m2;
209  }
210  };
211 
212  template <typename E>
213  struct site_set_contents_check< mln::trait::site_set::contents::free, E >
214  {
215  static void run()
216  {
217  typedef typename E::i_element i_element;
218  mlc_equal(mlc_unqualif(i_element), i_element)::check();
219  void (E::*m1)(const i_element&) = & E::insert;
220  (void) m1;
221  typedef typename E::r_element r_element;
222  mlc_equal(mlc_unqualif(r_element), r_element)::check();
223  void (E::*m2)(const r_element&) = & E::remove;
224  (void) m2;
225  void (E::*m3)() = & E::clear;
226  (void) m3;
227  }
228  };
229 
230  } // end of namespace mln::internal
231 
232 
233  // fwd decl
234  template <typename P> struct box_;
235 
236  template <typename E>
237  inline
239  {
240  // Check properties.
241  mlc_not_equal( mln_trait_site_set_nsites(E), mln::trait::undef )::check();
242  mlc_not_equal( mln_trait_site_set_bbox(E), mln::trait::undef )::check();
243  mlc_not_equal( mln_trait_site_set_contents(E), mln::trait::undef )::check();
244  mlc_not_equal( mln_trait_site_set_arity(E), mln::trait::undef )::check();
245  // FIXME: also test something like
246  // mlc_is_a( mln_trait_site_set_nsites(E), mln::trait::site_set::nsites::any )::check();
247 
248  // Check associated types.
249  typedef mln_element(E) element;
250  mlc_is_unqualif(element)::check();
251  typedef mln_site(E) site;
252  typedef mln_psite(E) psite;
253  typedef mln_piter(E) piter;
254  typedef mln_fwd_piter(E) fwd_piter;
255  typedef mln_bkd_piter(E) bkd_piter;
256 
257  // Check methods.
258  bool (E::*m1)(const psite& p) const = & E::has;
259  (void) m1;
260  bool (E::*m2)() const = & E::is_valid;
261  (void) m2;
262  std::size_t (E::*m3)() const = & E::memory_size;
263  (void) m3;
264 
265  // Check methods depending upon properties.
266  internal::site_set_nsites_check < mln_trait_site_set_nsites(E), E >::run();
267  internal::site_set_bbox_check < mln_trait_site_set_bbox(E), E >::run();
268  internal::site_set_contents_check< mln_trait_site_set_contents(E), E >::run();
269  }
270 
271 
272  // Conversion
273 
274  template <typename S, typename P, typename C_>
275  inline
276  void
277  from_to_(const Site_Set<S>& from_, std::set<P,C_>& to)
278  {
279  mlc_converts_to(mln_psite(S), P)::check();
280  const S& from = exact(from_);
281  to.clear();
282  mln_piter(S) p(from);
283  for_all(p)
284  to.insert(p);
285  }
286 
287 } // end of namespace mln
288 
289 namespace std
290 {
291 
292  template <typename P, typename C_, typename S>
293  inline
294  void
295  from_to_(const set<P,C_>& from, mln::Site_Set<S>& to_)
296  {
297  mlc_converts_to(P, mln_i_element(S))::check();
298  S& to = exact(to_);
299  to.clear();
300  for (typename set<P>::const_iterator i = from.begin();
301  i != from.end();
302  ++i)
303  to.insert(*i);
304  }
305 
306 } // end of namespace std
307 
308 
309 # endif // ! MLN_INCLUDE_ONLY
310 
311 
312 # include <mln/core/site_set/operators.hh>
313 # include <mln/core/routine/ops.hh>
314 
315 
316 #endif // ! MLN_CORE_CONCEPT_SITE_SET_HH