26 #ifndef MLN_CORE_SITE_SET_P_RUN_HH
27 # define MLN_CORE_SITE_SET_P_RUN_HH
35 # include <mln/core/internal/site_set_base.hh>
36 # include <mln/core/site_set/box.hh>
37 # include <mln/core/internal/pseudo_site_base.hh>
38 # include <mln/util/index.hh>
45 template <
typename P>
class p_run;
46 template <
typename P>
class p_run_psite;
47 template <
typename P>
class p_run_fwd_piter_;
48 template <
typename P>
class p_run_bkd_piter_;
57 struct site_set_< p_run<P> >
59 typedef trait::site_set::nsites::known
nsites;
60 typedef trait::site_set::bbox::straight bbox;
61 typedef trait::site_set::contents::fixed contents;
62 typedef trait::site_set::arity::unique arity;
66 struct set_precise_unary_< op::ord, p_run<P> >
68 typedef set_precise_unary_< op::ord, p_run<P> > ret;
69 bool strict(
const p_run<P>& lhs,
const p_run<P>& rhs)
const;
86 class p_run :
public internal::site_set_base_< P, p_run<P> >
117 void init(
const P&
start,
unsigned short len);
124 bool has(
const P& p)
const;
133 unsigned short length()
const;
139 const P&
start()
const;
168 template <
typename P>
169 std::ostream& operator<<(std::ostream& ostr, const p_run<P>& r);
175 template <
typename P>
176 class p_run_psite :
public internal::pseudo_site_base_< const P&,
179 typedef p_run_psite<P>
self;
180 typedef internal::pseudo_site_base_<const P&, self> super;
193 p_run_psite(
const p_run<P>& run,
int i);
197 void change_index(
int i);
202 void change_target(
const p_run<P>& new_target);
204 bool is_valid()
const;
206 operator util::index()
const;
219 # ifndef MLN_INCLUDE_ONLY
221 template <
typename P>
228 template <
typename P>
232 mln_precondition(len != 0);
236 template <
typename P>
241 mln_precondition(cut_(end) == cut_(start));
242 mln_precondition(end.last_coord() >= start.last_coord());
243 len_ = end.last_coord() - start.last_coord() + 1;
246 template <
typename P>
251 mln_precondition(len != 0);
256 template <
typename P>
264 template <
typename P>
273 template <
typename P>
278 mln_precondition(p.target_() ==
this);
279 if (p.index() < 0 || unsigned(p.index()) >= len_)
282 mln_invariant(p.to_site() == (*this)[p.index()]);
286 template <
typename P>
291 mln_precondition(is_valid());
292 if (cut_(p) != cut_(start_))
295 p.last_coord() >= start_.last_coord() &&
296 p.last_coord() < start_.last_coord() + len_;
299 template <
typename P>
307 template <
typename P>
312 mln_precondition(is_valid());
316 template <
typename P>
321 mln_precondition(is_valid());
325 template <
typename P>
330 mln_precondition(is_valid());
331 mln_precondition(i < len_);
337 template <
typename P>
345 template <
typename P>
355 template <
typename P>
360 return sizeof(*this);
363 template <
typename P>
364 std::ostream& operator<<(std::ostream& ostr, const p_run<P>& r)
366 ostr <<
'(' << r.start() <<
", " << r.length() <<
')';
374 template <
typename P>
376 p_run_psite<P>::p_run_psite()
382 template <
typename P>
384 p_run_psite<P>::p_run_psite(
const p_run<P>& run,
int i)
389 p_.last_coord() += i_;
392 template <
typename P>
395 p_run_psite<P>::is_valid()
const
397 return run_ != 0 && run_->has_index(i_);
400 template <
typename P>
403 p_run_psite<P>::index()
const
408 template <
typename P>
411 p_run_psite<P>::change_index(
int i)
413 p_.last_coord() += (i - i_);
417 template <
typename P>
420 p_run_psite<P>::dec_index()
423 p_.last_coord() -= 1;
426 template <
typename P>
429 p_run_psite<P>::inc_index()
432 p_.last_coord() += 1;
435 template <
typename P>
438 p_run_psite<P>::target_()
const
443 template <
typename P>
446 p_run_psite<P>::change_target(
const p_run<P>& new_target)
453 template <
typename P>
456 p_run_psite<P>::subj_()
461 template <
typename P>
463 p_run_psite<P>::operator util::index()
const
468 template <
typename P>
471 p_run_psite<P>::run()
const
473 mln_precondition(run_ != 0);
480 template <
typename P>
483 set_precise_unary_< op::ord, p_run<P> >::strict(
const p_run<P>& lhs,
const p_run<P>& rhs)
const
490 # endif // ! MLN_INCLUDE_ONLY
495 # include <mln/core/site_set/p_run_piter.hh>
498 #endif // ! MLN_CORE_SITE_SET_P_RUN_HH