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_UTIL_INTERNAL_GRAPH_NBH_ITER_HH
00027 # define MLN_UTIL_INTERNAL_GRAPH_NBH_ITER_HH
00028 
00029 # include <mln/core/concept/proxy.hh>
00030 # include <mln/util/internal/graph_nbh_iter_base.hh>
00031 # include <mln/util/vertex.hh>
00032 # include <mln/util/edge.hh>
00033 
00036 
00037 namespace mln
00038 {
00039 
00040   namespace internal
00041   {
00042 
00043     
00044 
00045 
00046 
00047     template <typename G>
00048     class vertex_nbh_vertex_fwd_iterator
00049       : public nbh_iterator_base<G,
00050                                  util::vertex<G>,
00051                                  util::vertex<G>,
00052                                  vertex_nbh_vertex_fwd_iterator<G> >
00053     {
00054       typedef util::vertex<G> V;
00055       typedef vertex_nbh_vertex_fwd_iterator<G> self_;
00056       typedef nbh_iterator_base<G, V, V, self_> super_;
00057 
00058       public:
00061         vertex_nbh_vertex_fwd_iterator();
00062         template <typename C>
00063         vertex_nbh_vertex_fwd_iterator(const C& c);
00065 
00066       protected:
00067         
00070         bool is_valid_() const;
00072 
00074         unsigned start_id_() const;
00075 
00077         unsigned next_id_() const;
00078 
00079         void update_();
00080 
00081         friend class nbh_iterator_base<G, V, V, self_>;
00082     };
00083 
00084     template <typename G>
00085     class vertex_nbh_vertex_bkd_iterator
00086       : public nbh_iterator_base<G,
00087                                  util::vertex<G>,
00088                                  util::vertex<G>,
00089                                  vertex_nbh_vertex_bkd_iterator<G> >
00090     {
00091       typedef util::vertex<G> V;
00092       typedef vertex_nbh_vertex_bkd_iterator<G> self_;
00093       typedef nbh_iterator_base<G, V, V, self_> super_;
00094 
00095       public:
00098         vertex_nbh_vertex_bkd_iterator();
00099         template <typename C>
00100         vertex_nbh_vertex_bkd_iterator(const C& c);
00102 
00103       protected:
00107         bool is_valid_() const;
00109 
00111         unsigned start_id_() const;
00112 
00114         unsigned next_id_() const;
00115 
00116         void update_();
00117 
00118         friend class nbh_iterator_base<G, V, V, self_>;
00119     };
00120 
00121 
00122     
00123 
00124 
00125 
00126     template <typename G>
00127     class vertex_nbh_edge_fwd_iterator
00128       : public nbh_iterator_base<G,
00129                                  util::vertex<G>,
00130                                  util::edge<G>,
00131                                  vertex_nbh_edge_fwd_iterator<G> >
00132     {
00133       typedef util::vertex<G> V;
00134       typedef util::edge<G> E;
00135       typedef vertex_nbh_edge_fwd_iterator<G> self_;
00136       typedef nbh_iterator_base<G, V, E, self_> super_;
00137 
00138       public:
00141         vertex_nbh_edge_fwd_iterator();
00142         template <typename C>
00143         vertex_nbh_edge_fwd_iterator(const C& c);
00145 
00146       protected:
00147         
00150         bool is_valid_() const;
00152 
00154         unsigned start_id_() const;
00155 
00157         unsigned next_id_() const;
00158 
00159         void update_();
00160 
00161         friend class nbh_iterator_base<G, V, E, self_>;
00162     };
00163 
00164 
00165     template <typename G>
00166     class vertex_nbh_edge_bkd_iterator
00167       : public nbh_iterator_base<G,
00168                                  util::vertex<G>,
00169                                  util::edge<G>,
00170                                  vertex_nbh_edge_bkd_iterator<G> >
00171     {
00172       typedef util::vertex<G> V;
00173       typedef util::edge<G> E;
00174       typedef vertex_nbh_edge_bkd_iterator<G> self_;
00175       typedef nbh_iterator_base<G, V, E, self_> super_;
00176 
00177       public:
00180         vertex_nbh_edge_bkd_iterator();
00181         template <typename C>
00182         vertex_nbh_edge_bkd_iterator(const C& c);
00184 
00185       protected:
00186         
00189         bool is_valid_() const;
00191 
00193         unsigned start_id_() const;
00194 
00196         unsigned next_id_() const;
00197 
00198         void update_();
00199 
00200         friend class nbh_iterator_base<G, V, E, self_>;
00201     };
00202 
00203 
00204     
00205 
00206 
00207 
00208     template <typename G>
00209     class edge_nbh_edge_fwd_iterator
00210       : public nbh_iterator_base<G,
00211                                  util::edge<G>,
00212                                  util::edge<G>,
00213                                  edge_nbh_edge_fwd_iterator<G> >
00214     {
00215       typedef util::edge<G> E;
00216       typedef edge_nbh_edge_fwd_iterator<G> self_;
00217       typedef nbh_iterator_base<G, E, E, self_> super_;
00218 
00219       public:
00222         edge_nbh_edge_fwd_iterator();
00223         template <typename C>
00224         edge_nbh_edge_fwd_iterator(const C& c);
00226 
00227       protected:
00228         
00231         bool is_valid_() const;
00233 
00235         unsigned start_id_() const;
00236 
00238         unsigned next_id_() const;
00239 
00240         void update_();
00241 
00242         friend class nbh_iterator_base<G, E, E, self_>;
00243     };
00244 
00245 
00246     template <typename G>
00247     class edge_nbh_edge_bkd_iterator
00248       : public nbh_iterator_base<G,
00249                                  util::edge<G>,
00250                                  util::edge<G>,
00251                                  edge_nbh_edge_bkd_iterator<G> >
00252     {
00253       typedef util::edge<G> E;
00254       typedef edge_nbh_edge_bkd_iterator<G> self_;
00255       typedef nbh_iterator_base<G, E, E, self_> super_;
00256 
00257       public:
00260         edge_nbh_edge_bkd_iterator();
00261         template <typename C>
00262         edge_nbh_edge_bkd_iterator(const C& c);
00264 
00265       protected:
00266         
00269         bool is_valid_() const;
00271 
00273         unsigned start_id_() const;
00274 
00276         unsigned next_id_() const;
00277 
00278         void update_();
00279 
00280         friend class nbh_iterator_base<G, E, E, self_>;
00281     };
00282 
00283 # ifndef MLN_INCLUDE_ONLY
00284 
00285     
00286 
00287 
00288 
00289     template <typename G>
00290     inline
00291     vertex_nbh_vertex_fwd_iterator<G>::vertex_nbh_vertex_fwd_iterator()
00292     {
00293     }
00294 
00295     template <typename G>
00296     template <typename C>
00297     inline
00298     vertex_nbh_vertex_fwd_iterator<G>::vertex_nbh_vertex_fwd_iterator(const C& c)
00299     : super_(c)
00300     {
00301     }
00302 
00303     template <typename G>
00304     inline
00305     bool
00306     vertex_nbh_vertex_fwd_iterator<G>::is_valid_() const
00307     {
00308       return this->c_->is_valid() && this->i_ < this->c_->nmax_nbh_vertices();
00309     }
00310 
00311     template <typename G>
00312     inline
00313     unsigned
00314     vertex_nbh_vertex_fwd_iterator<G>::start_id_() const
00315     {
00316       return 0;
00317     }
00318 
00319     template <typename G>
00320     inline
00321     unsigned
00322     vertex_nbh_vertex_fwd_iterator<G>::next_id_() const
00323     {
00324       return this->i_ + 1;
00325     }
00326 
00327     template <typename G>
00328     inline
00329     void
00330     vertex_nbh_vertex_fwd_iterator<G>::update_()
00331     {
00332       this->elt_.update_id(this->c_->ith_nbh_vertex(this->i_));
00333     }
00334 
00335     
00336 
00337 
00338 
00339     template <typename G>
00340     inline
00341     vertex_nbh_vertex_bkd_iterator<G>::vertex_nbh_vertex_bkd_iterator()
00342     {
00343     }
00344 
00345     template <typename G>
00346     template <typename C>
00347     inline
00348     vertex_nbh_vertex_bkd_iterator<G>::vertex_nbh_vertex_bkd_iterator(const C& c)
00349       : super_(c)
00350     {
00351     }
00352 
00353     template <typename G>
00354     inline
00355     bool
00356     vertex_nbh_vertex_bkd_iterator<G>::is_valid_() const
00357     {
00358       return this->c_->is_valid() && this->i_ < this->c_->nmax_nbh_vertices();
00359     }
00360 
00361     template <typename G>
00362     inline
00363     unsigned
00364     vertex_nbh_vertex_bkd_iterator<G>::start_id_() const
00365     {
00366       return this->c_->nmax_nbh_vertices() - 1;
00367     }
00368 
00369     template <typename G>
00370     inline
00371     unsigned
00372     vertex_nbh_vertex_bkd_iterator<G>::next_id_() const
00373     {
00374       return this->i_ - 1;
00375     }
00376 
00377     template <typename G>
00378     inline
00379     void
00380     vertex_nbh_vertex_bkd_iterator<G>::update_()
00381     {
00382       this->elt_.update_id(this->c_->ith_nbh_vertex(this->i_));
00383     }
00384 
00385 
00386     
00387 
00388 
00389 
00390     template <typename G>
00391     inline
00392     vertex_nbh_edge_fwd_iterator<G>::vertex_nbh_edge_fwd_iterator()
00393     {
00394     }
00395 
00396     template <typename G>
00397     template <typename C>
00398     inline
00399     vertex_nbh_edge_fwd_iterator<G>::vertex_nbh_edge_fwd_iterator(const C& c)
00400       : super_(c)
00401     {
00402     }
00403 
00404     template <typename G>
00405     inline
00406     bool
00407     vertex_nbh_edge_fwd_iterator<G>::is_valid_() const
00408     {
00409       return this->c_->is_valid() && this->i_ < this->c_->nmax_nbh_edges();
00410     }
00411 
00412     template <typename G>
00413     inline
00414     unsigned
00415     vertex_nbh_edge_fwd_iterator<G>::start_id_() const
00416     {
00417       return 0;
00418     }
00419 
00420     template <typename G>
00421     inline
00422     unsigned
00423     vertex_nbh_edge_fwd_iterator<G>::next_id_() const
00424     {
00425       return this->i_ + 1;
00426     }
00427 
00428     template <typename G>
00429     inline
00430     void
00431     vertex_nbh_edge_fwd_iterator<G>::update_()
00432     {
00433       this->elt_.update_id(this->c_->ith_nbh_edge(this->i_));
00434     }
00435 
00436     
00437 
00438 
00439 
00440     template <typename G>
00441     inline
00442     vertex_nbh_edge_bkd_iterator<G>::vertex_nbh_edge_bkd_iterator()
00443     {
00444     }
00445 
00446     template <typename G>
00447     template <typename C>
00448     inline
00449     vertex_nbh_edge_bkd_iterator<G>::vertex_nbh_edge_bkd_iterator(const C& c)
00450       : super_(c)
00451     {
00452     }
00453 
00454     template <typename G>
00455     inline
00456     bool
00457     vertex_nbh_edge_bkd_iterator<G>::is_valid_() const
00458     {
00459       return this->c_->is_valid() && this->i_ < this->c_->nmax_nbh_edges();
00460     }
00461 
00462     template <typename G>
00463     inline
00464     unsigned
00465     vertex_nbh_edge_bkd_iterator<G>::start_id_() const
00466     {
00467       return this->c_->nmax_nbh_edges() - 1;
00468     }
00469 
00470     template <typename G>
00471     inline
00472     unsigned
00473     vertex_nbh_edge_bkd_iterator<G>::next_id_() const
00474     {
00475       return this->i_ - 1;
00476     }
00477 
00478     template <typename G>
00479     inline
00480     void
00481     vertex_nbh_edge_bkd_iterator<G>::update_()
00482     {
00483       this->elt_.update_id(this->c_->ith_nbh_edge(this->i_));
00484     }
00485 
00486 
00487 
00488     
00489 
00490 
00491 
00492     template <typename G>
00493     inline
00494     edge_nbh_edge_fwd_iterator<G>::edge_nbh_edge_fwd_iterator()
00495     {
00496     }
00497 
00498     template <typename G>
00499     template <typename C>
00500     inline
00501     edge_nbh_edge_fwd_iterator<G>::edge_nbh_edge_fwd_iterator(const C& c)
00502       : super_(c)
00503     {
00504     }
00505 
00506     template <typename G>
00507     inline
00508     bool
00509     edge_nbh_edge_fwd_iterator<G>::is_valid_() const
00510     {
00511       return this->c_->is_valid() && this->i_ < this->c_->nmax_nbh_edges();
00512     }
00513 
00514     template <typename G>
00515     inline
00516     unsigned
00517     edge_nbh_edge_fwd_iterator<G>::start_id_() const
00518     {
00519       return 0;
00520     }
00521 
00522     template <typename G>
00523     inline
00524     unsigned
00525     edge_nbh_edge_fwd_iterator<G>::next_id_() const
00526     {
00527       return this->i_ + 1;
00528     }
00529 
00530     template <typename G>
00531     inline
00532     void
00533     edge_nbh_edge_fwd_iterator<G>::update_()
00534     {
00535       
00536       
00537       
00538       
00539       util::edge_id_t e_id = this->c_->ith_nbh_edge(this->i_);
00540       while (e_id == this->c_->id())
00541       {
00542         this->i_ = next_id_();
00543         e_id = this->c_->ith_nbh_edge(this->i_);
00544       }
00545 
00546       this->elt_.update_id(e_id);
00547     }
00548 
00549     
00550 
00551 
00552 
00553     template <typename G>
00554     inline
00555     edge_nbh_edge_bkd_iterator<G>::edge_nbh_edge_bkd_iterator()
00556     {
00557     }
00558 
00559     template <typename G>
00560     template <typename C>
00561     inline
00562     edge_nbh_edge_bkd_iterator<G>::edge_nbh_edge_bkd_iterator(const C& c)
00563       : super_(c)
00564     {
00565     }
00566 
00567     template <typename G>
00568     inline
00569     bool
00570     edge_nbh_edge_bkd_iterator<G>::is_valid_() const
00571     {
00572       return this->c_->is_valid() && this->i_ < this->c_->nmax_nbh_edges();
00573     }
00574 
00575     template <typename G>
00576     inline
00577     unsigned
00578     edge_nbh_edge_bkd_iterator<G>::start_id_() const
00579     {
00580       return this->c_->nmax_nbh_edges() - 1;
00581     }
00582 
00583     template <typename G>
00584     inline
00585     unsigned
00586     edge_nbh_edge_bkd_iterator<G>::next_id_() const
00587     {
00588       return this->i_ - 1;
00589     }
00590 
00591     template <typename G>
00592     inline
00593     void
00594     edge_nbh_edge_bkd_iterator<G>::update_()
00595     {
00596       
00597       
00598       
00599       unsigned e_id = this->c_->ith_nbh_edge(this->i_);
00600       while (e_id == this->c_->id())
00601       {
00602         this->i_ = next_id_();
00603         e_id = this->c_->ith_nbh_edge(this->i_);
00604       }
00605 
00606       this->elt_.update_id(e_id);
00607     }
00608 
00609 # endif // !MLN_INCLUDE_ONLY
00610 
00611   } 
00612 
00613 } 
00614 
00615 
00616 #endif // ! MLN_UTIL_INTERNAL_GRAPH_NBH_ITER_HH