Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
graph_window_if_piter.hh
1 // Copyright (C) 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_IMAGE_GRAPH_WINDOW_IF_PITER_HH
27 # define MLN_CORE_IMAGE_GRAPH_WINDOW_IF_PITER_HH
28 
32 
33 # include <mln/core/internal/is_masked_impl_selector.hh>
34 # include <mln/core/internal/site_relative_iterator_base.hh>
35 
36 
37 namespace mln
38 {
39 
40  // Forward declaration.
41  template <typename S, typename I> class p_graph_piter;
42 
43 
44 
46  template <typename S, typename W, typename I>
48  : public internal::site_relative_iterator_base< W,
49  graph_window_if_piter<S,W,I> >,
50  public internal::is_masked_impl_selector< S,
51  typename W::mask_t::domain_t,
52  graph_window_if_piter<S,W,I> >
53  {
55  typedef internal::site_relative_iterator_base<W,self_> super_;
56 
57  public:
60  typedef mln_result(S::fun_t) P;
62 
66  template <typename Pref>
67  graph_window_if_piter(const Window<W>& win,
68  const Pref& p_ref);
70 
72  template <typename Pref>
73  void init_(const Window<W>& win, const Pref& p_ref);
74 
78  bool is_valid_() const;
80  void invalidate_();
81 
83  void do_start_();
85  void do_next_();
86 
88  template <typename Pref>
89  void center_at_(const Pref& c);
90 
92  template <typename I2>
93  void center_at_(const p_graph_piter<S, I2>& c);
94 
96  const mln_graph_element(S)& element() const;
97 
99  mln_psite(W) compute_p_() const;
100 
105  unsigned id() const;
107 
108  private:
109  I iter_;
110 
111  protected:
113  using super_::s_;
114  };
115 
116 
117 
118 # ifndef MLN_INCLUDE_ONLY
119 
120  template <typename S, typename W, typename I>
121  inline
123  {
124  }
125 
126  template <typename S, typename W, typename I>
127  template <typename Pref>
128  inline
130  const Pref& p_ref)
131  {
132  init_(win, p_ref);
133  }
134 
135  template <typename S, typename W, typename I>
136  template <typename Pref>
137  inline
138  void
139  graph_window_if_piter<S,W,I>::init_(const Window<W>& win,
140  const Pref& p_ref)
141  {
142  this->center_at(p_ref);
143  this->change_target(exact(win));
144 
145  mln_postcondition(!this->is_valid());
146  }
147 
148  template <typename S, typename W, typename I>
149  inline
150  bool
151  graph_window_if_piter<S,W,I>::is_valid_() const
152  {
153  return iter_.is_valid();
154  }
155 
156  template <typename S, typename W, typename I>
157  inline
158  void
159  graph_window_if_piter<S,W,I>::invalidate_()
160  {
161  iter_.invalidate();
162  }
163 
164  template <typename S, typename W, typename I>
165  inline
166  void
167  graph_window_if_piter<S,W,I>::do_start_()
168  {
169  iter_.start();
170  while (iter_.is_valid() && this->is_masked(this->c_->element(), iter_))
171  iter_.next();
172  }
173 
174  template <typename S, typename W, typename I>
175  inline
176  void
177  graph_window_if_piter<S,W,I>::do_next_()
178  {
179  iter_.next();
180  while (iter_.is_valid() && this->is_masked(this->c_->element(), iter_))
181  iter_.next();
182  }
183 
184  template <typename S, typename W, typename I>
185  template <typename Pref>
186  inline
187  void
188  graph_window_if_piter<S,W,I>::center_at_(const Pref& c)
189  {
190  iter_.center_at(c.p_hook_());
191  }
192 
193  template <typename S, typename W, typename I>
194  template <typename I2>
195  inline
196  void
197  graph_window_if_piter<S,W,I>::center_at_(const p_graph_piter<S, I2>& c)
198  {
199  iter_.center_at(c.hook_elt_());
200  }
201 
202  template <typename S, typename W, typename I>
203  inline
204  mln_psite(W)
205  graph_window_if_piter<S,W,I>::compute_p_() const
206  {
207  return mln_psite(S)(this->center().site_set(), iter_.id());
208  }
209 
210  template <typename S, typename W, typename I>
211  inline
212  const mln_graph_element(S)&
214  {
215  return iter_;
216  }
217 
218  template <typename S, typename W, typename I>
219  inline
220  unsigned
222  {
223  return iter_.id();
224  }
225 
226 
227 # endif // ! MLN_INCLUDE_ONLY
228 
229 } // end of namespace mln
230 
231 #endif // ! MLN_CORE_IMAGE_GRAPH_WINDOW_IF_PITER_HH