Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
dpsites_piter.hh
1 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development
2 // 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_DPSITES_PITER_HH
28 # define MLN_CORE_DPSITES_PITER_HH
29 
34 
35 # include <vector>
36 # include <mln/core/internal/site_relative_iterator_base.hh>
37 
38 
39 namespace mln
40 {
41 
47  template <typename V>
49  : public internal::site_relative_iterator_base< V, dpsites_fwd_piter<V> >
50  {
51  public:
52 
57  template <typename P>
58  dpsites_fwd_piter(const V& v, const P& c);
59 
61  template <typename P>
62  void init_(const V& v, const P& c);
63 
66 
68  bool is_valid_() const;
69 
71  void invalidate_();
72 
74  void do_start_();
75 
77  void do_next_();
78 
80  mln_psite(V) compute_p_() const;
81 
82  protected:
83 
84  unsigned i_;
85  };
86 
87 
93  template <typename V>
95  public internal::site_relative_iterator_base< V, dpsites_bkd_piter<V> >
96  {
97  public:
98 
103  template <typename P>
104  dpsites_bkd_piter(const V& v, const P& c);
105 
108 
110  template <typename P>
111  void init_(const V& v, const P& c);
112 
114  bool is_valid_() const;
115 
117  void invalidate_();
118 
120  void do_start_();
121 
123  void do_next_();
124 
126  mln_psite(V) compute_p_() const;
127 
128  protected:
129 
130  int i_;
131  };
132 
133 
134 
135 # ifndef MLN_INCLUDE_ONLY
136 
137 
138  // Forward.
139 
140  template <typename V>
141  inline
143  {
144  }
145 
146  template <typename V>
147  template <typename P>
148  inline
150  {
151  init_(v, c);
152  }
153 
154  template <typename V>
155  template <typename P>
156  inline
157  void
158  dpsites_fwd_piter<V>::init_(const V& v, const P& c)
159  {
160  this->change_target(v);
161  this->center_at(c);
162  }
163 
164 
165  template <typename V>
166  inline
167  bool
168  dpsites_fwd_piter<V>::is_valid_() const
169  {
170  return i_ != this->s_->std_vector().size();
171  }
172 
173  template <typename V>
174  inline
175  void
176  dpsites_fwd_piter<V>::invalidate_()
177  {
178  i_ = this->s_->std_vector().size();
179  }
180 
181  template <typename V>
182  inline
183  void
184  dpsites_fwd_piter<V>::do_start_()
185  {
186  i_ = 0;
187  }
188 
189  template <typename V>
190  inline
191  void
192  dpsites_fwd_piter<V>::do_next_()
193  {
194  ++i_;
195  }
196 
197  template <typename V>
198  inline
199  mln_psite(V)
200  dpsites_fwd_piter<V>::compute_p_() const
201  {
202  return *this->c_ + this->s_->std_vector()[i_];
203  }
204 
205 
206  // Backward.
207 
208  template <typename V>
209  inline
211  {
212  }
213 
214  template <typename V>
215  template <typename P>
216  inline
218  {
219  init_(v, c);
220  }
221 
222  template <typename V>
223  template <typename P>
224  inline
225  void
226  dpsites_bkd_piter<V>::init_(const V& v, const P& c)
227  {
228  this->change_target(v);
229  this->center_at(c);
230  }
231 
232 
233  template <typename V>
234  inline
235  bool
236  dpsites_bkd_piter<V>::is_valid_() const
237  {
238  return i_ != -1;
239  }
240 
241  template <typename V>
242  inline
243  void
244  dpsites_bkd_piter<V>::invalidate_()
245  {
246  i_ = -1;
247  }
248 
249  template <typename V>
250  inline
251  void
252  dpsites_bkd_piter<V>::do_start_()
253  {
254  i_ = this->s_->std_vector().size() - 1;
255  }
256 
257  template <typename V>
258  inline
259  void
260  dpsites_bkd_piter<V>::do_next_()
261  {
262  --i_;
263  }
264 
265  template <typename V>
266  inline
267  mln_psite(V)
268  dpsites_bkd_piter<V>::compute_p_() const
269  {
270  return *this->c_ + this->s_->std_vector()[i_];
271  }
272 
273 # endif // ! MLN_INCLUDE_ONLY
274 
275 } // end of namespace mln
276 
277 
278 #endif // ! MLN_CORE_DPSITES_PITER_HH