Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
p_graph_piter.hh
1 // Copyright (C) 2007, 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_CORE_SITE_SET_P_GRAPH_PITER_HH
27 # define MLN_CORE_SITE_SET_P_GRAPH_PITER_HH
28 
32 
33 # include <mln/core/internal/site_set_iterator_base.hh>
34 
35 
36 namespace mln
37 {
38 
39  // Forward declaration.
40  template <typename S, typename I> class graph_psite;
41  namespace util
42  {
43  template <typename G> class edge;
44  template <typename G> class vertex;
45  }
46 
47 
48 
49  /*------------------------.
50  | p_graph_piter<S,I>. |
51  `------------------------*/
52 
54  template <typename S, typename I>
56  : public internal::site_set_iterator_base< S,
57  p_graph_piter<S, I> >
58  {
59  typedef p_graph_piter<S,I> self_;
60  typedef internal::site_set_iterator_base< S, self_ > super_;
61  typedef I iter;
62 
63  public:
64 
67  p_graph_piter();
68  p_graph_piter(const S& pv);
70 
74  bool is_valid_() const;
76  void invalidate_();
77 
79  void start_();
81  void next_();
83 
85  mln_q_subject(iter) element();
86 
88  const typename S::graph_t& graph() const;
89 
91  const iter& hook_elt_() const;
92 
94  unsigned id() const;
95 
96  private:
97 
99  void update_();
100 
101  private:
102 
104  using super_::p_;
105 
107  iter iter_;
108  };
109 
110 
111  namespace internal
112  {
113 
116  template <typename S, typename I, typename E>
117  struct subject_impl< const p_graph_piter<S,I>&, E >
118  {
119  typedef typename S::graph_t graph_t;
120 
121  const graph_t& graph() const;
122  unsigned id() const;
123  util::edge<graph_t> edge_with(const util::vertex<graph_t>& v) const;
124 
125  private:
126  const E& exact_() const;
127  };
128 
129  template <typename S, typename I, typename E>
130  struct subject_impl< p_graph_piter<S,I>&, E >
131  : subject_impl< const p_graph_piter<S,I>&, E >
132  {
133  mln_q_subject(I) element();
134 
135  private:
136  E& exact_();
137  };
139 
140  } // end of namespace mln::internal
141 
142 
143 # ifndef MLN_INCLUDE_ONLY
144 
145  /*---------------------.
146  | p_graph_piter<S,I>. |
147  `---------------------*/
148 
149  template <typename S, typename I>
150  inline
152  {
153  mln_postcondition(! this->is_valid());
154  }
155 
156  template <typename S, typename I>
157  inline
159  : iter_(pv.graph())
160  {
161  this->change_target(pv);
162  mln_postcondition(! this->is_valid());
163  }
164 
165  template <typename S, typename I>
166  inline
167  bool
168  p_graph_piter<S,I>::is_valid_() const
169  {
170  return iter_.is_valid();
171  }
172 
173  template <typename S, typename I>
174  inline
175  void
176  p_graph_piter<S,I>::invalidate_()
177  {
178  iter_.invalidate();
179  }
180 
181  template <typename S, typename I>
182  inline
183  void
184  p_graph_piter<S,I>::start_()
185  {
186  iter_.start();
187  if (this->is_valid())
188  update_();
189  }
190 
191  template <typename S, typename I>
192  inline
193  void
194  p_graph_piter<S,I>::next_()
195  {
196  iter_.next();
197  if (this->is_valid())
198  update_();
199  }
200 
201  template <typename S, typename I>
202  inline
203  mln_q_subject(I)
204  p_graph_piter<S,I>::element()
205  {
206  return this->subj_();
207  }
208 
209  template <typename S, typename I>
210  inline
211  const typename S::graph_t&
213  {
214  return this->site_set().graph();
215  }
216 
217  template <typename S, typename I>
218  inline
219  const I&
221  {
222  return iter_;
223  }
224 
225  template <typename S, typename I>
226  inline
227  unsigned
229  {
230  return iter_.id();
231  }
232 
233  template <typename S, typename I>
234  inline
235  void
237  {
238  mln_precondition(this->is_valid());
239  // Update psite_.
240  p_.update_id(iter_.id());
241  }
242 
243 
244 
245  namespace internal
246  {
247 
249 
250  template <typename S, typename I, typename E>
251  inline
252  const E&
253  subject_impl< const p_graph_piter<S,I>&, E >::exact_() const
254  {
255  return internal::force_exact<const E>(*this);
256  }
257 
258  template <typename S, typename I, typename E>
259  inline
260  const typename subject_impl< const p_graph_piter<S,I>&, E >::graph_t&
261  subject_impl< const p_graph_piter<S,I>&, E >::graph() const
262  {
263  return exact_().get_subject().graph();
264  }
265 
266  template <typename S, typename I, typename E>
267  inline
268  unsigned
269  subject_impl< const p_graph_piter<S,I>&, E >::id() const
270  {
271  return exact_().get_subject().id();
272  };
273 
274  template <typename S, typename I, typename E>
275  inline
276  util::edge<typename S::graph_t>
277  subject_impl< const p_graph_piter<S,I>&, E >::edge_with(const util::vertex<graph_t>& v) const
278  {
279  return exact_().get_subject().element().edge_with(v);
280  };
281 
282  template <typename S, typename I, typename E>
283  inline
284  E&
285  subject_impl< p_graph_piter<S,I>&, E >::exact_()
286  {
287  return internal::force_exact<E>(*this);
288  }
289 
290  template <typename S, typename I, typename E>
291  inline
292  mln_q_subject(I)
293  subject_impl< p_graph_piter<S,I>&, E >::element()
294  {
295  return exact_().get_subject().element();
296  }
297 
298  } // end of namespace mln::internal
299 
300 # endif // ! MLN_INCLUDE_ONLY
301 
302 } // end of namespace mln
303 
304 
305 #endif // ! MLN_CORE_SITE_SET_P_GRAPH_PITER_HH