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

box_piter.hh

00001 // Copyright (C) 2007, 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_CORE_SITE_SET_BOX_PITER_HH
00027 # define MLN_CORE_SITE_SET_BOX_PITER_HH
00028 
00032 
00033 # include <mln/core/internal/site_set_iterator_base.hh>
00034 # include <mln/core/concept/box.hh>
00035 # include <mln/core/site_set/box.hh>
00036 
00037 
00038 namespace mln
00039 {
00040 
00047   template <typename P>
00048   class box_fwd_piter_ : public internal::site_set_iterator_base< box<P>,
00049                                                                   box_fwd_piter_<P> >
00050   {
00051     typedef box_fwd_piter_<P> self_;
00052     typedef internal::site_set_iterator_base< box<P>, self_ > super_;
00053 
00054   public:
00055 
00056     // Make definitions from super class available.
00057     enum { dim = P::dim };
00058 
00060     box_fwd_piter_();
00061 
00066     box_fwd_piter_(const mln::box<P>& b);
00067 
00069     bool is_valid_() const;
00070 
00072     void invalidate_();
00073 
00075     void start_();
00076 
00078     void next_();
00079 
00080   protected:
00081     using super_::p_;
00082     using super_::s_;
00083   };
00084 
00085 
00086 
00093   template <typename P>
00094   class box_bkd_piter_ : public internal::site_set_iterator_base< box<P>,
00095                                                                   box_bkd_piter_<P> >
00096   {
00097     typedef box_bkd_piter_<P> self_;
00098     typedef internal::site_set_iterator_base< box<P>, self_ > super_;
00099 
00100   public:
00101 
00102     // Make definitions from super class available.
00103     enum { dim = P::dim };
00104 
00106     box_bkd_piter_();
00107 
00112     box_bkd_piter_(const box<P>& b);
00113 
00115     bool is_valid_() const;
00116 
00118     void invalidate_();
00119 
00121     void start_();
00122 
00124     void next_();
00125 
00126   protected:
00127     using super_::p_;
00128     using super_::s_;
00129   };
00130 
00131 
00132 
00133 
00134 # ifndef MLN_INCLUDE_ONLY
00135 
00136 
00137   // box_fwd_piter_<P>
00138 
00139   template <typename P>
00140   inline
00141   box_fwd_piter_<P>::box_fwd_piter_()
00142   {
00143   }
00144 
00145   template <typename P>
00146   inline
00147   box_fwd_piter_<P>::box_fwd_piter_(const mln::box<P>& b)
00148   {
00149     this->change_target(b);
00150   }
00151 
00152   template <typename P>
00153   inline
00154   bool
00155   box_fwd_piter_<P>::is_valid_() const
00156   {
00157     return p_[0] != s_->pmax()[0] + 1;
00158   }
00159 
00160   template <typename P>
00161   inline
00162   void
00163   box_fwd_piter_<P>::invalidate_()
00164   {
00165     p_[0] = static_cast<def::coord>(s_->pmax()[0] + 1);
00166   }
00167 
00168   template <typename P>
00169   inline
00170   void
00171   box_fwd_piter_<P>::start_()
00172   {
00173     p_ = s_->pmin();
00174   }
00175 
00176   template <typename P>
00177   inline
00178   void
00179   box_fwd_piter_<P>::next_()
00180   {
00181     for (int i = dim - 1; i >= 0; --i)
00182       if (p_[i] != s_->pmax()[i])
00183         {
00184           ++p_[i];
00185           break;
00186         }
00187       else
00188         {
00189           p_[i] = s_->pmin()[i];
00190           if (i == 0)
00191             invalidate_();
00192         }
00193 
00194     // memo
00195 
00196 //     for (int i = dim - 1; i >= 0; --i)
00197 //       if (p_[i] != s_->pmax()[i])
00198 //      {
00199 //        ++p_[i];
00200 //        break;
00201 //      }
00202 //       else
00203 //      p_[i] = s_->pmin()[i];
00204 //     if (p_ == s_->pmin())
00205 //       invalidate_();
00206   }
00207 
00208 
00209   // box_bkd_piter_<P>
00210 
00211   template <typename P>
00212   inline
00213   box_bkd_piter_<P>::box_bkd_piter_()
00214   {
00215   }
00216 
00217   template <typename P>
00218   inline
00219   box_bkd_piter_<P>::box_bkd_piter_(const box<P>& b)
00220   {
00221     this->change_target(b);
00222   }
00223 
00224   template <typename P>
00225   inline
00226   bool
00227   box_bkd_piter_<P>::is_valid_() const
00228   {
00229     return p_[0] != s_->pmin()[0] - 1;
00230   }
00231 
00232   template <typename P>
00233   inline
00234   void
00235   box_bkd_piter_<P>::invalidate_()
00236   {
00237     p_[0] = mln_coord(P)(s_->pmin()[0] - 1);
00238   }
00239 
00240   template <typename P>
00241   inline
00242   void
00243   box_bkd_piter_<P>::start_()
00244   {
00245     p_ = s_->pmax();
00246   }
00247 
00248   template <typename P>
00249   inline
00250   void
00251   box_bkd_piter_<P>::next_()
00252   {
00253     for (int i = dim - 1; i >= 0; --i)
00254       if (p_[i] == s_->pmin()[i])
00255         p_[i] = s_->pmax()[i];
00256       else
00257         {
00258           --p_[i];
00259           break;
00260         }
00261     if (p_ == s_->pmax())
00262       invalidate_();
00263   }
00264 
00265 # endif // ! MLN_INCLUDE_ONLY
00266 
00267 } // end of namespace mln
00268 
00269 
00270 #endif // ! MLN_CORE_SITE_SET_BOX_PITER_HH

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