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

graph_nbh_iter.hh

00001 // Copyright (C) 2008, 2009 EPITA Research and Development Laboratory
00002 // (LRDE)
00003 //
00004 // This file is part of Olena.
00005 //
00006 // Olena is free software: you can redistribute it and/or modify it under
00007 // the terms of the GNU General Public License as published by the Free
00008 // Software Foundation, version 2 of the License.
00009 //
00010 // Olena is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00017 //
00018 // As a special exception, you may use this file as part of a free
00019 // software project without restriction.  Specifically, if other files
00020 // instantiate templates or use macros or inline functions from this
00021 // file, or you compile this file and link it with other files to produce
00022 // an executable, this file does not by itself cause the resulting
00023 // executable to be covered by the GNU General Public License.  This
00024 // exception does not however invalidate any other reasons why the
00025 // executable file might be covered by the GNU General Public License.
00026 
00027 #ifndef MLN_UTIL_INTERNAL_GRAPH_NBH_ITER_HH
00028 # define MLN_UTIL_INTERNAL_GRAPH_NBH_ITER_HH
00029 
00030 # include <mln/core/concept/proxy.hh>
00031 # include <mln/util/internal/graph_nbh_iter_base.hh>
00032 # include <mln/util/vertex.hh>
00033 # include <mln/util/edge.hh>
00034 
00038 
00039 namespace mln
00040 {
00041 
00042   namespace internal
00043   {
00044 
00045     /*-----------------------------`
00046     | vertex_nbh_vertex_*_iterator |
00047     \-----------------------------*/
00048 
00049     template <typename G>
00050     class vertex_nbh_vertex_fwd_iterator
00051       : public nbh_iterator_base<G,
00052                                  util::vertex<G>,
00053                                  util::vertex<G>,
00054                                  vertex_nbh_vertex_fwd_iterator<G> >
00055     {
00056         typedef util::vertex<G> V;
00057         typedef vertex_nbh_vertex_fwd_iterator<G> self_;
00058         typedef nbh_iterator_base<G, V, V, self_> super_;
00059 
00060       public:
00062         typedef V center;
00064         typedef V nbh;
00065 
00068         vertex_nbh_vertex_fwd_iterator();
00069         template <typename C>
00070         vertex_nbh_vertex_fwd_iterator(const C& c);
00072 
00073       protected:
00074         // Manipulation.
00077         bool is_valid_() const;
00079 
00081         unsigned start_id_() const;
00082 
00084         unsigned next_id_() const;
00085 
00086         void update_();
00087 
00088         friend class nbh_iterator_base<G, V, V, self_>;
00089     };
00090 
00091     template <typename G>
00092     class vertex_nbh_vertex_bkd_iterator
00093       : public nbh_iterator_base<G,
00094                                  util::vertex<G>,
00095                                  util::vertex<G>,
00096                                  vertex_nbh_vertex_bkd_iterator<G> >
00097     {
00098         typedef util::vertex<G> V;
00099 
00100         typedef vertex_nbh_vertex_bkd_iterator<G> self_;
00101         typedef nbh_iterator_base<G, V, V, self_> super_;
00102 
00103       public:
00105         typedef V center;
00107         typedef V nbh;
00108 
00111         vertex_nbh_vertex_bkd_iterator();
00112         template <typename C>
00113         vertex_nbh_vertex_bkd_iterator(const C& c);
00115 
00116       protected:
00120         bool is_valid_() const;
00122 
00124         unsigned start_id_() const;
00125 
00127         unsigned next_id_() const;
00128 
00129         void update_();
00130 
00131         friend class nbh_iterator_base<G, V, V, self_>;
00132     };
00133 
00134 
00135     /*---------------------------`
00136     | vertex_nbh_edge_*_iterator |
00137     \---------------------------*/
00138 
00139     template <typename G>
00140     class vertex_nbh_edge_fwd_iterator
00141       : public nbh_iterator_base<G,
00142                                  util::vertex<G>,
00143                                  util::edge<G>,
00144                                  vertex_nbh_edge_fwd_iterator<G> >
00145     {
00146         typedef util::vertex<G> V;
00147         typedef util::edge<G> E;
00148         typedef vertex_nbh_edge_fwd_iterator<G> self_;
00149         typedef nbh_iterator_base<G, V, E, self_> super_;
00150 
00151       public:
00153         typedef V center;
00155         typedef E nbh;
00156 
00159         vertex_nbh_edge_fwd_iterator();
00160         template <typename C>
00161         vertex_nbh_edge_fwd_iterator(const C& c);
00163 
00164       protected:
00165         // Manipulation.
00168         bool is_valid_() const;
00170 
00172         unsigned start_id_() const;
00173 
00175         unsigned next_id_() const;
00176 
00177         void update_();
00178 
00179         friend class nbh_iterator_base<G, V, E, self_>;
00180     };
00181 
00182 
00183     template <typename G>
00184     class vertex_nbh_edge_bkd_iterator
00185       : public nbh_iterator_base<G,
00186                                  util::vertex<G>,
00187                                  util::edge<G>,
00188                                  vertex_nbh_edge_bkd_iterator<G> >
00189     {
00190         typedef util::vertex<G> V;
00191         typedef util::edge<G> E;
00192         typedef vertex_nbh_edge_bkd_iterator<G> self_;
00193         typedef nbh_iterator_base<G, V, E, self_> super_;
00194 
00195       public:
00197         typedef V center;
00199         typedef E nbh;
00200 
00203         vertex_nbh_edge_bkd_iterator();
00204         template <typename C>
00205         vertex_nbh_edge_bkd_iterator(const C& c);
00207 
00208       protected:
00209         // Manipulation.
00212         bool is_valid_() const;
00214 
00216         unsigned start_id_() const;
00217 
00219         unsigned next_id_() const;
00220 
00221         void update_();
00222 
00223         friend class nbh_iterator_base<G, V, E, self_>;
00224     };
00225 
00226 
00227     /*---------------------------`
00228     | edge_nbh_edge_*_iterator |
00229     \---------------------------*/
00230 
00231     template <typename G>
00232     class edge_nbh_edge_fwd_iterator
00233       : public nbh_iterator_base<G,
00234                                  util::edge<G>,
00235                                  util::edge<G>,
00236                                  edge_nbh_edge_fwd_iterator<G> >
00237     {
00238         typedef util::edge<G> E;
00239         typedef edge_nbh_edge_fwd_iterator<G> self_;
00240         typedef nbh_iterator_base<G, E, E, self_> super_;
00241 
00242       public:
00244         typedef E center;
00246         typedef E nbh;
00247 
00248 
00251         edge_nbh_edge_fwd_iterator();
00252         template <typename C>
00253         edge_nbh_edge_fwd_iterator(const C& c);
00255 
00256       protected:
00257         // Manipulation.
00260         bool is_valid_() const;
00262 
00264         unsigned start_id_() const;
00265 
00267         unsigned next_id_() const;
00268 
00269         void update_();
00270 
00271         friend class nbh_iterator_base<G, E, E, self_>;
00272     };
00273 
00274 
00275     template <typename G>
00276     class edge_nbh_edge_bkd_iterator
00277       : public nbh_iterator_base<G,
00278                                  util::edge<G>,
00279                                  util::edge<G>,
00280                                  edge_nbh_edge_bkd_iterator<G> >
00281     {
00282         typedef util::edge<G> E;
00283 
00284         typedef edge_nbh_edge_bkd_iterator<G> self_;
00285         typedef nbh_iterator_base<G, E, E, self_> super_;
00286 
00287       public:
00288 
00290         typedef E center;
00292         typedef E nbh;
00293 
00296         edge_nbh_edge_bkd_iterator();
00297         template <typename C>
00298         edge_nbh_edge_bkd_iterator(const C& c);
00300 
00301       protected:
00302         // Manipulation.
00305         bool is_valid_() const;
00307 
00309         unsigned start_id_() const;
00310 
00312         unsigned next_id_() const;
00313 
00314         void update_();
00315 
00316         friend class nbh_iterator_base<G, E, E, self_>;
00317     };
00318 
00319 # ifndef MLN_INCLUDE_ONLY
00320 
00321     /*-------------------------------`
00322     | vertex_nbh_vertex_fwd_iterator |
00323     \-------------------------------*/
00324 
00325     template <typename G>
00326     inline
00327     vertex_nbh_vertex_fwd_iterator<G>::vertex_nbh_vertex_fwd_iterator()
00328     {
00329     }
00330 
00331     template <typename G>
00332     template <typename C>
00333     inline
00334     vertex_nbh_vertex_fwd_iterator<G>::vertex_nbh_vertex_fwd_iterator(const C& c)
00335       : super_(c)
00336     {
00337     }
00338 
00339     template <typename G>
00340     inline
00341     bool
00342     vertex_nbh_vertex_fwd_iterator<G>::is_valid_() const
00343     {
00344       return this->c_->is_valid() && this->i_ < this->c_->nmax_nbh_vertices();
00345     }
00346 
00347     template <typename G>
00348     inline
00349     unsigned
00350     vertex_nbh_vertex_fwd_iterator<G>::start_id_() const
00351     {
00352       return 0;
00353     }
00354 
00355     template <typename G>
00356     inline
00357     unsigned
00358     vertex_nbh_vertex_fwd_iterator<G>::next_id_() const
00359     {
00360       return this->i_ + 1;
00361     }
00362 
00363     template <typename G>
00364     inline
00365     void
00366     vertex_nbh_vertex_fwd_iterator<G>::update_()
00367     {
00368       this->elt_.update_id(this->c_->ith_nbh_vertex(this->i_));
00369     }
00370 
00371   /*-------------------------------`
00372   | vertex_nbh_vertex_bkd_iterator |
00373   \-------------------------------*/
00374 
00375     template <typename G>
00376     inline
00377     vertex_nbh_vertex_bkd_iterator<G>::vertex_nbh_vertex_bkd_iterator()
00378     {
00379     }
00380 
00381     template <typename G>
00382     template <typename C>
00383     inline
00384     vertex_nbh_vertex_bkd_iterator<G>::vertex_nbh_vertex_bkd_iterator(const C& c)
00385       : super_(c)
00386     {
00387     }
00388 
00389     template <typename G>
00390     inline
00391     bool
00392     vertex_nbh_vertex_bkd_iterator<G>::is_valid_() const
00393     {
00394       return this->c_->is_valid() && this->i_ < this->c_->nmax_nbh_vertices();
00395     }
00396 
00397     template <typename G>
00398     inline
00399     unsigned
00400     vertex_nbh_vertex_bkd_iterator<G>::start_id_() const
00401     {
00402       return this->c_->nmax_nbh_vertices() - 1;
00403     }
00404 
00405     template <typename G>
00406     inline
00407     unsigned
00408     vertex_nbh_vertex_bkd_iterator<G>::next_id_() const
00409     {
00410       return this->i_ - 1;
00411     }
00412 
00413     template <typename G>
00414     inline
00415     void
00416     vertex_nbh_vertex_bkd_iterator<G>::update_()
00417     {
00418       this->elt_.update_id(this->c_->ith_nbh_vertex(this->i_));
00419     }
00420 
00421 
00422   /*-----------------------------`
00423   | vertex_nbh_edge_fwd_iterator |
00424   \-----------------------------*/
00425 
00426     template <typename G>
00427     inline
00428     vertex_nbh_edge_fwd_iterator<G>::vertex_nbh_edge_fwd_iterator()
00429     {
00430     }
00431 
00432     template <typename G>
00433     template <typename C>
00434     inline
00435     vertex_nbh_edge_fwd_iterator<G>::vertex_nbh_edge_fwd_iterator(const C& c)
00436       : super_(c)
00437     {
00438     }
00439 
00440     template <typename G>
00441     inline
00442     bool
00443     vertex_nbh_edge_fwd_iterator<G>::is_valid_() const
00444     {
00445       return this->c_->is_valid() && this->i_ < this->c_->nmax_nbh_edges();
00446     }
00447 
00448     template <typename G>
00449     inline
00450     unsigned
00451     vertex_nbh_edge_fwd_iterator<G>::start_id_() const
00452     {
00453       return 0;
00454     }
00455 
00456     template <typename G>
00457     inline
00458     unsigned
00459     vertex_nbh_edge_fwd_iterator<G>::next_id_() const
00460     {
00461       return this->i_ + 1;
00462     }
00463 
00464     template <typename G>
00465     inline
00466     void
00467     vertex_nbh_edge_fwd_iterator<G>::update_()
00468     {
00469       this->elt_.update_id(this->c_->ith_nbh_edge(this->i_));
00470     }
00471 
00472   /*-----------------------------`
00473   | vertex_nbh_edge_bkd_iterator |
00474   \-----------------------------*/
00475 
00476     template <typename G>
00477     inline
00478     vertex_nbh_edge_bkd_iterator<G>::vertex_nbh_edge_bkd_iterator()
00479     {
00480     }
00481 
00482     template <typename G>
00483     template <typename C>
00484     inline
00485     vertex_nbh_edge_bkd_iterator<G>::vertex_nbh_edge_bkd_iterator(const C& c)
00486       : super_(c)
00487     {
00488     }
00489 
00490     template <typename G>
00491     inline
00492     bool
00493     vertex_nbh_edge_bkd_iterator<G>::is_valid_() const
00494     {
00495       return this->c_->is_valid() && this->i_ < this->c_->nmax_nbh_edges();
00496     }
00497 
00498     template <typename G>
00499     inline
00500     unsigned
00501     vertex_nbh_edge_bkd_iterator<G>::start_id_() const
00502     {
00503       return this->c_->nmax_nbh_edges() - 1;
00504     }
00505 
00506     template <typename G>
00507     inline
00508     unsigned
00509     vertex_nbh_edge_bkd_iterator<G>::next_id_() const
00510     {
00511       return this->i_ - 1;
00512     }
00513 
00514     template <typename G>
00515     inline
00516     void
00517     vertex_nbh_edge_bkd_iterator<G>::update_()
00518     {
00519       this->elt_.update_id(this->c_->ith_nbh_edge(this->i_));
00520     }
00521 
00522 
00523 
00524   /*-----------------------------`
00525   | edge_nbh_edge_fwd_iterator |
00526   \-----------------------------*/
00527 
00528     template <typename G>
00529     inline
00530     edge_nbh_edge_fwd_iterator<G>::edge_nbh_edge_fwd_iterator()
00531     {
00532     }
00533 
00534     template <typename G>
00535     template <typename C>
00536     inline
00537     edge_nbh_edge_fwd_iterator<G>::edge_nbh_edge_fwd_iterator(const C& c)
00538       : super_(c)
00539     {
00540     }
00541 
00542     template <typename G>
00543     inline
00544     bool
00545     edge_nbh_edge_fwd_iterator<G>::is_valid_() const
00546     {
00547       return this->c_->is_valid() && this->i_ < this->c_->nmax_nbh_edges();
00548     }
00549 
00550     template <typename G>
00551     inline
00552     unsigned
00553     edge_nbh_edge_fwd_iterator<G>::start_id_() const
00554     {
00555       return 0;
00556     }
00557 
00558     template <typename G>
00559     inline
00560     unsigned
00561     edge_nbh_edge_fwd_iterator<G>::next_id_() const
00562     {
00563       return this->i_ + 1;
00564     }
00565 
00566     template <typename G>
00567     inline
00568     void
00569     edge_nbh_edge_fwd_iterator<G>::update_()
00570     {
00571       // We shall encounter the current edge in its neighborhood
00572       // since it is computed thanks to the edge neighboors of its
00573       // two vertices.
00574       // We do not want the current edge to be part of its neighbors.
00575       util::edge_id_t e_id = this->c_->ith_nbh_edge(this->i_);
00576       while (e_id == this->c_->id())
00577       {
00578         this->i_ = next_id_();
00579         e_id = this->c_->ith_nbh_edge(this->i_);
00580       }
00581 
00582       this->elt_.update_id(e_id);
00583     }
00584 
00585   /*-----------------------------`
00586   | edge_nbh_edge_bkd_iterator |
00587   \-----------------------------*/
00588 
00589     template <typename G>
00590     inline
00591     edge_nbh_edge_bkd_iterator<G>::edge_nbh_edge_bkd_iterator()
00592     {
00593     }
00594 
00595     template <typename G>
00596     template <typename C>
00597     inline
00598     edge_nbh_edge_bkd_iterator<G>::edge_nbh_edge_bkd_iterator(const C& c)
00599       : super_(c)
00600     {
00601     }
00602 
00603     template <typename G>
00604     inline
00605     bool
00606     edge_nbh_edge_bkd_iterator<G>::is_valid_() const
00607     {
00608       return this->c_->is_valid() && this->i_ < this->c_->nmax_nbh_edges();
00609     }
00610 
00611     template <typename G>
00612     inline
00613     unsigned
00614     edge_nbh_edge_bkd_iterator<G>::start_id_() const
00615     {
00616       return this->c_->nmax_nbh_edges() - 1;
00617     }
00618 
00619     template <typename G>
00620     inline
00621     unsigned
00622     edge_nbh_edge_bkd_iterator<G>::next_id_() const
00623     {
00624       return this->i_ - 1;
00625     }
00626 
00627     template <typename G>
00628     inline
00629     void
00630     edge_nbh_edge_bkd_iterator<G>::update_()
00631     {
00632       // We shall encounter vertices which are part of the
00633       // current edge.
00634       // We do not want them to be part of the edge neighbors.
00635       unsigned e_id = this->c_->ith_nbh_edge(this->i_);
00636       while (e_id == this->c_->id())
00637       {
00638         this->i_ = next_id_();
00639         e_id = this->c_->ith_nbh_edge(this->i_);
00640       }
00641 
00642       this->elt_.update_id(e_id);
00643     }
00644 
00645 # endif // !MLN_INCLUDE_ONLY
00646 
00647   } // End of namespace mln::internal
00648 
00649 } // End of namespace mln
00650 
00651 
00652 #endif // ! MLN_UTIL_INTERNAL_GRAPH_NBH_ITER_HH

Generated on Tue Oct 4 2011 15:23:50 for Milena (Olena) by  doxygen 1.7.1