• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

complex_relative_iterator_base.hh

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_INTERNAL_COMPLEX_RELATIVE_ITERATOR_BASE_HH
00027 # define MLN_TOPO_INTERNAL_COMPLEX_RELATIVE_ITERATOR_BASE_HH
00028 
00049 # include <vector>
00050 
00051 # include <mln/topo/internal/complex_iterator_base.hh>
00052 
00053 /* FIXME: By moving iterator `i_' into
00054    internal::complex_relative_iterator_base, we'll be able to factor
00055    more methods (do_next_, update_f); this requires the type of this
00056    iterator be passed as an extra parameter to
00057    internal::complex_relative_iterator_base.  */
00058 
00059 
00060 namespace mln
00061 {
00062 
00063   namespace topo
00064   {
00065 
00066     namespace internal
00067     {
00068 
00069       // Forward declaration.
00070       template <typename F, typename E>
00071       class complex_iterator_base;
00072 
00073 
00074       /*----------------------------------------------------------.
00075       | topo::internal::complex_relative_iterator_base<C, F, E>.  |
00076       `----------------------------------------------------------*/
00077 
00083       template <typename C, typename F, typename E>
00084       class complex_relative_iterator_base :
00085         public complex_iterator_base<F, E>
00086       {
00087         typedef complex_relative_iterator_base<C, F, E> self_;
00088 
00089       public:
00091         typedef C center_type;
00093         typedef F face_type;
00094 
00097         complex_relative_iterator_base();
00098         template <typename Fref>
00099         complex_relative_iterator_base(const Fref& f_ref);
00101 
00105         void center_at(const center_type& c);
00106 
00108         void start();
00110         void next_();
00112 
00113       protected:
00116         const center_type* c_;
00117 
00118         // The type of the set of vicinity sites (adjacent face handles).
00119         typedef std::vector<face_type> adj_faces_t;
00121         adj_faces_t adj_faces_;
00122       };
00123 
00124 
00125 
00126       /*------------------------------------------------------------------.
00127       | topo::internal::forward_complex_relative_iterator_base<C, F, E>.  |
00128       `------------------------------------------------------------------*/
00129 
00136       template <typename C, typename F, typename E>
00137       class forward_complex_relative_iterator_base
00138         : public complex_relative_iterator_base<C, F, E>
00139       {
00140         typedef forward_complex_relative_iterator_base<C, F, E> self_;
00141         typedef complex_relative_iterator_base<C, F, E> super_;
00142 
00143       public:
00144         typedef F face_type;
00145 
00146       public:
00149         forward_complex_relative_iterator_base();
00150         template <typename Fref>
00151         forward_complex_relative_iterator_base(const Fref& f_ref);
00153 
00154       public:
00158         bool is_valid() const;
00160         void invalidate();
00161 
00163         void do_start_();
00165         void do_next_();
00166 
00168         void update_f_();
00170 
00171       protected:
00173         typename super_::adj_faces_t::const_iterator i_;
00174       };
00175 
00176 
00177       /*-------------------------------------------------------------------.
00178       | topo::internal::backward_complex_relative_iterator_base<C, F, E>.  |
00179       `-------------------------------------------------------------------*/
00180 
00187       template <typename C, typename F, typename E>
00188       class backward_complex_relative_iterator_base
00189         : public complex_relative_iterator_base<C, F, E>
00190       {
00191         typedef backward_complex_relative_iterator_base<C, F, E> self_;
00192         typedef complex_relative_iterator_base<C, F, E> super_;
00193 
00194       public:
00195         typedef F face_type;
00196 
00197       public:
00200         backward_complex_relative_iterator_base();
00201         template <typename Fref>
00202         backward_complex_relative_iterator_base(const Fref& f_ref);
00204 
00205       public:
00209         bool is_valid() const;
00211         void invalidate();
00212 
00214         void do_start_();
00216         void do_next_();
00217 
00219         void update_f_();
00221 
00222       protected:
00224         typename super_::adj_faces_t::const_reverse_iterator i_;
00225       };
00226 
00227 
00228 
00229 # ifndef MLN_INCLUDE_ONLY
00230 
00231       /*----------------------------------------------------------.
00232       | topo::internal::complex_relative_iterator_base<C, F, E>.  |
00233       `----------------------------------------------------------*/
00234 
00235       template <typename C, typename F, typename E>
00236       inline
00237       complex_relative_iterator_base<C, F, E>::complex_relative_iterator_base()
00238         : c_(0)
00239       {
00240         // Check for required methods in E.
00241         void (E::*m)() = & E::update_adj_faces_;
00242         m = 0;
00243 
00244         exact(this)->invalidate();
00245       }
00246 
00247       template <typename C, typename F, typename E>
00248       template <typename Fref>
00249       inline
00250       complex_relative_iterator_base<C, F, E>::complex_relative_iterator_base(const Fref& f_ref)
00251       {
00252         // Check for required methods in E.
00253         void (E::*m)() = & E::update_adj_faces_;
00254         m = 0;
00255 
00256         center_at(f_ref);
00257       }
00258 
00259       template <typename C, typename F, typename E>
00260       inline
00261       void
00262       complex_relative_iterator_base<C, F, E>::center_at(const C& c)
00263       {
00264         c_ = &c;
00265         exact(this)->invalidate();
00266       }
00267 
00268       template <typename C, typename F, typename E>
00269       inline
00270       void
00271       complex_relative_iterator_base<C, F, E>::start()
00272       {
00273         exact(this)->do_start_();
00274         if (exact(this)->is_valid())
00275           exact(this)->update_f_();
00276       }
00277 
00278       template <typename C, typename F, typename E>
00279       inline
00280       void
00281       complex_relative_iterator_base<C, F, E>::next_()
00282       {
00283         exact(this)->do_next_();
00284         if (exact(this)->is_valid())
00285           exact(this)->update_f_();
00286       }
00287 
00288 
00289 
00290       /*------------------------------------------------------------------.
00291       | topo::internal::forward_complex_relative_iterator_base<C, F, E>.  |
00292       `------------------------------------------------------------------*/
00293 
00294       template <typename C, typename F, typename E>
00295       inline
00296       forward_complex_relative_iterator_base<C, F, E>::forward_complex_relative_iterator_base()
00297       {
00298       }
00299 
00300       template <typename C, typename F, typename E>
00301       template <typename Fref>
00302       inline
00303       forward_complex_relative_iterator_base<C, F, E>::forward_complex_relative_iterator_base(const Fref& f_ref)
00304         : super_(f_ref)
00305       {
00306       }
00307 
00308       template <typename C, typename F, typename E>
00309       inline
00310       bool
00311       forward_complex_relative_iterator_base<C, F, E>::is_valid() const
00312       {
00313         return i_ != this->adj_faces_.end();
00314       }
00315 
00316       template <typename C, typename F, typename E>
00317       inline
00318       void
00319       forward_complex_relative_iterator_base<C, F, E>::invalidate()
00320       {
00321         i_ = this->adj_faces_.end();
00322       }
00323 
00324       template <typename C, typename F, typename E>
00325       inline
00326       void
00327       forward_complex_relative_iterator_base<C, F, E>::do_start_()
00328       {
00329         exact(this)->update_adj_faces_();
00330         i_ = this->adj_faces_.begin();
00331       }
00332 
00333       template <typename C, typename F, typename E>
00334       inline
00335       void
00336       forward_complex_relative_iterator_base<C, F, E>::do_next_()
00337       {
00338         ++i_;
00339       }
00340 
00341       template <typename C, typename F, typename E>
00342       inline
00343       void
00344       forward_complex_relative_iterator_base<C, F, E>::update_f_()
00345       {
00346         mln_precondition(is_valid());
00347         this->f_ = *i_;
00348       }
00349 
00350 
00351       /*-------------------------------------------------------------------.
00352       | topo::internal::backward_complex_relative_iterator_base<C, F, E>.  |
00353       `-------------------------------------------------------------------*/
00354 
00355       template <typename C, typename F, typename E>
00356       inline
00357       backward_complex_relative_iterator_base<C, F, E>::backward_complex_relative_iterator_base()
00358       {
00359       }
00360 
00361       template <typename C, typename F, typename E>
00362       template <typename Fref>
00363       inline
00364       backward_complex_relative_iterator_base<C, F, E>::backward_complex_relative_iterator_base(const Fref& f_ref)
00365         : super_(f_ref)
00366       {
00367       }
00368 
00369       template <typename C, typename F, typename E>
00370       inline
00371       bool
00372       backward_complex_relative_iterator_base<C, F, E>::is_valid() const
00373       {
00374         return i_ != this->adj_faces_.rend();
00375       }
00376 
00377       template <typename C, typename F, typename E>
00378       inline
00379       void
00380       backward_complex_relative_iterator_base<C, F, E>::invalidate()
00381       {
00382         i_ = this->adj_faces_.rend();
00383       }
00384 
00385       template <typename C, typename F, typename E>
00386       inline
00387       void
00388       backward_complex_relative_iterator_base<C, F, E>::do_start_()
00389       {
00390         exact(this)->update_adj_faces_();
00391         i_ = this->adj_faces_.rbegin();
00392       }
00393 
00394       template <typename C, typename F, typename E>
00395       inline
00396       void
00397       backward_complex_relative_iterator_base<C, F, E>::do_next_()
00398       {
00399         ++i_;
00400       }
00401 
00402       template <typename C, typename F, typename E>
00403       inline
00404       void
00405       backward_complex_relative_iterator_base<C, F, E>::update_f_()
00406       {
00407         mln_precondition(is_valid());
00408         this->f_ = *i_;
00409       }
00410 
00411 # endif // ! MLN_INCLUDE_ONLY
00412 
00413     } // end of namespace mln::topo::internal
00414 
00415   } // end of namespace mln::topo
00416 
00417 } // end of namespace mln
00418 
00419 #endif // ! MLN_TOPO_INTERNAL_COMPLEX_RELATIVE_ITERATOR_BASE_HH

Generated on Tue Oct 4 2011 15:23:37 for Milena (Olena) by  doxygen 1.7.1