$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
p_complex_piter_base.hh
1 // Copyright (C) 2008, 2009, 2013 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_INTERNAL_P_COMPLEX_PITER_BASE_HH
28 # define MLN_CORE_INTERNAL_P_COMPLEX_PITER_BASE_HH
29 
33 
34 # include <mln/core/internal/site_set_iterator_base.hh>
35 
36 /* FIXME: Rename internal::p_complex_piter_base_ to something else, as
37  it is also used for p_faces piters. Maybe
38  internal::complex_piter_base_, but it is really close to
39  internal::complex_iter_base_... */
40 
41 namespace mln
42 {
43 
44  namespace internal
45  {
46 
47  /*------------------------------------.
48  | p_complex_piter_base_<I, S, P, E>. |
49  `------------------------------------*/
50 
51  // FIXME: P could probably be deduced from S.
52 
59  template <typename I, typename S, typename P, typename E>
61  : public internal::site_set_iterator_base< S, E >
62  {
65 
67  typedef I iter;
68 
69  public:
73  p_complex_piter_base_(const S& pc);
75 
78  public:
81  bool is_valid_() const;
83  void invalidate_();
84 
86  void start_();
88  void next_();
89 
91  void change_target_(const S& pc);
93 
94  private:
96  void update_();
98 
99  protected:
101  using super_::p_;
104  };
105 
106 
108  template <typename I, typename S, typename P, typename E>
109  inline
110  std::ostream&
111  operator<<(std::ostream& ostr, const p_complex_piter_base_<I, S, P, E>& p);
112 
113 
114 
115 # ifndef MLN_INCLUDE_ONLY
116 
117  /*------------------------------------.
118  | p_complex_piter_base_<I, S, P, E>. |
119  `------------------------------------*/
120 
121  template <typename I, typename S, typename P, typename E>
122  inline
124  {
125  mln_postcondition(!this->is_valid());
126  }
127 
128  template <typename I, typename S, typename P, typename E>
129  inline
131  {
132  this->change_target(pc);
133  mln_postcondition(!this->is_valid());
134  }
135 
136  template <typename I, typename S, typename P, typename E>
137  inline
138  void
140  {
141  iter_.set_cplx(pc.cplx());
142  }
143 
144  template <typename I, typename S, typename P, typename E>
145  inline
146  bool
148  {
149  return iter_.is_valid();
150  }
151 
152  template <typename I, typename S, typename P, typename E>
153  inline
154  void
156  {
157  iter_.invalidate();
158  }
159 
160  template <typename I, typename S, typename P, typename E>
161  inline
162  void
164  {
165  iter_.start();
166  if (this->is_valid())
167  update_();
168  }
169 
170  template <typename I, typename S, typename P, typename E>
171  inline
172  void
174  {
175  iter_.next_();
176  if (this->is_valid())
177  update_();
178  }
179 
180  template <typename I, typename S, typename P, typename E>
181  inline
182  void
183  p_complex_piter_base_<I, S, P, E>::update_()
184  {
185  mln_precondition(this->is_valid());
186  // Update psite_.
187  typedef mln_psite(S) psite;
188  p_ = psite(exact(this)->site_set(), iter_);
189  }
190 
191 
192  template <typename I, typename S, typename P, typename E>
193  inline
194  std::ostream&
195  operator<<(std::ostream& ostr, const p_complex_piter_base_<I, S, P, E>& p)
196  {
197  return ostr << p.unproxy_();
198  }
199 
200 # endif // ! MLN_INCLUDE_ONLY
201 
202  } // end of mln::internal
203 
204 } // end of mln
205 
206 
207 #endif // ! MLN_CORE_INTERNAL_P_COMPLEX_PITER_BASE_HH