Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
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_FACE_ITER_HH
27 # define MLN_TOPO_FACE_ITER_HH
28 
33 
34 # include <mln/topo/internal/complex_set_iterator_base.hh>
35 # include <mln/topo/face.hh>
36 # include <mln/topo/face_iter.hh>
37 
38 // FIXME: Factor a bit more? (Using complex_set_iterator_base.)
39 
40 
41 namespace mln
42 {
43 
44  namespace topo
45  {
46 
47  // Forward declarations.
48  template <unsigned D> class complex;
49 
50  namespace internal
51  {
52 
53  template <typename F, typename E>
54  class complex_set_iterator_base;
55 
56  } // end of namespace mln::topo::internal
57 
58 
59  /*-------------------------.
60  | topo::face_fwd_iter<D>. |
61  `-------------------------*/
62 
67  //
68  template <unsigned D>
70  : public internal::complex_set_iterator_base< topo::face<D>, face_fwd_iter<D> >
71  {
72  // Tech note: we use topo::face to help g++-2.95.
73  private:
74  typedef face_fwd_iter<D> self_;
75  typedef internal::complex_set_iterator_base< topo::face<D>, self_ > super_;
76 
77  public:
78  using super_::is_valid;
79  using super_::invalidate;
80 
81  public:
84  face_fwd_iter();
85  // FIXME: See comment in internal::complex_set_iterator_base's
86  // default ctor.
89 
93  void start();
95  void next_();
97 
98  private:
99  using super_::f_;
100  };
101 
102 
103  /*-------------------------.
104  | topo::face_bkd_iter<D>. |
105  `-------------------------*/
106 
110  //
111  template <unsigned D>
113  : public internal::complex_set_iterator_base< topo::face<D>, face_bkd_iter<D> >
114  {
115  // Tech note: we use topo::face to help g++-2.95.
116  private:
117  typedef face_bkd_iter<D> self_;
118  typedef internal::complex_set_iterator_base< topo::face<D>, self_ > super_;
119 
120  public:
121  using super_::is_valid;
122  using super_::invalidate;
123 
124  public:
127  face_bkd_iter();
128  // FIXME: See comment in internal::complex_set_iterator_base's
129  // default ctor.
132 
136  void start();
138  void next_();
140 
141  private:
142  using super_::f_;
143  };
144 
145 
146 
147 # ifndef MLN_INCLUDE_ONLY
148 
149  /*-------------------------.
150  | topo::face_fwd_iter<D>. |
151  `-------------------------*/
152 
153  template <unsigned D>
154  inline
156  : super_()
157  {
158  }
159 
160  template <unsigned D>
161  inline
163  : super_(c)
164  {
165  set_cplx(c);
166  mln_postcondition(!is_valid());
167  }
168 
169  template <unsigned D>
170  inline
171  void
173  {
174  f_.set_n(0u);
175  f_.set_face_id(0u);
176  }
177 
178  template <unsigned D>
179  inline
180  void
182  {
183  if (is_valid())
184  {
185  if (f_.face_id() + 1 < f_.cplx().nfaces_of_dim(f_.n()))
186  f_.inc_face_id();
187  else
188  // Start to iterate on the faces of the next dimension if
189  // possible.
190  if (f_.n() <= D)
191  {
192  f_.inc_n();
193  f_.set_face_id(0u);
194  }
195  else
196  invalidate();
197  }
198  }
199 
200 
201  /*-------------------------.
202  | topo::face_bkd_iter<D>. |
203  `-------------------------*/
204 
205  template <unsigned D>
206  inline
208  : super_()
209  {
210  }
211 
212  template <unsigned D>
213  inline
215  : super_(c)
216  {
217  set_cplx(c);
218  mln_postcondition(!is_valid());
219  }
220 
221  template <unsigned D>
222  inline
223  void
225  {
226  f_.set_n(D);
227  f_.set_face_id(f_.cplx().template nfaces_of_static_dim<D>() - 1);
228  }
229 
230  template <unsigned D>
231  inline
232  void
234  {
235  if (is_valid())
236  {
237  if (f_.face_id() > 0)
238  f_.dec_face_id();
239  else
240  // Start to iterate on the faces of the previous dimension
241  // if it exists.
242  if (f_.n() > 0)
243  {
244  f_.dec_n();
245  f_.set_face_id(f_.cplx().nfaces_of_dim(f_.n()) - 1);
246  }
247  else
248  invalidate();
249  }
250  }
251 
252 # endif // ! MLN_INCLUDE_ONLY
253 
254  } // end of namespace mln::topo
255 
256 } // end of namespace mln
257 
258 #endif // ! MLN_TOPO_FACE_ITER_HH