Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
n_face_iter.hh
1 // Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef MLN_TOPO_N_FACE_ITER_HH
27 # define MLN_TOPO_N_FACE_ITER_HH
28 
33 
34 # include <mln/topo/internal/complex_set_iterator_base.hh>
35 # include <mln/topo/face.hh>
36 
37 // \todo Factor a bit more? (Using complex_set_iterator_base.)
38 
39 // FIXME: Rename the old commplex_faces_{fwd,bkd}_iter as
40 // static_n_face_{fwd,bkd}_iter.
41 
42 
43 namespace mln
44 {
45 
46  namespace topo
47  {
48 
49  // Forward declarations.
50  template <unsigned D> class complex;
51 
52  namespace internal
53  {
54 
55  // Forward declaration.
56  template <typename F, typename E>
57  class complex_set_iterator_base;
58 
59  } // end of namespace mln::topo::internal
60 
61 
62  /*---------------------------.
63  | topo::n_face_fwd_iter<D>. |
64  `---------------------------*/
65 
70  //
71  template <unsigned D>
73  : public internal::complex_set_iterator_base< topo::face<D>,
74  n_face_fwd_iter<D> >
75  {
76  // Tech note: we use topo::face to help g++-2.95.
77  private:
78  typedef n_face_fwd_iter<D> self_;
79  typedef internal::complex_set_iterator_base< topo::face<D>, self_ > super_;
80 
81  public:
82  using super_::is_valid;
83  using super_::invalidate;
84 
85  public:
89  // FIXME: See comment in internal::complex_set_iterator_base's
90  // default ctor.
91  n_face_fwd_iter(complex<D>& c, unsigned n);
93 
97  void start();
99  void next_();
101 
106  unsigned n() const;
107  void set_n (unsigned n);
109 
110  private:
112  void invalidate_face_id_();
113 
114  private:
115  using super_::f_;
116  };
117 
118 
119  /*---------------------------.
120  | topo::n_face_bkd_iter<D>. |
121  `---------------------------*/
122 
126  template <unsigned D>
128  : public internal::complex_set_iterator_base< topo::face<D>,
129  n_face_bkd_iter<D> >
130  {
131  // Tech note: we use topo::face to help g++-2.95.
132  private:
133  typedef n_face_bkd_iter<D> self_;
134  typedef internal::complex_set_iterator_base< topo::face<D>, self_ > super_;
135 
136  public:
137  using super_::is_valid;
138  using super_::invalidate;
139 
140  public:
143  n_face_bkd_iter();
144  // FIXME: See comment in internal::complex_set_iterator_base's
145  // default ctor.
146  n_face_bkd_iter(complex<D>& c, unsigned n);
148 
152  void start();
154  void next_();
156 
161  unsigned n() const;
162  void set_n (unsigned n);
164 
165  private:
167  void invalidate_face_id_();
168 
169  private:
170  using super_::f_;
171  };
172 
173 
174 
175 # ifndef MLN_INCLUDE_ONLY
176 
177  /*---------------------------.
178  | topo::n_face_fwd_iter<D>. |
179  `---------------------------*/
180 
181  template <unsigned D>
182  inline
184  : super_()
185  {
186  }
187 
188  template <unsigned D>
189  inline
190  n_face_fwd_iter<D>::n_face_fwd_iter(complex<D>& c, unsigned n)
191  : super_(c)
192  {
193  mln_precondition(n <= D);
194  set_cplx(c);
195  set_n(n);
196  mln_postcondition(!is_valid());
197  }
198 
199  template <unsigned D>
200  inline
201  void
203  {
204  f_.set_face_id(0u);
205  }
206 
207  template <unsigned D>
208  inline
209  void
211  {
212  if (is_valid())
213  {
214  if (f_.face_id() + 1 < f_.cplx().nfaces_of_dim(n()))
215  f_.inc_face_id();
216  else
217  /* Don't invalidate the whole face if we have reached the
218  last face of the dimension---this would lose the
219  dimension. Instead, invalidate the face_id only. */
220  invalidate_face_id_();
221  }
222  }
223 
224  template <unsigned D>
225  inline
226  void
227  n_face_fwd_iter<D>::invalidate_face_id_()
228  {
229  f_.set_face_id(f_.cplx().nfaces_of_dim(n()));
230  }
231 
232  template <unsigned D>
233  inline
234  unsigned
236  {
237  return f_.n();
238  }
239 
240  template <unsigned D>
241  inline
242  void
243  n_face_fwd_iter<D>::set_n(unsigned n)
244  {
245  mln_precondition(n <= D);
246  f_.set_n(n);
247  }
248 
249 
250  /*---------------------------.
251  | topo::n_face_bkd_iter<D>. |
252  `---------------------------*/
253 
254  template <unsigned D>
255  inline
256  n_face_bkd_iter<D>::n_face_bkd_iter()
257  : super_()
258  {
259  }
260 
261  template <unsigned D>
262  inline
263  n_face_bkd_iter<D>::n_face_bkd_iter(complex<D>& c, unsigned n)
264  : super_(c)
265  {
266  mln_precondition(n <= D);
267  set_cplx(c);
268  set_n(n);
269  mln_postcondition(!is_valid());
270  }
271 
272  template <unsigned D>
273  inline
274  void
276  {
277  f_.set_face_id(f_.cplx().nfaces_of_dim(n()) - 1);
278  }
279 
280  template <unsigned D>
281  inline
282  void
284  {
285  if (is_valid())
286  {
287  if (f_.face_id() > 0)
288  f_.dec_face_id();
289  else
290  /* Don't invalidate the whole face if we have reached the
291  last face of the dimension---this would lose the
292  dimension. Instead, invalidate the face_id only. */
293  invalidate_face_id_();
294  }
295  }
296 
297  template <unsigned D>
298  inline
299  void
300  n_face_bkd_iter<D>::invalidate_face_id_()
301  {
302  f_.set_face_id(f_.cplx().nfaces_of_dim(n()));
303  }
304 
305  template <unsigned D>
306  inline
307  unsigned
309  {
310  return f_.n();
311  }
312 
313  template <unsigned D>
314  inline
315  void
316  n_face_bkd_iter<D>::set_n(unsigned n)
317  {
318  mln_precondition(n <= D);
319  f_.set_n(n);
320  }
321 
322 # endif // ! MLN_INCLUDE_ONLY
323 
324  } // end of namespace mln::topo
325 
326 } // end of namespace mln
327 
328 #endif // ! MLN_TOPO_N_FACE_ITER_HH