00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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
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
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 }
00141
00142
00143 # ifndef MLN_INCLUDE_ONLY
00144
00145
00146
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
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 }
00299
00300 # endif // ! MLN_INCLUDE_ONLY
00301
00302 }
00303
00304
00305 #endif // ! MLN_CORE_SITE_SET_P_GRAPH_PITER_HH