Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
p_centered.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_SITE_SET_P_CENTERED_HH
27 # define MLN_CORE_SITE_SET_P_CENTERED_HH
28 
36 
37 
38 # include <mln/core/internal/site_set_base.hh>
39 # include <mln/core/internal/site_set_iterator_base.hh>
40 
41 
42 namespace mln
43 {
44 
45  // Fwd decls.
46  template <typename W> class p_centered;
47  template <typename W> class p_centered_piter;
48 
49 
50  namespace trait
51  {
52 
53  template <typename W>
54  struct site_set_< p_centered<W> >
55  {
56  typedef trait::site_set::nsites::unknown nsites;
57  typedef trait::site_set::bbox::unknown bbox;
58  typedef trait::site_set::contents::fixed contents;
59  typedef trait::site_set::arity::unique arity;
60  };
61 
62 // template <typename W>
63 // struct set_precise_unary_< op::ord, p_centered<W> >
64 // {
65 // typedef set_precise_unary_< op::ord, p_centered<W> > ret; // Itself.
66 // bool strict(const p_centered<W>& lhs, const p_centered<W>& rhs) const;
67 // };
68 
69  } // end of namespace mln::trait
70 
71 
75  //
76  template <typename W>
77  class p_centered : public internal::site_set_base_< mln_psite(W), p_centered<W> >,
78  private mlc_is_a(W, Window)::check_t
79  {
80  public:
81 
83  typedef mln_psite(W) psite;
84 
86  typedef mln_site(W) site;
87 
88 
90  typedef psite element;
91 
92 
94  typedef p_centered_piter<W> fwd_piter;
95 
97  typedef p_centered_piter<W> bkd_piter; // FIXME
98 
100  typedef fwd_piter piter;
101 
102 
104  p_centered();
105 
107  p_centered(const W& win, const mln_psite(W)& c);
108 
109 
111  template <typename P>
112  bool has(const P& p) const;
113 
115  bool is_valid() const;
116 
118  std::size_t memory_size() const;
119 
121  const mln_psite(W)& center() const;
122 
124  const W& window() const;
125 
126  protected:
127 
128  W win_;
129  mln_psite(W) c_;
130  };
131 
132 
133  template <typename W>
134  class p_centered_piter : public internal::site_set_iterator_base< p_centered<W>,
135  p_centered_piter<W> >
136  {
137  typedef p_centered_piter<W> self_;
138  typedef internal::site_set_iterator_base< p_centered<W>, self_ > super_;
139  public:
140 
142  p_centered_piter();
143 
145  p_centered_piter(const p_centered<W>& s);
146 
148  bool is_valid_() const;
149 
151  void invalidate_();
152 
154  void start_();
155 
157  void next_();
158 
159  protected:
160  using super_::p_;
161  using super_::s_;
162 
163  mln_fwd_qiter(W) q_;
164  };
165 
166 
167 
168 # ifndef MLN_INCLUDE_ONLY
169 
170  // p_centered<W>
171 
172  template <typename W>
173  inline
174  bool
176  {
177  return true; // FIXME
178  }
179 
180  template <typename W>
181  inline
183  {
184  }
185 
186  template <typename W>
187  inline
188  p_centered<W>::p_centered(const W& win, const mln_psite(W)& c)
189  : win_(win),
190  c_(c)
191  {
192  mln_precondition(is_valid());
193  }
194 
195  template <typename W>
196  template <typename P>
197  inline
198  bool
199  p_centered<W>::has(const P&) const
200  {
201  mln_precondition(is_valid());
202  return true; // FIXME
203  }
204 
205  template <typename W>
206  inline
207  std::size_t
209  {
210  return sizeof(*this);
211  }
212 
213  template <typename W>
214  inline
215  const mln_psite(W)&
217  {
218  return c_;
219  }
220 
221  template <typename W>
222  inline
223  const W&
225  {
226  return win_;
227  }
228 
229 // namespace trait
230 // {
231 
232 // template <typename W>
233 // inline
234 // bool
235 // set_precise_unary_< op::ord, p_centered<W> >::strict(const p_centered<W>& lhs, const p_centered<W>& rhs) const
236 // {
237 // // Lexicographical over "pmin then pmax".
238 // return util::ord_lexi_strict(lhs.pmin(), lhs.pmax(),
239 // rhs.pmin(), rhs.pmax());
240 // }
241 
242 // } // end of namespace mln::trait
243 
244 
245  // p_centered_piter<W>
246 
247  template <typename W>
248  inline
249  p_centered_piter<W>::p_centered_piter()
250  {
251  }
252 
253  template <typename W>
254  inline
255  p_centered_piter<W>::p_centered_piter(const p_centered<W>& s)
256  {
257  this->change_target(s);
258  q_.center_at(s.center());
259  q_.change_target(s.window_());
260  }
261 
262  template <typename W>
263  inline
264  bool
265  p_centered_piter<W>::is_valid_() const
266  {
267  return q_.is_valid();
268  }
269 
270  template <typename W>
271  inline
272  void
273  p_centered_piter<W>::invalidate_()
274  {
275  q_.invalidate();
276  }
277 
278  template <typename W>
279  inline
280  void
281  p_centered_piter<W>::start_()
282  {
283  q_.start();
284  if (is_valid_())
285  p_ = q_;
286  }
287 
288  template <typename W>
289  inline
290  void
291  p_centered_piter<W>::next_()
292  {
293  q_.next();
294  if (is_valid_())
295  p_ = q_;
296  }
297 
298 # endif // ! MLN_INCLUDE_ONLY
299 
300 } // end of namespace mln
301 
302 
303 #endif // ! MLN_CORE_SITE_SET_P_CENTERED_HH