Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
site_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_SITE_ITERATOR_HH
27 # define MLN_CORE_CONCEPT_SITE_ITERATOR_HH
28 
34 
35 
36 # include <mln/core/concept/site_proxy.hh>
37 # include <mln/core/concept/iterator.hh> // To fetch the macros.
38 
39 
40 namespace mln
41 {
42 
52  template <typename E>
53  struct Site_Iterator : public Site_Proxy<E>
54  {
55  /*
56  bool is_valid_() const;
57  void invalidate_();
58  void start_();
59  void next_();
60  const ..& target_() const;
61  */
62 
71  void next(); // final
72 
73  // FIXME: Doc!!!
74  bool is_valid() const;
75  void invalidate();
76  void start();
77 
78  // Defined in site_iterator_base:
79  // void change_target(s);
80 
81  protected:
82  Site_Iterator();
83  };
84 
85 
86 
87 # ifndef MLN_INCLUDE_ONLY
88 
89  template <typename E>
90  inline
91  void
93  {
94  mln_precondition(is_valid());
95  exact(this)->next_();
96  }
97 
98  template <typename E>
99  inline
100  bool
102  {
103  E *const this_ = const_cast<E*const>(exact(this)); // Unconst.
104  if (this_->target_() == 0)
105  return false;
106  return exact(this)->is_valid_();
107  }
108 
109  template <typename E>
110  inline
111  void
112  Site_Iterator<E>::invalidate()
113  {
114  if (exact(this)->target_() == 0)
115  return; // No-op.
116  exact(this)->invalidate_();
117  mln_postcondition(is_valid() == false);
118  }
119 
120  template <typename E>
121  inline
122  void
123  Site_Iterator<E>::start()
124  {
125  mln_precondition(exact(this)->target_() != 0);
126  exact(this)->start_();
127  }
128 
129  template <typename E>
130  inline
131  Site_Iterator<E>::Site_Iterator()
132  {
133  bool m0 = (& E::target_) == (& E::target_); // FIXME: Find a better test.
134  m0 = 0;
135  bool (E::*m1)() const = & E::is_valid_;
136  m1 = 0;
137  void (E::*m2)() = & E::invalidate_;
138  m2 = 0;
139  void (E::*m3)() = & E::start_;
140  m3 = 0;
141  void (E::*m4)() = & E::next_;
142  m4 = 0;
143  bool m5 = (& E::change_target) == (& E::change_target);
144  m5 = 0;
145  }
146 
147 # endif // ! MLN_INCLUDE_ONLY
148 
149 } // end of namespace mln
150 
151 
152 #endif // ! MLN_CORE_CONCEPT_SITE_ITERATOR_HH