$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
complex_relative_iterator_sequence.hh
1 // Copyright (C) 2008, 2009, 2012 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_TOPO_INTERNAL_COMPLEX_RELATIVE_ITERATOR_SEQUENCE_HH
28 # define MLN_TOPO_INTERNAL_COMPLEX_RELATIVE_ITERATOR_SEQUENCE_HH
29 
34 
35 # include <iosfwd>
36 
37 # include <mln/metal/equal.hh>
38 
39 # include <mln/core/concept/iterator.hh>
40 # include <mln/topo/complex.hh>
41 
42 
43 namespace mln
44 {
45 
46  namespace topo
47  {
48 
49  namespace internal
50  {
51 
52  template <typename I1>
54  {
55  typedef typename I1::face_type F_;
56  typedef const F_& ret;
57  };
58 
59 
72  template <typename I1, typename I2, typename E>
74  {
76 
77  public:
79  typedef typename I1::center_type center_type;
81  typedef typename I1::face_type face_type;
82 
86  template <typename Fref>
87  complex_relative_iterator_sequence(const Fref& f_ref);
89 
93  void center_at(const center_type& c);
94 
96  bool is_valid() const;
98  void invalidate();
99 
101  void start();
103  void next_();
105 
109  operator typename const_face_type_<I1>::ret () const;
110  // that is: const face_type&
112 
113  protected:
115  void update_();
116 
117  protected:
119  I1 iter1_;
121  I2 iter2_;
122 
125  };
126 
127 
129  template <typename I1, typename I2, typename E>
130  inline
131  std::ostream&
132  operator<<(std::ostream& ostr,
134 
135 
136 
137 # ifndef MLN_INCLUDE_ONLY
138 
139  template <typename I1, typename I2, typename E>
140  inline
142  {
143  // Ensure I1 and I2 are compatible.
144  mlc_equal(typename I1::face_type, typename I2::face_type)::check();
145 
146  invalidate();
147  }
148 
149  template <typename I1, typename I2, typename E>
150  template <typename Fref>
151  inline
153  {
154  // Ensure I1 and I2 are compatible.
155  mlc_equal(typename I1::face_type, typename I2::face_type)::check();
156 
157  center_at(f_ref);
158  }
159 
160  template <typename I1, typename I2, typename E>
161  inline
162  void
164  {
165  iter1_.center_at(c);
166  iter2_.center_at(c);
167  invalidate();
168  }
169 
170  template <typename I1, typename I2, typename E>
171  inline
172  bool
174  {
175  return iter1_.is_valid() || iter2_.is_valid();
176  }
177 
178  template <typename I1, typename I2, typename E>
179  inline
180  void
182  {
183  iter1_.invalidate();
184  iter2_.invalidate();
185  }
186 
187  template <typename I1, typename I2, typename E>
188  inline
189  void
191  {
192  iter1_.start();
193  iter2_.start();
194  if (is_valid())
195  update_();
196  }
197 
198  template <typename I1, typename I2, typename E>
199  inline
200  void
202  {
203  /* Iterator<E>::next() ensures that either iter1_ or iter2_
204  (or both) are valid before executing this method. */
205  if (iter1_.is_valid())
206  iter1_.next();
207  else
208  iter2_.next();
209  if (is_valid())
210  update_();
211  }
212 
213  template <typename I1, typename I2, typename E>
214  inline
215  void
217  {
218  mln_precondition(is_valid());
219  if (iter1_.is_valid())
220  f_ = iter1_;
221  else
222  f_ = iter2_;
223  }
224 
225  template <typename I1, typename I2, typename E>
226  inline
227  complex_relative_iterator_sequence<I1, I2, E>::operator typename const_face_type_<I1>::ret () const
228  {
229  return f_;
230  }
231 
232 
233  template <typename I1, typename I2, typename E>
234  inline
235  std::ostream&
236  operator<<(std::ostream& ostr,
237  const complex_relative_iterator_sequence<I1, I2, E>& p)
238  {
239  return ostr << typename I1::face_type(p);
240  }
241 
242 # endif // ! MLN_INCLUDE_ONLY
243 
244  } // end of namespace mln::topo::internal
245 
246  } // end of namespace mln::topo
247 
248 } // end of namespace mln
249 
250 #endif // ! MLN_TOPO_INTERNAL_COMPLEX_RELATIVE_ITERATOR_SEQUENCE_HH