$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
p_graph_piter.hh
1 // Copyright (C) 2007, 2008, 2009, 2012, 2013 EPITA Research and
2 // Development Laboratory (LRDE)
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #ifndef MLN_CORE_SITE_SET_P_GRAPH_PITER_HH
28 # define MLN_CORE_SITE_SET_P_GRAPH_PITER_HH
29 
33 
34 # include <mln/core/internal/site_set_iterator_base.hh>
35 
36 
37 namespace mln
38 {
39 
40  // Forward declaration.
41  template <typename S, typename I> class graph_psite;
42  namespace util
43  {
44  template <typename G> class edge;
45  template <typename G> class vertex;
46  }
47 
48 
49 
50  /*---------------------.
51  | p_graph_piter<S,I>. |
52  `---------------------*/
53 
58  template <typename S, typename I>
61  p_graph_piter<S, I> >
62  {
63  typedef p_graph_piter<S,I> self_;
65  typedef I iter;
66 
67  public:
68 
71  p_graph_piter();
72  p_graph_piter(const S& pv);
74 
79  bool is_valid_() const;
81  void invalidate_();
82 
84  void start_();
86  void next_();
89 
91  mln_q_subject(iter) element();
92 
94  const typename S::graph_t& graph() const;
95 
98  const iter& hook_elt_() const;
100 
102  unsigned id() const;
103 
104  private:
105 
107  void update_();
108 
109  private:
110 
112  using super_::p_;
113 
115  iter iter_;
116  };
117 
118 
119  namespace internal
120  {
121 
123 
126  template <typename S, typename I, typename E>
127  struct subject_impl< const p_graph_piter<S,I>&, E >
128  {
129  typedef typename S::graph_t graph_t;
130 
131  const graph_t& graph() const;
132  unsigned id() const;
133  util::edge<graph_t> edge_with(const util::vertex<graph_t>& v) const;
134 
135  private:
136  const E& exact_() const;
137  };
138 
139  template <typename S, typename I, typename E>
140  struct subject_impl< p_graph_piter<S,I>&, E >
142  {
143  mln_q_subject(I) element();
144 
145  private:
146  E& exact_();
147  };
149 
150  } // end of namespace mln::internal
151 
152 
153 # ifndef MLN_INCLUDE_ONLY
154 
155  /*---------------------.
156  | p_graph_piter<S,I>. |
157  `---------------------*/
158 
159  template <typename S, typename I>
160  inline
161  p_graph_piter<S,I>::p_graph_piter()
162  {
163  mln_postcondition(! this->is_valid());
164  }
165 
166  template <typename S, typename I>
167  inline
168  p_graph_piter<S,I>::p_graph_piter(const S& pv)
169  : iter_(pv.graph())
170  {
171  this->change_target(pv);
172  mln_postcondition(! this->is_valid());
173  }
174 
175  template <typename S, typename I>
176  inline
177  bool
179  {
180  return iter_.is_valid();
181  }
182 
183  template <typename S, typename I>
184  inline
185  void
187  {
188  iter_.invalidate();
189  }
190 
191  template <typename S, typename I>
192  inline
193  void
195  {
196  iter_.start();
197  if (this->is_valid())
198  update_();
199  }
200 
201  template <typename S, typename I>
202  inline
203  void
205  {
206  iter_.next();
207  if (this->is_valid())
208  update_();
209  }
210 
211  template <typename S, typename I>
212  inline
213  mln_q_subject(I)
214  p_graph_piter<S,I>::element()
215  {
216  return this->subj_();
217  }
218 
219  template <typename S, typename I>
220  inline
221  const typename S::graph_t&
223  {
224  return this->site_set().graph();
225  }
226 
227  template <typename S, typename I>
228  inline
229  const I&
231  {
232  return iter_;
233  }
234 
235  template <typename S, typename I>
236  inline
237  unsigned
238  p_graph_piter<S,I>::id() const
239  {
240  return iter_.id();
241  }
242 
243  template <typename S, typename I>
244  inline
245  void
246  p_graph_piter<S,I>::update_()
247  {
248  mln_precondition(this->is_valid());
249  // Update psite_.
250  p_.update_id(iter_.id());
251  }
252 
253 
254 
255  namespace internal
256  {
257 
259 
260  template <typename S, typename I, typename E>
261  inline
262  const E&
263  subject_impl< const p_graph_piter<S,I>&, E >::exact_() const
264  {
265  return internal::force_exact<const E>(*this);
266  }
267 
268  template <typename S, typename I, typename E>
269  inline
270  const typename subject_impl< const p_graph_piter<S,I>&, E >::graph_t&
271  subject_impl< const p_graph_piter<S,I>&, E >::graph() const
272  {
273  return exact_().get_subject().graph();
274  }
275 
276  template <typename S, typename I, typename E>
277  inline
278  unsigned
280  {
281  return exact_().get_subject().id();
282  };
283 
284  template <typename S, typename I, typename E>
285  inline
286  util::edge<typename S::graph_t>
287  subject_impl< const p_graph_piter<S,I>&, E >::edge_with(const util::vertex<graph_t>& v) const
288  {
289  return exact_().get_subject().element().edge_with(v);
290  };
291 
292  template <typename S, typename I, typename E>
293  inline
294  E&
295  subject_impl< p_graph_piter<S,I>&, E >::exact_()
296  {
297  return internal::force_exact<E>(*this);
298  }
299 
300  template <typename S, typename I, typename E>
301  inline
302  mln_q_subject(I)
303  subject_impl< p_graph_piter<S,I>&, E >::element()
304  {
305  return exact_().get_subject().element();
306  }
307 
308  } // end of namespace mln::internal
309 
310 # endif // ! MLN_INCLUDE_ONLY
311 
312 } // end of namespace mln
313 
314 
315 #endif // ! MLN_CORE_SITE_SET_P_GRAPH_PITER_HH