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

p_transformed_piter.hh

00001 // Copyright (C) 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_P_TRANSFORMED_PITER_HH
00027 # define MLN_CORE_SITE_SET_P_TRANSFORMED_PITER_HH
00028 
00032 
00033 # include <mln/core/internal/site_set_iterator_base.hh>
00034 # include <mln/core/site_set/p_transformed.hh>
00035 
00036 
00037 namespace mln
00038 {
00039 
00040 
00047   //
00048   template <typename Pi, typename S, typename F>
00049   struct p_transformed_piter
00050     : public internal::site_set_iterator_base< p_transformed<S,F>,            // Site_Set.
00051                                                p_transformed_piter<Pi,S,F> >  // Exact.
00052   {
00054     p_transformed_piter();
00055 
00057     p_transformed_piter(const p_transformed<S,F>& s);
00058 
00060     bool is_valid_() const;
00061     
00063     void invalidate_();
00064     
00066     void start_();
00067     
00069     void next_();
00070     
00072     void change_target(const p_transformed<S,F>& s);
00073 
00074   private:
00075     typedef p_transformed_piter<Pi,S,F> self_;
00076     typedef internal::site_set_iterator_base<p_transformed<S,F>, self_> super_;
00077 
00078   protected:
00079     using super_::s_;
00080     using super_::p_;
00081 
00082     // The underlying site iterator.
00083     Pi pi_;
00084   };
00085 
00086 
00087 
00088 # ifndef MLN_INCLUDE_ONLY
00089 
00090   template <typename Pi, typename S, typename F>
00091   inline
00092   p_transformed_piter<Pi,S,F>::p_transformed_piter()
00093   {
00094   }
00095 
00096   template <typename Pi, typename S, typename F>
00097   inline
00098   p_transformed_piter<Pi,S,F>::p_transformed_piter(const p_transformed<S,F>& s)
00099   {
00100     this->change_target(s);
00101   }
00102 
00103   template <typename Pi, typename S, typename F>
00104   inline
00105   bool
00106   p_transformed_piter<Pi,S,F>::is_valid_() const
00107   {
00108     return pi_.is_valid();
00109   }
00110     
00111   template <typename Pi, typename S, typename F>
00112   inline
00113   void
00114   p_transformed_piter<Pi,S,F>::invalidate_()
00115   {
00116     pi_.invalidate();
00117   }
00118 
00119   template <typename Pi, typename S, typename F>
00120   inline
00121   void
00122   p_transformed_piter<Pi,S,F>::start_()
00123   {
00124     pi_.start();
00125     if (pi_.is_valid())
00126       p_ = s_->function()(pi_);
00127   }
00128 
00129   template <typename Pi, typename S, typename F>
00130   inline
00131   void
00132   p_transformed_piter<Pi,S,F>::next_()
00133   {
00134     pi_.next();
00135     if (pi_.is_valid())
00136       p_ = s_->function()(pi_);
00137   }
00138 
00139   template <typename Pi, typename S, typename F>
00140   inline
00141   void
00142   p_transformed_piter<Pi,S,F>::change_target(const p_transformed<S,F>& s)
00143   {
00144     s_ = & s;
00145     // p might be also updated since it can hold a pointer towards
00146     // the set it designates, so:
00147     pi_.change_target(s.primary_set());
00148     // Last:
00149     this->invalidate();
00150   }
00151 
00152 # endif // ! MLN_INCLUDE_ONLY
00153 
00154 } // end of namespace mln
00155 
00156 
00157 #endif // ! MLN_CORE_SITE_SET_P_TRANSFORMED_PITER_HH

Generated on Thu Sep 8 2011 18:32:18 for Milena (Olena) by  doxygen 1.7.1