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

p_complex_piter_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_CORE_INTERNAL_P_COMPLEX_PITER_BASE_HH
00027 # define MLN_CORE_INTERNAL_P_COMPLEX_PITER_BASE_HH
00028 
00032 
00033 # include <mln/core/internal/site_set_iterator_base.hh>
00034 
00035 /* FIXME: Rename internal::p_complex_piter_base_ to something else, as
00036    it is also used for p_faces piters.  Maybe
00037    internal::complex_piter_base_, but it is really close to
00038    internal::complex_iter_base_... */
00039 
00040 namespace mln
00041 {
00042 
00043   namespace internal
00044   {
00045 
00046     /*------------------------------------.
00047     | p_complex_piter_base_<I, S, P, E>.  |
00048     `------------------------------------*/
00049 
00050     // FIXME: P could probably be deduced from S.
00051 
00058     template <typename I, typename S, typename P, typename E>
00059     class p_complex_piter_base_
00060       : public internal::site_set_iterator_base< S, E >
00061     {
00062       typedef p_complex_piter_base_< I, S, P, E > self_;
00063       typedef internal::site_set_iterator_base< S, E > super_;
00064 
00066       typedef I iter;
00067 
00068     public:
00071       p_complex_piter_base_();
00072       p_complex_piter_base_(const S& pc);
00074 
00077     public:
00079       bool is_valid_() const;
00081       void invalidate_();
00082 
00084       void start_();
00086       void next_();
00087 
00088     private:
00090       void update_();
00092 
00093     protected:
00095       using super_::p_;
00097       iter iter_;
00098     };
00099 
00100 
00102     template <typename I, typename S, typename P, typename E>
00103     inline
00104     std::ostream&
00105     operator<<(std::ostream& ostr, const p_complex_piter_base_<I, S, P, E>& p);
00106 
00107 
00108 
00109 # ifndef MLN_INCLUDE_ONLY
00110 
00111     /*------------------------------------.
00112     | p_complex_piter_base_<I, S, P, E>.  |
00113     `------------------------------------*/
00114 
00115     template <typename I, typename S, typename P, typename E>
00116     inline
00117     p_complex_piter_base_<I, S, P, E>::p_complex_piter_base_()
00118     {
00119       mln_postcondition(!this->is_valid());
00120     }
00121 
00122     template <typename I, typename S, typename P, typename E>
00123     inline
00124     p_complex_piter_base_<I, S, P, E>::p_complex_piter_base_(const S& pc)
00125     {
00126       this->change_target(pc);
00127       iter_.set_cplx(pc.cplx());
00128       mln_postcondition(!this->is_valid());
00129     }
00130 
00131     template <typename I, typename S, typename P, typename E>
00132     inline
00133     bool
00134     p_complex_piter_base_<I, S, P, E>::is_valid_() const
00135     {
00136       return iter_.is_valid();
00137     }
00138 
00139     template <typename I, typename S, typename P, typename E>
00140     inline
00141     void
00142     p_complex_piter_base_<I, S, P, E>::invalidate_()
00143     {
00144       iter_.invalidate();
00145     }
00146 
00147     template <typename I, typename S, typename P, typename E>
00148     inline
00149     void
00150     p_complex_piter_base_<I, S, P, E>::start_()
00151     {
00152       iter_.start();
00153       if (this->is_valid())
00154         update_();
00155     }
00156 
00157     template <typename I, typename S, typename P, typename E>
00158     inline
00159     void
00160     p_complex_piter_base_<I, S, P, E>::next_()
00161     {
00162       iter_.next_();
00163       if (this->is_valid())
00164         update_();
00165     }
00166 
00167     template <typename I, typename S, typename P, typename E>
00168     inline
00169     void
00170     p_complex_piter_base_<I, S, P, E>::update_()
00171     {
00172       mln_precondition(this->is_valid());
00173       // Update psite_.
00174       typedef mln_psite(S) psite;
00175       p_ = psite(exact(this)->site_set(), iter_);
00176     }
00177 
00178 
00179     template <typename I, typename S, typename P, typename E>
00180     inline
00181     std::ostream&
00182     operator<<(std::ostream& ostr, const p_complex_piter_base_<I, S, P, E>& p)
00183     {
00184       return ostr << p.unproxy_();
00185     }
00186 
00187 # endif // ! MLN_INCLUDE_ONLY
00188 
00189   } // end of mln::internal
00190 
00191 } // end of mln
00192 
00193 
00194 #endif // ! MLN_CORE_INTERNAL_P_COMPLEX_PITER_BASE_HH

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