Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
box_runstart_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_BOX_RUNSTART_PITER_HH
27 # define MLN_CORE_BOX_RUNSTART_PITER_HH
28 
32 
33 # include <mln/core/internal/site_iterator_base.hh>
34 # include <mln/core/site_set/box.hh>
35 
36 
37 #define mln_box_runstart_piter(I) typename mln::box_runstart_piter<mln_psite(I)>
38 #define mln_box_runstart_piter_(I) mln::box_runstart_piter<mln_psite_(I)>
39 
40 
41 namespace mln
42 {
43 
48  template <typename P>
50  public internal::site_set_iterator_base< box<P>,
51  box_runstart_piter<P> >
52  {
54  typedef internal::site_set_iterator_base< box<P>, self_ > super_;
55  public:
56 
57  // Make definitions from super class available.
58  enum { dim = super_::dim };
59 
64  box_runstart_piter(const box<P>& b);
65 
67  void init_(const box<P>& b);
68 
70 
72  bool is_valid_() const;
73 
75  void invalidate_();
76 
78  void start_();
79 
81  void next_();
82 
84  unsigned run_length() const;
85 
86  private:
87  using super_::p_;
88  using super_::s_;
89  };
90 
91 
92 # ifndef MLN_INCLUDE_ONLY
93 
94 
95  // box_runstart_piter<P>
96 
97  template <typename P>
98  inline
100  {
101  }
102 
103  template <typename P>
104  inline
106  {
107  init_(b);
108  }
109 
110  template <typename P>
111  inline
112  void
114  {
115  this->change_target(b);
116  }
117 
118 
119  template <typename P>
120  inline
121  bool
122  box_runstart_piter<P>::is_valid_() const
123  {
124  return p_[0] != static_cast<mln_coord(P)>(s_->pmax()[0] + 1);
125  }
126 
127  template <typename P>
128  inline
129  void
130  box_runstart_piter<P>::invalidate_()
131  {
132  p_[0] = static_cast<mln_coord(P)>(s_->pmax()[0] + 1);
133  }
134 
135  template <typename P>
136  inline
137  void
138  box_runstart_piter<P>::start_()
139  {
140  p_ = s_->pmin();
141  }
142 
143  template <typename P>
144  inline
145  void
146  box_runstart_piter<P>::next_()
147  {
148  // Do we want this run for image in 3d?
149  /* FIXME: `dim - 2' is probably the wrong (= not generic) way to
150  express the manipulated dimension anyway. */
151  for (int c = dim - 2; c >= 0; --c)
152  {
153  if (p_[c] != s_->pmax()[c])
154  {
155  ++p_[c];
156  break;
157  }
158  else
159  p_[c] = s_->pmin()[c];
160  }
161 
162  if (p_ == s_->pmin())
163  invalidate_();
164  }
165 
166  template <typename P>
167  inline
168  unsigned
170  {
171  return s_->len(dim - 1);
172  }
173 
174 
175 # endif // ! MLN_INCLUDE_ONLY
176 
177 } // end of namespace mln
178 
179 
180 #endif // ! MLN_CORE_BOX_RUNSTART_PITER_HH