Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
faces_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_ATTIC_FACES_ITER_HH
27 # define MLN_TOPO_ATTIC_FACES_ITER_HH
28 
32 
33 # include <mln/topo/internal/complex_set_iterator_base.hh>
34 # include <mln/topo/n_face.hh>
35 
36 namespace mln
37 {
38 
39  namespace topo
40  {
41 
42  /*------------------------------.
43  | topo::faces_fwd_iter_<N, D>. |
44  `------------------------------*/
45 
50  template <unsigned N, unsigned D>
51  class faces_fwd_iter_
52  : public internal::complex_set_iterator_base< n_face<N, D>,
53  faces_fwd_iter_<N, D> >
54  {
55  public:
57  typedef n_face<N, D> face;
58 
59  private:
60  typedef faces_fwd_iter_<N, D> self_;
61  typedef internal::complex_set_iterator_base< face, self_ > super_;
62 
63  public:
64  using super_::is_valid;
65  using super_::invalidate;
66 
67  public:
70  faces_fwd_iter_();
71  // FIXME: See comment in internal::complex_set_iterator_base's
72  // default ctor.
73  faces_fwd_iter_(complex<D>& c);
75 
79  void start();
81  void next_();
83 
84  private:
85  using super_::face_;
86  };
87 
88 
89  /*------------------------------.
90  | topo::faces_bkd_iter_<N, D>. |
91  `------------------------------*/
92 
97  template <unsigned N, unsigned D>
98  class faces_bkd_iter_
99  : public internal::complex_set_iterator_base< n_face<N, D>,
100  faces_bkd_iter_<N, D> >
101  {
102  public:
104  typedef n_face<N, D> face;
105 
106  private:
107  typedef faces_bkd_iter_<N, D> self_;
108  typedef internal::complex_set_iterator_base< face, self_ > super_;
109 
110  public:
111  using super_::is_valid;
112  using super_::invalidate;
113 
114  public:
117  faces_bkd_iter_();
118  // FIXME: See comment in internal::complex_set_iterator_base's
119  // default ctor.
120  faces_bkd_iter_(complex<D>& c);
122 
126  void start();
128  void next_();
130 
131  private:
132  using super_::face_;
133  };
134 
135 
136 
137 # ifndef MLN_INCLUDE_ONLY
138 
139  /*------------------------------.
140  | topo::faces_fwd_iter_<N, D>. |
141  `------------------------------*/
142 
143  template <unsigned N, unsigned D>
144  inline
145  faces_fwd_iter_<N, D>::faces_fwd_iter_()
146  : super_()
147  {
148  // Ensure N is compatible with D.
149  metal::bool_< N <= D >::check();
150  mln_postcondition(!is_valid());
151  }
152 
153  template <unsigned N, unsigned D>
154  inline
155  faces_fwd_iter_<N, D>::faces_fwd_iter_(complex<D>& c)
156  : super_(c)
157  {
158  // Ensure N is compatible with D.
159  metal::bool_< N <= D >::check();
160  mln_postcondition(!is_valid());
161  }
162 
163  template <unsigned N, unsigned D>
164  inline
165  void
166  faces_fwd_iter_<N, D>::start()
167  {
168  face_.set_face_id(0u);
169  }
170 
171  template <unsigned N, unsigned D>
172  inline
173  void
174  faces_fwd_iter_<N, D>::next_()
175  {
176  if (is_valid())
177  {
178  unsigned face_id = face_.face_id();
179  if (face_id + 1 < face_.cplx().template nfaces_of_static_dim<N>())
180  /* FIXME: Provide accessor n_face::n() returning
181  a mutable reference? This way, we could just write
182 
183  ++face_.face_id();
184 
185  instead of the following. */
186  face_.set_face_id(face_id + 1);
187  else
188  invalidate();
189  }
190  }
191 
192 
193  /*------------------------------.
194  | topo::faces_bkd_iter_<N, D>. |
195  `------------------------------*/
196 
197  template <unsigned N, unsigned D>
198  inline
199  faces_bkd_iter_<N, D>::faces_bkd_iter_()
200  : super_()
201  {
202  // Ensure N is compatible with D.
203  metal::bool_< N <= D >::check();
204  mln_postcondition(!is_valid());
205  }
206 
207  template <unsigned N, unsigned D>
208  inline
209  faces_bkd_iter_<N, D>::faces_bkd_iter_(complex<D>& c)
210  : super_(c)
211  {
212  // Ensure N is compatible with D.
213  metal::bool_< N <= D >::check();
214  mln_postcondition(!is_valid());
215  }
216 
217  template <unsigned N, unsigned D>
218  inline
219  void
220  faces_bkd_iter_<N, D>::start()
221  {
222  face_.set_face_id(face_.cplx().template nfaces_of_static_dim<N>() - 1);
223  }
224 
225  template <unsigned N, unsigned D>
226  inline
227  void
228  faces_bkd_iter_<N, D>::next_()
229  {
230  if (is_valid())
231  {
232  unsigned face_id = face_.face_id();
233  if (face_id > 0)
234  /* FIXME: Provide accessor n_face::n() returning
235  a mutable reference? This way, we could just write
236 
237  ++face_.face_id();
238 
239  instead of the following. */
240  face_.set_face_id(face_id - 1);
241  else
242  invalidate();
243  }
244  }
245 
246 # endif // ! MLN_INCLUDE_ONLY
247 
248  } // end of namespace mln::topo
249 
250 } // end of namespace mln
251 
252 #endif // ! MLN_TOPO_ATTIC_FACES_ITER_HH