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