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