27 #ifndef MLN_WIN_MULTIPLE_SIZE_HH
28 # define MLN_WIN_MULTIPLE_SIZE_HH
36 # include <mln/core/internal/window_base.hh>
37 # include <mln/core/internal/site_relative_iterator_base.hh>
38 # include <mln/util/array.hh>
39 # include <mln/metal/ands.hh>
49 template <
unsigned n,
typename W,
typename F>
class multiple_size;
50 template <
unsigned n,
typename W,
typename F>
class multiple_size_qiter;
58 template <
unsigned n,
typename W,
typename F>
59 struct window_< win::multiple_size<n,W,F> >
61 typedef trait::window::size::unknown size;
62 typedef trait::window::support::regular support;
63 typedef trait::window::definition::n_ary definition;
77 template <
unsigned n,
typename W,
typename F>
80 :
public internal::window_base< mln_dpsite(W), multiple_size<n,W,F> >,
83 mlc_is(mln_trait_window_size(W),
84 trait::window::size::fixed),
85 mlc_is(mln_trait_window_support(W),
86 trait::window::support::regular) >::check_t
90 typedef mln_dpsite(W) dpsite;
91 typedef mln_psite(W) psite;
92 typedef mln_site(W) site;
96 typedef multiple_size_qiter<n,W,F> fwd_qiter;
97 typedef multiple_size_qiter<n,W,F> bkd_qiter;
98 typedef multiple_size_qiter<n,W,F> qiter;
106 bool is_empty()
const;
108 void set_window(
unsigned i,
const W& win);
110 const W& window_(
unsigned i)
const;
112 unsigned nwindows()
const;
114 const F&
function()
const;
116 unsigned size_around(
const mln_psite(W)& p)
const;
118 const mln_dpsite(W)& ith_dp_around(
unsigned i,
const mln_psite(W)& p)
const;
120 bool is_centered()
const;
122 bool is_symmetric()
const;
126 unsigned delta()
const;
135 template <
unsigned n,
typename W,
typename F>
136 class multiple_size_qiter
137 :
public internal::site_relative_iterator_base< multiple_size<n,W,F>,
138 multiple_size_qiter<n,W,F> >
140 typedef multiple_size_qiter<n,W,F> self_;
141 typedef internal::site_relative_iterator_base< multiple_size<n,W,F>, self_ > super_;
144 multiple_size_qiter();
146 template <
typename P>
149 template <
typename P>
153 bool is_valid_()
const;
165 mln_psite(W) compute_p_() const;
174 # ifndef MLN_INCLUDE_ONLY
178 template <
unsigned n,
typename W,
typename F>
185 template <
unsigned n,
typename W,
typename F>
187 multiple_size<n,W,F>::multiple_size(
const F& f)
192 template <
unsigned n,
typename W,
typename F>
195 multiple_size<n,W,F>::is_empty()
const
197 return win_.is_empty();
200 template <
unsigned n,
typename W,
typename F>
203 multiple_size<n,W,F>::set_window(
unsigned i,
const W& win)
205 mln_precondition(i == win_.nelements());
210 template <
unsigned n,
typename W,
typename F>
213 multiple_size<n,W,F>::window_(
unsigned i)
const
215 mln_precondition(i < win_.nelements());
219 template <
unsigned n,
typename W,
typename F>
222 multiple_size<n,W,F>::nwindows()
const
224 return win_.nelements();
227 template <
unsigned n,
typename W,
typename F>
230 multiple_size<n,W,F>::function()
const
235 template <
unsigned n,
typename W,
typename F>
238 multiple_size<n,W,F>::is_centered()
const
240 mln_precondition(win_.nelements() >= 1);
241 for (
unsigned i = 0; i < win_.nelements(); ++i)
242 if (! win_[i].is_centered())
247 template <
unsigned n,
typename W,
typename F>
250 multiple_size<n,W,F>::is_symmetric()
const
252 mln_precondition(win_.nelements() >= 1);
253 for (
unsigned i = 0; i < win_.nelements(); ++i)
254 if (! win_[i].is_symmetric())
259 template <
unsigned n,
typename W,
typename F>
262 multiple_size<n,W,F>::sym()
264 mln_precondition(win_.nelements() >= 1);
265 for (
unsigned i = 0; i < win_.nelements(); ++i)
269 template <
unsigned n,
typename W,
typename F>
272 multiple_size<n,W,F>::delta()
const
274 mln_precondition(win_.nelements() >= 1);
275 unsigned d = win_[0].delta();
276 for (
unsigned i = 1; i < win_.nelements(); ++i)
278 unsigned d_i = win_[i].delta();
285 template <
unsigned n,
typename W,
typename F>
288 multiple_size<n,W,F>::size_around(
const mln_psite(W)& p)
const
290 mln_precondition(win_.nelements() >= 2);
291 mln_precondition(f_(p) < win_.nelements());
292 return win_[f_(p)].size();
295 template <
unsigned n,
typename W,
typename F>
298 multiple_size<n,W,F>::ith_dp_around(
unsigned i,
const mln_psite(W)& p)
const
300 mln_precondition(win_.nelements() >= 2);
301 mln_precondition(f_(p) < win_.nelements());
302 mln_precondition(i < win_[f_(p)].size());
303 return win_[f_(p)].dp(i);
309 template <
unsigned n,
typename W,
typename F>
311 multiple_size_qiter<n,W,F>::multiple_size_qiter()
315 template <
unsigned n,
typename W,
typename F>
316 template <
typename P>
318 multiple_size_qiter<n,W,F>::multiple_size_qiter(
const multiple_size<n,W,F>& w,
const P& c)
323 template <
unsigned n,
typename W,
typename F>
324 template <
typename P>
327 multiple_size_qiter<n,W,F>::init_(
const multiple_size<n,W,F>& w,
const P& c)
332 this->change_target(w);
336 template <
unsigned n,
typename W,
typename F>
339 multiple_size_qiter<n,W,F>::is_valid_()
const
341 return i_ != -1 && i_ < size_();
344 template <
unsigned n,
typename W,
typename F>
347 multiple_size_qiter<n,W,F>::invalidate_()
352 template <
unsigned n,
typename W,
typename F>
355 multiple_size_qiter<n,W,F>::do_start_()
360 template <
unsigned n,
typename W,
typename F>
363 multiple_size_qiter<n,W,F>::do_next_()
368 template <
unsigned n,
typename W,
typename F>
371 multiple_size_qiter<n,W,F>::compute_p_()
const
373 return *this->c_ + this->s_->ith_dp_around(i_, *this->c_);
376 template <
unsigned n,
typename W,
typename F>
379 multiple_size_qiter<n,W,F>::size_()
const
381 return int(this->s_->size_around(*this->c_));
384 # endif // ! MLN_INCLUDE_ONLY
392 #endif // ! MLN_WIN_MULTIPLE_SIZE_HH