Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
iterator.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_CONCEPT_ITERATOR_HH
27 # define MLN_CORE_CONCEPT_ITERATOR_HH
28 
33 # include <mln/core/concept/object.hh>
34 
38 # define for_all(x) for(x.start(); x.is_valid(); x.next())
39 
40 
44 # define for_all_2(x1, x2) \
45  for(x1.start(), x2.start(); \
46  x1.is_valid(); \
47  x1.next(), x2.next())
48 
49 
53 # define for_all_3(x1, x2, x3) \
54  for(x1.start(), x2.start(), x3.start(); \
55  x1.is_valid(); \
56  x1.next(), x2.next(), x3.next())
57 
58 
62 # define for_all_remaining(x) \
63  if (! x.is_valid()) {} else while (x.next(), x.is_valid())
64 
65 
66 
67 namespace mln
68 {
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  m1 = 0;
114  void (E::*m2)() = & E::invalidate;
115  m2 = 0;
116  void (E::*m3)() = & E::start;
117  m3 = 0;
118  void (E::*m4)() = & E::next_;
119  m4 = 0;
120  }
121 
122 # endif // ! MLN_INCLUDE_ONLY
123 
124 
125 } // end of namespace mln
126 
127 
128 #endif // ! MLN_CORE_CONCEPT_ITERATOR_HH