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

static_n_face_iter.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_STATIC_N_FACE_ITER_HH
00027 # define MLN_TOPO_STATIC_N_FACE_ITER_HH
00028 
00033 
00034 # include <mln/topo/internal/complex_set_iterator_base.hh>
00035 # include <mln/topo/face.hh>
00036 
00037 
00038 namespace mln
00039 {
00040 
00041   namespace topo
00042   {
00043 
00044     /*-------------------------------------.
00045     | topo::static_n_face_fwd_iter<N, D>.  |
00046     `-------------------------------------*/
00047 
00053     //
00054     template <unsigned N, unsigned D>
00055     class static_n_face_fwd_iter
00056       : public internal::complex_set_iterator_base< topo::face<D>,
00057                                                     static_n_face_fwd_iter<N, D> >
00058     {
00059       // Tech note: we use topo::face to help g++-2.95.
00060     private:
00061       typedef static_n_face_fwd_iter<N, D> self_;
00062       typedef internal::complex_set_iterator_base< topo::face<D>, self_ > super_;
00063 
00064     public:
00065       using super_::is_valid;
00066       using super_::invalidate;
00067 
00068     public:
00071       static_n_face_fwd_iter();
00072       // FIXME: See comment in internal::complex_set_iterator_base's
00073       // default ctor.
00074       static_n_face_fwd_iter(complex<D>& c);
00076 
00080       void start();
00082       void next_();
00084 
00085     private:
00086       using super_::f_;
00087     };
00088 
00089 
00090     /*-------------------------------------.
00091     | topo::static_n_face_bkd_iter<N, D>.  |
00092     `-------------------------------------*/
00093 
00099     //
00100     template <unsigned N, unsigned D>
00101     class static_n_face_bkd_iter
00102       : public internal::complex_set_iterator_base< topo::face<D>,
00103                                                     static_n_face_bkd_iter<N, D> >
00104     {
00105       // Tech note: we use topo::face to help g++-2.95.
00106     private:
00107       typedef static_n_face_bkd_iter<N, D> self_;
00108       typedef internal::complex_set_iterator_base< topo::face<D>, self_ > super_;
00109 
00110     public:
00111       using super_::is_valid;
00112       using super_::invalidate;
00113 
00114     public:
00117       static_n_face_bkd_iter();
00118       // FIXME: See comment in internal::complex_set_iterator_base's
00119       // default ctor.
00120       static_n_face_bkd_iter(complex<D>& c);
00122 
00126       void start();
00128       void next_();
00130 
00131     private:
00132       using super_::f_;
00133     };
00134 
00135 
00136 
00137 # ifndef MLN_INCLUDE_ONLY
00138 
00139     /*-------------------------------------.
00140     | topo::static_n_face_fwd_iter<N, D>.  |
00141     `-------------------------------------*/
00142 
00143     template <unsigned N, unsigned D>
00144     inline
00145     static_n_face_fwd_iter<N, D>::static_n_face_fwd_iter()
00146       : super_()
00147     {
00148       // Ensure N is compatible with D.
00149       metal::bool_< N <= D >::check();
00150       f_.set_n(N);
00151       mln_postcondition(!is_valid());
00152     }
00153 
00154     template <unsigned N, unsigned D>
00155     inline
00156     static_n_face_fwd_iter<N, D>::static_n_face_fwd_iter(complex<D>& c)
00157       : super_(c)
00158     {
00159       // Ensure N is compatible with D.
00160       metal::bool_< N <= D >::check();
00161       f_.set_n(N);
00162       mln_postcondition(!is_valid());
00163     }
00164 
00165     template <unsigned N, unsigned D>
00166     inline
00167     void
00168     static_n_face_fwd_iter<N, D>::start()
00169     {
00170       f_.set_face_id(0u);
00171     }
00172 
00173     template <unsigned N, unsigned D>
00174     inline
00175     void
00176     static_n_face_fwd_iter<N, D>::next_()
00177     {
00178       if (is_valid())
00179         {
00180           if (f_.face_id() + 1 < f_.cplx().template nfaces_of_static_dim<N>())
00181             f_.inc_face_id();
00182           else
00183             invalidate();
00184         }
00185     }
00186 
00187 
00188     /*-------------------------------------.
00189     | topo::static_n_face_bkd_iter<N, D>.  |
00190     `-------------------------------------*/
00191 
00192     template <unsigned N, unsigned D>
00193     inline
00194     static_n_face_bkd_iter<N, D>::static_n_face_bkd_iter()
00195       : super_()
00196     {
00197       // Ensure N is compatible with D.
00198       metal::bool_< N <= D >::check();
00199       f_.set_n(N);
00200       mln_postcondition(!is_valid());
00201     }
00202 
00203     template <unsigned N, unsigned D>
00204     inline
00205     static_n_face_bkd_iter<N, D>::static_n_face_bkd_iter(complex<D>& c)
00206       : super_(c)
00207     {
00208       // Ensure N is compatible with D.
00209       metal::bool_< N <= D >::check();
00210       f_.set_n(N);
00211       mln_postcondition(!is_valid());
00212     }
00213 
00214     template <unsigned N, unsigned D>
00215     inline
00216     void
00217     static_n_face_bkd_iter<N, D>::start()
00218     {
00219       f_.set_face_id(f_.cplx().template nfaces_of_static_dim<N>() - 1);
00220     }
00221 
00222     template <unsigned N, unsigned D>
00223     inline
00224     void
00225     static_n_face_bkd_iter<N, D>::next_()
00226     {
00227       if (is_valid())
00228         {
00229           if (f_.face_id() > 0)
00230             f_.dec_face_id();
00231           else
00232             invalidate();
00233         }
00234     }
00235 
00236 # endif // ! MLN_INCLUDE_ONLY
00237 
00238   } // end of namespace mln::topo
00239 
00240 } // end of namespace mln
00241 
00242 #endif // ! MLN_TOPO_STATIC_N_FACE_ITER_HH

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