Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
graph_iter.hh
1 // Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef MLN_UTIL_INTERNAL_GRAPH_ITER_HH
27 # define MLN_UTIL_INTERNAL_GRAPH_ITER_HH
28 
32 
33 # include <mln/util/internal/graph_iter_base.hh>
34 # include <mln/util/vertex.hh>
35 # include <mln/util/edge.hh>
36 
37 
38 
39 namespace mln
40 {
41 
42  namespace internal
43  {
44 
46 
47  template<typename G>
48  class vertex_fwd_iterator
49  : public graph_iter_base<G, util::vertex<G>, vertex_fwd_iterator<G> >
50  {
51  typedef graph_iter_base<G, util::vertex<G>, vertex_fwd_iterator<G> > super_;
52 
53  public:
56  vertex_fwd_iterator();
57  vertex_fwd_iterator(const G& g);
59 
60  protected:
63  util::vertex_id_t start_id_() const;
64 
67  util::vertex_id_t next_id_() const;
68 
69  friend class graph_iter_base<G, util::vertex<G>, vertex_fwd_iterator<G> >;
70  };
71 
72 
74 
75  template<typename G>
76  class vertex_bkd_iterator
77  : public graph_iter_base<G, util::vertex<G>, vertex_bkd_iterator<G> >
78  {
79  typedef graph_iter_base<G, util::vertex<G>, vertex_bkd_iterator<G> > super_;
80 
81  public:
84  vertex_bkd_iterator();
85  vertex_bkd_iterator(const G& g);
87 
88  protected:
91  util::vertex_id_t start_id_() const;
92 
95  util::vertex_id_t next_id_() const;
96 
97  friend class graph_iter_base<G, util::vertex<G>, vertex_bkd_iterator<G> >;
98  };
99 
100 
102 
103  template <typename G>
104  class edge_fwd_iterator
105  : public graph_iter_base<G, util::edge<G>, edge_fwd_iterator<G> >
106  {
107  typedef graph_iter_base<G, util::edge<G>, edge_fwd_iterator<G> > super_;
108 
109  public:
112  edge_fwd_iterator();
113  edge_fwd_iterator(const G& g);
115 
116  protected:
119  util::edge_id_t start_id_() const;
120 
123  util::edge_id_t next_id_() const;
124 
125  friend class graph_iter_base<G, util::edge<G>, edge_fwd_iterator<G> >;
126  };
127 
128 
130 
131  template <typename G>
132  class edge_bkd_iterator
133  : public graph_iter_base<G, util::edge<G>, edge_bkd_iterator<G> >
134  {
135  typedef graph_iter_base<G, util::edge<G>, edge_bkd_iterator<G> > super_;
136 
137  public:
140  edge_bkd_iterator();
141  edge_bkd_iterator(const G& g);
143 
144  protected:
147  util::edge_id_t start_id_() const;
148 
151  util::edge_id_t next_id_() const;
152 
153  friend class graph_iter_base<G, util::edge<G>, edge_bkd_iterator<G> >;
154  };
155 
156 
157 
158 
159 # ifndef MLN_INCLUDE_ONLY
160 
161 
162  /*--------------------`
163  | vertex_fwd_iterator |
164  \--------------------*/
165 
166  template <typename G>
167  inline
168  vertex_fwd_iterator<G>::vertex_fwd_iterator()
169  {
170  }
171 
172  template <typename G>
173  inline
174  vertex_fwd_iterator<G>::vertex_fwd_iterator(const G& g)
175  : super_(g)
176  {
177  }
178 
179  template <typename G>
180  inline
182  vertex_fwd_iterator<G>::start_id_() const
183  {
184  return 0;
185  }
186 
187  template <typename G>
188  inline
190  vertex_fwd_iterator<G>::next_id_() const
191  {
192  return this->p_.id().value() + 1;
193  }
194 
195 
196 
197  /*--------------------`
198  | vertex_bkd_iterator |
199  \--------------------*/
200 
201  template <typename G>
202  inline
203  vertex_bkd_iterator<G>::vertex_bkd_iterator()
204  {
205  }
206 
207  template <typename G>
208  inline
209  vertex_bkd_iterator<G>::vertex_bkd_iterator(const G& g)
210  : super_(g)
211  {
212  }
213 
214  template <typename G>
215  inline
217  vertex_bkd_iterator<G>::start_id_() const
218  {
219  return this->p_.graph().v_nmax() - 1;
220  }
221 
222  template <typename G>
223  inline
225  vertex_bkd_iterator<G>::next_id_() const
226  {
227  return this->p_.id().value() - 1;
228  }
229 
230 
231 
232  /*------------------`
233  | edge_fwd_iterator |
234  \------------------*/
235 
236  template <typename G>
237  inline
238  edge_fwd_iterator<G>::edge_fwd_iterator()
239  {
240  }
241 
242  template <typename G>
243  inline
244  edge_fwd_iterator<G>::edge_fwd_iterator(const G& g)
245  : super_(g)
246  {
247  }
248 
249  template <typename G>
250  inline
251  util::edge_id_t
252  edge_fwd_iterator<G>::start_id_() const
253  {
254  return 0;
255  }
256 
257  template <typename G>
258  inline
259  util::edge_id_t
260  edge_fwd_iterator<G>::next_id_() const
261  {
262  return this->p_.id().value() + 1;
263  }
264 
265 
266 
267  /*------------------`
268  | edge_bkd_iterator |
269  \------------------*/
270 
271  template <typename G>
272  inline
273  edge_bkd_iterator<G>::edge_bkd_iterator()
274  {
275  }
276 
277  template <typename G>
278  inline
279  edge_bkd_iterator<G>::edge_bkd_iterator(const G& g)
280  : super_(g)
281  {
282  }
283 
284  template <typename G>
285  inline
286  util::edge_id_t
287  edge_bkd_iterator<G>::start_id_() const
288  {
289  return this->p_.graph().e_nmax() - 1;
290  }
291 
292  template <typename G>
293  inline
294  util::edge_id_t
295  edge_bkd_iterator<G>::next_id_() const
296  {
297  return this->p_.id().value() - 1;
298  }
299 
300 # endif // ! MLN_INCLUDE_ONLY
301 
302  } // end of namespace mln::internal
303 
304 } // end of namespace mln
305 
306 
307 #endif // ! MLN_UTIL_INTERNAL_GRAPH_ITER_HH