Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
complex_window_piter.hh
1 // Copyright (C) 2008, 2009, 2010, 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_IMAGE_COMPLEX_WINDOW_PITER_HH
28 # define MLN_CORE_IMAGE_COMPLEX_WINDOW_PITER_HH
29 
32 
33 # include <mln/core/concept/window.hh>
34 # include <mln/core/internal/site_relative_iterator_base.hh>
35 
36 // FIXME: These might be factor-able, both between fwd/bkd and nbh/win.
37 
38 /* FIXME: Do we really want to inherit from
39  internal::site_relative_iterator_base? It might duplicate things,
40  since most of the implementation of this iterator is delegated to
41  the underlying complex iter. Think about introducing base class
42  replacement. */
43 
44 
45 namespace mln
46 {
47 
48  /*------------------------------------.
49  | complex_window_fwd_piter<I, G, W>. |
50  `------------------------------------*/
51 
53  template <typename I, typename G, typename W>
55  : public internal::site_relative_iterator_base< W,
56  complex_window_fwd_piter<I, G, W> >
57  {
59  typedef internal::site_relative_iterator_base< W, self_ > super_;
60 
61  public:
63  typedef mln_psite(W) psite;
65  typedef typename W::complex_fwd_iter iter_type;
66 
67  public:
71  template <typename Pref>
72  complex_window_fwd_piter(const Window<W>& win, const Pref& p_ref);
74 
76  template <typename Pref>
77  void init_(const Window<W>& win, const Pref& p_ref);
78 
82  bool is_valid_() const;
84  void invalidate_();
85 
87  void do_start_();
89  void do_next_();
90 
92  template <typename Pref>
93  void center_at_(const Pref& c);
94 
96  psite compute_p_() const;
98 
101  const iter_type& iter() const;
102  iter_type& iter();
104 
105  private:
107  iter_type iter_;
108  };
109 
110 
112  template <typename I, typename G, typename W>
113  std::ostream&
114  operator<<(std::ostream& ostr,
115  const complex_window_fwd_piter<I, G, W>& p);
116 
117 
118  /*------------------------------------.
119  | complex_window_bkd_piter<I, G, W>. |
120  `------------------------------------*/
121 
123  template <typename I, typename G, typename W>
125  : public internal::site_relative_iterator_base< W,
126  complex_window_bkd_piter<I, G, W> >
127  {
129  typedef internal::site_relative_iterator_base< W, self_ > super_;
130 
131  public:
133  typedef mln_psite(W) psite;
135  typedef typename W::complex_bkd_iter iter_type;
136 
137  public:
141  template <typename Pref>
142  complex_window_bkd_piter(const Window<W>& win, const Pref& p_ref);
144 
146  template <typename Pref>
147  void init_(const Window<W>& win, const Pref& p_ref);
148 
152  bool is_valid_() const;
154  void invalidate_();
155 
157  void do_start_();
159  void do_next_();
160 
162  template <typename Pref>
163  void center_at_(const Pref& c);
164 
166  psite compute_p_() const;
168 
171  const iter_type& iter() const;
172  iter_type& iter();
174 
175  private:
177  iter_type iter_;
178  };
179 
180 
182  template <typename I, typename G, typename W>
183  std::ostream&
184  operator<<(std::ostream& ostr,
185  const complex_window_bkd_piter<I, G, W>& p);
186 
187 
188 
189 # ifndef MLN_INCLUDE_ONLY
190 
191  /*------------------------------------.
192  | complex_window_fwd_piter<I, G, W>. |
193  `------------------------------------*/
194 
195  template <typename I, typename G, typename W>
196  inline
198  {
199  }
200 
201  template <typename I, typename G, typename W>
202  template <typename Pref>
203  inline
205  const Pref& p_ref)
206  {
207  init_(win, p_ref);
208  }
209 
210  template <typename I, typename G, typename W>
211  template <typename Pref>
212  inline
213  void
214  complex_window_fwd_piter<I, G, W>::init_(const Window<W>& win,
215  const Pref& p_ref)
216  {
217  this->change_target(exact(win));
218  this->center_at(p_ref);
219  mln_postcondition(!this->is_valid());
220  }
221 
222 
223  template <typename I, typename G, typename W>
224  inline
225  bool
226  complex_window_fwd_piter<I, G, W>::is_valid_() const
227  {
228  return iter_.is_valid();
229  }
230 
231  template <typename I, typename G, typename W>
232  inline
233  void
234  complex_window_fwd_piter<I, G, W>::invalidate_()
235  {
236  iter_.invalidate();
237  }
238 
239  template <typename I, typename G, typename W>
240  inline
241  void
242  complex_window_fwd_piter<I, G, W>::do_start_()
243  {
244  iter_.start();
245  }
246 
247  template <typename I, typename G, typename W>
248  inline
249  void
250  complex_window_fwd_piter<I, G, W>::do_next_()
251  {
252  iter_.next();
253  }
254 
255  template <typename I, typename G, typename W>
256  template <typename Pref>
257  inline
258  void
259  complex_window_fwd_piter<I, G, W>::center_at_(const Pref&)
260  {
261  iter_.center_at(this->center().face());
262  }
263 
264  template <typename I, typename G, typename W>
265  inline
266  mln_psite(W)
267  complex_window_fwd_piter<I, G, W>::compute_p_() const
268  {
269  return psite(this->center().site_set(), iter_);
270  }
271 
272  template <typename I, typename G, typename W>
273  inline
274  const typename W::complex_fwd_iter&
276  {
277  return iter_;
278  }
279 
280  template <typename I, typename G, typename W>
281  inline
282  typename W::complex_fwd_iter&
284  {
285  return iter_;
286  }
287 
288 
289  template <typename I, typename G, typename W>
290  inline
291  std::ostream&
292  operator<<(std::ostream& ostr,
294  {
295  return ostr << p.unproxy_();
296  }
297 
298 
299  /*------------------------------------.
300  | complex_window_bkd_piter<I, G, W>. |
301  `------------------------------------*/
302 
303  template <typename I, typename G, typename W>
304  inline
306  {
307  }
308 
309  template <typename I, typename G, typename W>
310  template <typename Pref>
311  inline
313  const Pref& p_ref)
314  {
315  init_(win, p_ref);
316  }
317 
318  template <typename I, typename G, typename W>
319  template <typename Pref>
320  inline
321  void
322  complex_window_bkd_piter<I, G, W>::init_(const Window<W>& win,
323  const Pref& p_ref)
324  {
325  this->change_target(exact(win));
326  this->center_at(p_ref);
327  mln_postcondition(!this->is_valid());
328  }
329 
330 
331  template <typename I, typename G, typename W>
332  inline
333  bool
334  complex_window_bkd_piter<I, G, W>::is_valid_() const
335  {
336  return iter_.is_valid();
337  }
338 
339  template <typename I, typename G, typename W>
340  inline
341  void
342  complex_window_bkd_piter<I, G, W>::invalidate_()
343  {
344  iter_.invalidate();
345  }
346 
347  template <typename I, typename G, typename W>
348  inline
349  void
350  complex_window_bkd_piter<I, G, W>::do_start_()
351  {
352  iter_.start();
353  }
354 
355  template <typename I, typename G, typename W>
356  inline
357  void
358  complex_window_bkd_piter<I, G, W>::do_next_()
359  {
360  iter_.next();
361  }
362 
363  template <typename I, typename G, typename W>
364  template <typename Pref>
365  inline
366  void
367  complex_window_bkd_piter<I, G, W>::center_at_(const Pref& c)
368  {
369  // FIXME: Argument C is not used here... Is this normal?
370  (void) c;
371  iter_.center_at(this->center().face());
372  }
373 
374  template <typename I, typename G, typename W>
375  inline
376  mln_psite(W)
377  complex_window_bkd_piter<I, G, W>::compute_p_() const
378  {
379  return psite(this->center().site_set(), iter_);
380  }
381 
382  template <typename I, typename G, typename W>
383  inline
384  const typename W::complex_bkd_iter&
386  {
387  return iter_;
388  }
389 
390  template <typename I, typename G, typename W>
391  inline
392  typename W::complex_bkd_iter&
394  {
395  return iter_;
396  }
397 
398 
399  template <typename I, typename G, typename W>
400  inline
401  std::ostream&
402  operator<<(std::ostream& ostr,
404  {
405  return ostr << p.unproxy_();
406  }
407 
408 # endif // ! MLN_INCLUDE_ONLY
409 
410 } // end of namespace mln
411 
412 #endif // ! MLN_CORE_IMAGE_COMPLEX_WINDOW_PITER_HH