$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
iterator.hh
1 // Copyright (C) 2007, 2008, 2009, 2011, 2013 EPITA Research and
2 // Development 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_CONCEPT_ITERATOR_HH
28 # define MLN_CORE_CONCEPT_ITERATOR_HH
29 
34 # include <mln/core/concept/object.hh>
35 
39 # define for_all(x) for(x.start(); x.is_valid(); x.next())
40 
41 
45 # define for_all_2(x1, x2) \
46  for(x1.start(), x2.start(); \
47  x1.is_valid(); \
48  x1.next(), x2.next())
49 
50 
54 # define for_all_3(x1, x2, x3) \
55  for(x1.start(), x2.start(), x3.start(); \
56  x1.is_valid(); \
57  x1.next(), x2.next(), x3.next())
58 
59 
63 # define for_all_remaining(x) \
64  if (! x.is_valid()) {} else while (x.next(), x.is_valid())
65 
66 
67 
68 namespace mln
69 {
74  template <typename E>
75  struct Iterator : public Object<E>
76  {
77  /*
78  bool is_valid() const;
79  void invalidate();
80  void start();
81  void next_();
82  */
83 
92  void next(); // final
93 
94  protected:
95  Iterator();
96  };
97 
98 
99 # ifndef MLN_INCLUDE_ONLY
100 
101  template <typename E>
102  void Iterator<E>::next() // final
103  {
104  assert(exact(this)->is_valid());
105  exact(this)->next_();
106  }
107 
108  template <typename E>
109  inline
111  {
112  bool (E::*m1)() const = & E::is_valid;
113  (void) m1;
114  void (E::*m2)() = & E::invalidate;
115  (void) m2;
116  void (E::*m3)() = & E::start;
117  (void) m3;
118  void (E::*m4)() = & E::next_;
119  (void) m4;
120  }
121 
122 # endif // ! MLN_INCLUDE_ONLY
123 
124 
125 } // end of namespace mln
126 
127 
128 #endif // ! MLN_CORE_CONCEPT_ITERATOR_HH