$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
graph_iter_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_UTIL_INTERNAL_GRAPH_ITER_BASE_HH
27 # define MLN_UTIL_INTERNAL_GRAPH_ITER_BASE_HH
28 
35 
36 # include <mln/core/concept/iterator.hh>
37 # include <mln/core/concept/proxy.hh>
38 
39 
40 namespace mln
41 {
42 
43  namespace internal
44  {
45 
46  template <typename G, typename Elt, typename E>
48  : public Proxy< E >,
49  public internal::proxy_impl< const Elt&, E >
50  {
51  public:
55  bool is_valid() const;
57  void invalidate();
58 
60  void start();
61 
63  void next();
64 
66  typename Elt::id_t id() const;
67 
69  operator typename Elt::id_t() const;
70 
73  operator typename Elt::id_value_t() const;
74 
76  operator const Elt&() const;
78 
80  const Elt& subj_();
81 
83  const Elt& p_hook_() const;
84 
85  protected:
86  graph_iter_base(const G& g);
87 
88  Elt p_;
89  };
90 
91 
92 
93 # ifndef MLN_INCLUDE_ONLY
94 
95  template <typename G, typename Elt, typename E>
96  inline
98  : p_(Elt(g))
99  {
100  invalidate();
101  }
102 
103  template <typename G, typename Elt, typename E>
104  inline
105  bool
106  graph_iter_base<G, Elt, E>::is_valid() const
107  {
108  return p_.is_valid();
109  }
110 
111  template <typename G, typename Elt, typename E>
112  inline
113  void
114  graph_iter_base<G, Elt, E>::invalidate()
115  {
116  p_.invalidate();
117  mln_postcondition(! is_valid());
118  }
119 
120  template <typename G, typename Elt, typename E>
121  inline
122  void
123  graph_iter_base<G, Elt, E>::start()
124  {
125  p_.update_id(exact(this)->start_id_());
126  }
127 
128  template <typename G, typename Elt, typename E>
129  inline
130  void
131  graph_iter_base<G, Elt, E>::next()
132  {
133  mln_precondition(is_valid());
134  p_.update_id(exact(this)->next_id_());
135  }
136 
137  template <typename G, typename Elt, typename E>
138  inline
139  typename Elt::id_t
140  graph_iter_base<G, Elt, E>::id() const
141  {
142  return p_.id();
143  }
144 
145  template <typename G, typename Elt, typename E>
146  inline
147  graph_iter_base<G, Elt, E>::operator typename Elt::id_t() const
148  {
149  return p_.id();
150  }
151 
152  template <typename G, typename Elt, typename E>
153  inline
154  graph_iter_base<G, Elt, E>::operator typename Elt::id_value_t() const
155  {
156  return p_.id();
157  }
158 
159  template <typename G, typename Elt, typename E>
160  inline
161  graph_iter_base<G, Elt, E>::operator const Elt&() const
162  {
163  return p_;
164  }
165 
166  template <typename G, typename Elt, typename E>
167  inline
168  const Elt&
169  graph_iter_base<G, Elt, E>::subj_()
170  {
171  return p_;
172  }
173 
174  template <typename G, typename Elt, typename E>
175  inline
176  const Elt&
177  graph_iter_base<G, Elt, E>::p_hook_() const
178  {
179  return p_;
180  }
181 
182 # endif // ! MLN_INCLUDE_ONLY
183 
184  } // end of namespace mln::internal
185 
186 } // end of namespace mln
187 
188 #endif // ! MLN_UTIL_INTERNAL_GRAPH_ITER_BASE_HH