Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
box_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_BOX_PITER_HH
27 # define MLN_CORE_SITE_SET_BOX_PITER_HH
28 
32 
33 # include <mln/core/internal/site_set_iterator_base.hh>
34 # include <mln/core/concept/box.hh>
35 # include <mln/core/site_set/box.hh>
36 
37 
38 namespace mln
39 {
40 
47  template <typename P>
48  class box_fwd_piter_ : public internal::site_set_iterator_base< box<P>,
49  box_fwd_piter_<P> >
50  {
51  typedef box_fwd_piter_<P> self_;
52  typedef internal::site_set_iterator_base< box<P>, self_ > super_;
53 
54  public:
55 
56  // Make definitions from super class available.
57  enum { dim = P::dim };
58 
60  box_fwd_piter_();
61 
66  box_fwd_piter_(const mln::box<P>& b);
67 
69  bool is_valid_() const;
70 
72  void invalidate_();
73 
75  void start_();
76 
78  void next_();
79 
80  protected:
81  using super_::p_;
82  using super_::s_;
83  };
84 
85 
86 
93  template <typename P>
94  class box_bkd_piter_ : public internal::site_set_iterator_base< box<P>,
95  box_bkd_piter_<P> >
96  {
97  typedef box_bkd_piter_<P> self_;
98  typedef internal::site_set_iterator_base< box<P>, self_ > super_;
99 
100  public:
101 
102  // Make definitions from super class available.
103  enum { dim = P::dim };
104 
106  box_bkd_piter_();
107 
112  box_bkd_piter_(const box<P>& b);
113 
115  bool is_valid_() const;
116 
118  void invalidate_();
119 
121  void start_();
122 
124  void next_();
125 
126  protected:
127  using super_::p_;
128  using super_::s_;
129  };
130 
131 
132 
133 
134 # ifndef MLN_INCLUDE_ONLY
135 
136 
137  // box_fwd_piter_<P>
138 
139  template <typename P>
140  inline
141  box_fwd_piter_<P>::box_fwd_piter_()
142  {
143  }
144 
145  template <typename P>
146  inline
147  box_fwd_piter_<P>::box_fwd_piter_(const mln::box<P>& b)
148  {
149  this->change_target(b);
150  }
151 
152  template <typename P>
153  inline
154  bool
155  box_fwd_piter_<P>::is_valid_() const
156  {
157  return p_[0] != s_->pmax()[0] + 1;
158  }
159 
160  template <typename P>
161  inline
162  void
163  box_fwd_piter_<P>::invalidate_()
164  {
165  p_[0] = static_cast<def::coord>(s_->pmax()[0] + 1);
166  }
167 
168  template <typename P>
169  inline
170  void
171  box_fwd_piter_<P>::start_()
172  {
173  p_ = s_->pmin();
174  }
175 
176  template <typename P>
177  inline
178  void
179  box_fwd_piter_<P>::next_()
180  {
181  for (int i = dim - 1; i >= 0; --i)
182  if (p_[i] != s_->pmax()[i])
183  {
184  ++p_[i];
185  break;
186  }
187  else
188  {
189  p_[i] = s_->pmin()[i];
190  if (i == 0)
191  invalidate_();
192  }
193 
194  // memo
195 
196 // for (int i = dim - 1; i >= 0; --i)
197 // if (p_[i] != s_->pmax()[i])
198 // {
199 // ++p_[i];
200 // break;
201 // }
202 // else
203 // p_[i] = s_->pmin()[i];
204 // if (p_ == s_->pmin())
205 // invalidate_();
206  }
207 
208 
209  // box_bkd_piter_<P>
210 
211  template <typename P>
212  inline
213  box_bkd_piter_<P>::box_bkd_piter_()
214  {
215  }
216 
217  template <typename P>
218  inline
219  box_bkd_piter_<P>::box_bkd_piter_(const box<P>& b)
220  {
221  this->change_target(b);
222  }
223 
224  template <typename P>
225  inline
226  bool
227  box_bkd_piter_<P>::is_valid_() const
228  {
229  return p_[0] != s_->pmin()[0] - 1;
230  }
231 
232  template <typename P>
233  inline
234  void
235  box_bkd_piter_<P>::invalidate_()
236  {
237  p_[0] = mln_coord(P)(s_->pmin()[0] - 1);
238  }
239 
240  template <typename P>
241  inline
242  void
243  box_bkd_piter_<P>::start_()
244  {
245  p_ = s_->pmax();
246  }
247 
248  template <typename P>
249  inline
250  void
251  box_bkd_piter_<P>::next_()
252  {
253  for (int i = dim - 1; i >= 0; --i)
254  if (p_[i] == s_->pmin()[i])
255  p_[i] = s_->pmax()[i];
256  else
257  {
258  --p_[i];
259  break;
260  }
261  if (p_ == s_->pmax())
262  invalidate_();
263  }
264 
265 # endif // ! MLN_INCLUDE_ONLY
266 
267 } // end of namespace mln
268 
269 
270 #endif // ! MLN_CORE_SITE_SET_BOX_PITER_HH