00001 // Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE) 00002 // 00003 // This file is part of Olena. 00004 // 00005 // Olena is free software: you can redistribute it and/or modify it under 00006 // the terms of the GNU General Public License as published by the Free 00007 // Software Foundation, version 2 of the License. 00008 // 00009 // Olena is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00016 // 00017 // As a special exception, you may use this file as part of a free 00018 // software project without restriction. Specifically, if other files 00019 // instantiate templates or use macros or inline functions from this 00020 // file, or you compile this file and link it with other files to produce 00021 // an executable, this file does not by itself cause the resulting 00022 // executable to be covered by the GNU General Public License. This 00023 // exception does not however invalidate any other reasons why the 00024 // executable file might be covered by the GNU General Public License. 00025 00026 #ifndef MLN_TOPO_N_FACE_ITER_HH 00027 # define MLN_TOPO_N_FACE_ITER_HH 00028 00033 00034 # include <mln/topo/internal/complex_set_iterator_base.hh> 00035 # include <mln/topo/face.hh> 00036 00037 // \todo Factor a bit more? (Using complex_set_iterator_base.) 00038 00039 // FIXME: Rename the old commplex_faces_{fwd,bkd}_iter as 00040 // static_n_face_{fwd,bkd}_iter. 00041 00042 00043 namespace mln 00044 { 00045 00046 namespace topo 00047 { 00048 00049 // Forward declarations. 00050 template <unsigned D> class complex; 00051 00052 namespace internal 00053 { 00054 00055 // Forward declaration. 00056 template <typename F, typename E> 00057 class complex_set_iterator_base; 00058 00059 } // end of namespace mln::topo::internal 00060 00061 00062 /*---------------------------. 00063 | topo::n_face_fwd_iter<D>. | 00064 `---------------------------*/ 00065 00070 // 00071 template <unsigned D> 00072 class n_face_fwd_iter 00073 : public internal::complex_set_iterator_base< topo::face<D>, 00074 n_face_fwd_iter<D> > 00075 { 00076 // Tech note: we use topo::face to help g++-2.95. 00077 private: 00078 typedef n_face_fwd_iter<D> self_; 00079 typedef internal::complex_set_iterator_base< topo::face<D>, self_ > super_; 00080 00081 public: 00082 using super_::is_valid; 00083 using super_::invalidate; 00084 00085 public: 00088 n_face_fwd_iter(); 00089 // FIXME: See comment in internal::complex_set_iterator_base's 00090 // default ctor. 00091 n_face_fwd_iter(complex<D>& c, unsigned n); 00093 00097 void start(); 00099 void next_(); 00101 00106 unsigned n() const; 00107 void set_n (unsigned n); 00109 00110 private: 00112 void invalidate_face_id_(); 00113 00114 private: 00115 using super_::f_; 00116 }; 00117 00118 00119 /*---------------------------. 00120 | topo::n_face_bkd_iter<D>. | 00121 `---------------------------*/ 00122 00126 template <unsigned D> 00127 class n_face_bkd_iter 00128 : public internal::complex_set_iterator_base< topo::face<D>, 00129 n_face_bkd_iter<D> > 00130 { 00131 // Tech note: we use topo::face to help g++-2.95. 00132 private: 00133 typedef n_face_bkd_iter<D> self_; 00134 typedef internal::complex_set_iterator_base< topo::face<D>, self_ > super_; 00135 00136 public: 00137 using super_::is_valid; 00138 using super_::invalidate; 00139 00140 public: 00143 n_face_bkd_iter(); 00144 // FIXME: See comment in internal::complex_set_iterator_base's 00145 // default ctor. 00146 n_face_bkd_iter(complex<D>& c, unsigned n); 00148 00152 void start(); 00154 void next_(); 00156 00161 unsigned n() const; 00162 void set_n (unsigned n); 00164 00165 private: 00167 void invalidate_face_id_(); 00168 00169 private: 00170 using super_::f_; 00171 }; 00172 00173 00174 00175 # ifndef MLN_INCLUDE_ONLY 00176 00177 /*---------------------------. 00178 | topo::n_face_fwd_iter<D>. | 00179 `---------------------------*/ 00180 00181 template <unsigned D> 00182 inline 00183 n_face_fwd_iter<D>::n_face_fwd_iter() 00184 : super_() 00185 { 00186 } 00187 00188 template <unsigned D> 00189 inline 00190 n_face_fwd_iter<D>::n_face_fwd_iter(complex<D>& c, unsigned n) 00191 : super_(c) 00192 { 00193 mln_precondition(n <= D); 00194 set_cplx(c); 00195 set_n(n); 00196 mln_postcondition(!is_valid()); 00197 } 00198 00199 template <unsigned D> 00200 inline 00201 void 00202 n_face_fwd_iter<D>::start() 00203 { 00204 f_.set_face_id(0u); 00205 } 00206 00207 template <unsigned D> 00208 inline 00209 void 00210 n_face_fwd_iter<D>::next_() 00211 { 00212 if (is_valid()) 00213 { 00214 if (f_.face_id() + 1 < f_.cplx().nfaces_of_dim(n())) 00215 f_.inc_face_id(); 00216 else 00217 /* Don't invalidate the whole face if we have reached the 00218 last face of the dimension---this would lose the 00219 dimension. Instead, invalidate the face_id only. */ 00220 invalidate_face_id_(); 00221 } 00222 } 00223 00224 template <unsigned D> 00225 inline 00226 void 00227 n_face_fwd_iter<D>::invalidate_face_id_() 00228 { 00229 f_.set_face_id(f_.cplx().nfaces_of_dim(n())); 00230 } 00231 00232 template <unsigned D> 00233 inline 00234 unsigned 00235 n_face_fwd_iter<D>::n() const 00236 { 00237 return f_.n(); 00238 } 00239 00240 template <unsigned D> 00241 inline 00242 void 00243 n_face_fwd_iter<D>::set_n(unsigned n) 00244 { 00245 mln_precondition(n <= D); 00246 f_.set_n(n); 00247 } 00248 00249 00250 /*---------------------------. 00251 | topo::n_face_bkd_iter<D>. | 00252 `---------------------------*/ 00253 00254 template <unsigned D> 00255 inline 00256 n_face_bkd_iter<D>::n_face_bkd_iter() 00257 : super_() 00258 { 00259 } 00260 00261 template <unsigned D> 00262 inline 00263 n_face_bkd_iter<D>::n_face_bkd_iter(complex<D>& c, unsigned n) 00264 : super_(c) 00265 { 00266 mln_precondition(n <= D); 00267 set_cplx(c); 00268 set_n(n); 00269 mln_postcondition(!is_valid()); 00270 } 00271 00272 template <unsigned D> 00273 inline 00274 void 00275 n_face_bkd_iter<D>::start() 00276 { 00277 f_.set_face_id(f_.cplx().nfaces_of_dim(n()) - 1); 00278 } 00279 00280 template <unsigned D> 00281 inline 00282 void 00283 n_face_bkd_iter<D>::next_() 00284 { 00285 if (is_valid()) 00286 { 00287 if (f_.face_id() > 0) 00288 f_.dec_face_id(); 00289 else 00290 /* Don't invalidate the whole face if we have reached the 00291 last face of the dimension---this would lose the 00292 dimension. Instead, invalidate the face_id only. */ 00293 invalidate_face_id_(); 00294 } 00295 } 00296 00297 template <unsigned D> 00298 inline 00299 void 00300 n_face_bkd_iter<D>::invalidate_face_id_() 00301 { 00302 f_.set_face_id(f_.cplx().nfaces_of_dim(n())); 00303 } 00304 00305 template <unsigned D> 00306 inline 00307 unsigned 00308 n_face_bkd_iter<D>::n() const 00309 { 00310 return f_.n(); 00311 } 00312 00313 template <unsigned D> 00314 inline 00315 void 00316 n_face_bkd_iter<D>::set_n(unsigned n) 00317 { 00318 mln_precondition(n <= D); 00319 f_.set_n(n); 00320 } 00321 00322 # endif // ! MLN_INCLUDE_ONLY 00323 00324 } // end of namespace mln::topo 00325 00326 } // end of namespace mln 00327 00328 #endif // ! MLN_TOPO_N_FACE_ITER_HH