Milena (Olena)
User documentation 2.0a Id
|
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_P_GRAPH_PITER_HH 00027 # define MLN_CORE_SITE_SET_P_GRAPH_PITER_HH 00028 00032 00033 # include <mln/core/internal/site_set_iterator_base.hh> 00034 00035 00036 namespace mln 00037 { 00038 00039 // Forward declaration. 00040 template <typename S, typename I> class graph_psite; 00041 namespace util 00042 { 00043 template <typename G> class edge; 00044 template <typename G> class vertex; 00045 } 00046 00047 00048 00049 /*------------------------. 00050 | p_graph_piter<S,I>. | 00051 `------------------------*/ 00052 00054 template <typename S, typename I> 00055 class p_graph_piter 00056 : public internal::site_set_iterator_base< S, 00057 p_graph_piter<S, I> > 00058 { 00059 typedef p_graph_piter<S,I> self_; 00060 typedef internal::site_set_iterator_base< S, self_ > super_; 00061 typedef I iter; 00062 00063 public: 00064 00067 p_graph_piter(); 00068 p_graph_piter(const S& pv); 00070 00074 bool is_valid_() const; 00076 void invalidate_(); 00077 00079 void start_(); 00081 void next_(); 00083 00085 mln_q_subject(iter) element(); 00086 00088 const typename S::graph_t& graph() const; 00089 00091 const iter& hook_elt_() const; 00092 00094 unsigned id() const; 00095 00096 private: 00097 00099 void update_(); 00100 00101 private: 00102 00104 using super_::p_; 00105 00107 iter iter_; 00108 }; 00109 00110 00111 namespace internal 00112 { 00113 00116 template <typename S, typename I, typename E> 00117 struct subject_impl< const p_graph_piter<S,I>&, E > 00118 { 00119 typedef typename S::graph_t graph_t; 00120 00121 const graph_t& graph() const; 00122 unsigned id() const; 00123 util::edge<graph_t> edge_with(const util::vertex<graph_t>& v) const; 00124 00125 private: 00126 const E& exact_() const; 00127 }; 00128 00129 template <typename S, typename I, typename E> 00130 struct subject_impl< p_graph_piter<S,I>&, E > 00131 : subject_impl< const p_graph_piter<S,I>&, E > 00132 { 00133 mln_q_subject(I) element(); 00134 00135 private: 00136 E& exact_(); 00137 }; 00139 00140 } // end of namespace mln::internal 00141 00142 00143 # ifndef MLN_INCLUDE_ONLY 00144 00145 /*---------------------. 00146 | p_graph_piter<S,I>. | 00147 `---------------------*/ 00148 00149 template <typename S, typename I> 00150 inline 00151 p_graph_piter<S,I>::p_graph_piter() 00152 { 00153 mln_postcondition(! this->is_valid()); 00154 } 00155 00156 template <typename S, typename I> 00157 inline 00158 p_graph_piter<S,I>::p_graph_piter(const S& pv) 00159 : iter_(pv.graph()) 00160 { 00161 this->change_target(pv); 00162 mln_postcondition(! this->is_valid()); 00163 } 00164 00165 template <typename S, typename I> 00166 inline 00167 bool 00168 p_graph_piter<S,I>::is_valid_() const 00169 { 00170 return iter_.is_valid(); 00171 } 00172 00173 template <typename S, typename I> 00174 inline 00175 void 00176 p_graph_piter<S,I>::invalidate_() 00177 { 00178 iter_.invalidate(); 00179 } 00180 00181 template <typename S, typename I> 00182 inline 00183 void 00184 p_graph_piter<S,I>::start_() 00185 { 00186 iter_.start(); 00187 if (this->is_valid()) 00188 update_(); 00189 } 00190 00191 template <typename S, typename I> 00192 inline 00193 void 00194 p_graph_piter<S,I>::next_() 00195 { 00196 iter_.next(); 00197 if (this->is_valid()) 00198 update_(); 00199 } 00200 00201 template <typename S, typename I> 00202 inline 00203 mln_q_subject(I) 00204 p_graph_piter<S,I>::element() 00205 { 00206 return this->subj_(); 00207 } 00208 00209 template <typename S, typename I> 00210 inline 00211 const typename S::graph_t& 00212 p_graph_piter<S,I>::graph() const 00213 { 00214 return this->site_set().graph(); 00215 } 00216 00217 template <typename S, typename I> 00218 inline 00219 const I& 00220 p_graph_piter<S,I>::hook_elt_() const 00221 { 00222 return iter_; 00223 } 00224 00225 template <typename S, typename I> 00226 inline 00227 unsigned 00228 p_graph_piter<S,I>::id() const 00229 { 00230 return iter_.id(); 00231 } 00232 00233 template <typename S, typename I> 00234 inline 00235 void 00236 p_graph_piter<S,I>::update_() 00237 { 00238 mln_precondition(this->is_valid()); 00239 // Update psite_. 00240 p_.update_id(iter_.id()); 00241 } 00242 00243 00244 00245 namespace internal 00246 { 00247 00249 00250 template <typename S, typename I, typename E> 00251 inline 00252 const E& 00253 subject_impl< const p_graph_piter<S,I>&, E >::exact_() const 00254 { 00255 return internal::force_exact<const E>(*this); 00256 } 00257 00258 template <typename S, typename I, typename E> 00259 inline 00260 const typename subject_impl< const p_graph_piter<S,I>&, E >::graph_t& 00261 subject_impl< const p_graph_piter<S,I>&, E >::graph() const 00262 { 00263 return exact_().get_subject().graph(); 00264 } 00265 00266 template <typename S, typename I, typename E> 00267 inline 00268 unsigned 00269 subject_impl< const p_graph_piter<S,I>&, E >::id() const 00270 { 00271 return exact_().get_subject().id(); 00272 }; 00273 00274 template <typename S, typename I, typename E> 00275 inline 00276 util::edge<typename S::graph_t> 00277 subject_impl< const p_graph_piter<S,I>&, E >::edge_with(const util::vertex<graph_t>& v) const 00278 { 00279 return exact_().get_subject().element().edge_with(v); 00280 }; 00281 00282 template <typename S, typename I, typename E> 00283 inline 00284 E& 00285 subject_impl< p_graph_piter<S,I>&, E >::exact_() 00286 { 00287 return internal::force_exact<E>(*this); 00288 } 00289 00290 template <typename S, typename I, typename E> 00291 inline 00292 mln_q_subject(I) 00293 subject_impl< p_graph_piter<S,I>&, E >::element() 00294 { 00295 return exact_().get_subject().element(); 00296 } 00297 00298 } // end of namespace mln::internal 00299 00300 # endif // ! MLN_INCLUDE_ONLY 00301 00302 } // end of namespace mln 00303 00304 00305 #endif // ! MLN_CORE_SITE_SET_P_GRAPH_PITER_HH