27 #ifndef MLN_CORE_SITE_SET_P_ARRAY_HH
28 # define MLN_CORE_SITE_SET_P_ARRAY_HH
43 # include <mln/core/internal/site_set_base.hh>
44 # include <mln/core/internal/site_set_iterator_base.hh>
45 # include <mln/core/internal/pseudo_site_base.hh>
46 # include <mln/util/index.hh>
53 template <
typename P>
class p_array;
55 template <
typename S>
class p_indexed_psite;
56 template <
typename S>
class p_indexed_fwd_piter;
57 template <
typename S>
class p_indexed_bkd_piter;
65 struct site_set_< p_array<P> >
67 typedef trait::site_set::nsites::known
nsites;
68 typedef trait::site_set::bbox::unknown bbox;
69 typedef trait::site_set::contents::growing contents;
70 typedef trait::site_set::arity::multiple arity;
84 class p_array :
public internal::site_set_base_< P, p_array<P> >
88 typedef typename std::vector<P>::size_type size_type;
110 p_array(
const std::vector<P>& vect);
121 bool has(
const util::index& i)
const;
160 const P&
operator[](
const util::index& i)
const;
171 std::vector<P>& hook_std_vector_();
175 std::vector<P> vect_;
182 template <
typename S>
188 typedef mln_element(S) element;
198 const element& subj_();
206 const util::index& index()
const;
208 void change_index(
int i);
212 const S* target_()
const;
213 void change_target(
const S& newtarget);
215 bool is_valid()
const;
217 operator util::index()
const;
218 operator int()
const;
219 operator unsigned()
const;
221 void update_()
const;
234 template <
typename S>
237 public internal::site_set_iterator_base< S,
238 p_indexed_fwd_piter<S> >
241 typedef internal::site_set_iterator_base<S, self> super;
252 bool is_valid_()
const;
275 template <
typename S>
278 public internal::site_set_iterator_base< S,
279 p_indexed_bkd_piter<S> >
282 typedef internal::site_set_iterator_base<S, self> super;
293 bool is_valid_()
const;
316 template <
typename P,
typename S>
317 int index_of_in(
const P&,
const S&);
319 template <
typename S>
322 template <
typename S,
typename A>
325 template <
typename S,
typename A>
328 template <
typename S,
typename A>
333 # ifndef MLN_INCLUDE_ONLY
338 template <
typename P>
344 template <
typename P>
351 template <
typename P>
359 template <
typename P>
364 mln_precondition(p.target_() ==
this);
365 if (! has(p.index()))
368 mln_invariant(p == static_cast<P>((*
this)[p.index()]));
372 template <
typename P>
377 return i >= 0 && unsigned(i) < nsites();
380 template <
typename P>
388 template <
typename P>
393 mln_precondition(has(i));
397 template <
typename P>
405 template <
typename P>
414 template <
typename P>
422 template <
typename P>
427 vect_.insert(vect_.end(),
433 template <
typename P>
439 mln_postcondition(this->is_empty());
442 template <
typename P>
447 mln_precondition(size >= 0);
451 template <
typename P>
456 mln_precondition(i < nsites());
460 template <
typename P>
465 mln_precondition(i < nsites());
469 template <
typename P>
474 mln_precondition(has(p));
475 vect_[p.index()] = new_p;
478 template <
typename P>
483 return sizeof(*this) + nsites() *
sizeof(P);
486 template <
typename P>
488 const std::vector<P>&
494 template <
typename P>
506 template <
typename S>
508 p_indexed_psite<S>::p_indexed_psite()
514 template <
typename S>
516 p_indexed_psite<S>::p_indexed_psite(
const S& s,
int i)
523 template <
typename S>
526 p_indexed_psite<S>::index()
const
531 template <
typename S>
534 p_indexed_psite<S>::change_index(
int i)
540 template <
typename S>
543 p_indexed_psite<S>::dec_index()
549 template <
typename S>
552 p_indexed_psite<S>::inc_index()
558 template <
typename S>
561 p_indexed_psite<S>::change_target(
const S& newtarget)
567 template <
typename S>
570 p_indexed_psite<S>::is_valid()
const
572 return s_ != 0 && s_->has(i_);
575 template <
typename S>
578 p_indexed_psite<S>::target_()
const
583 template <
typename S>
585 const mln_element(S)&
586 p_indexed_psite<S>::subj_()
589 mln_invariant(p_ == (*s_)[i_]);
593 template <
typename S>
596 p_indexed_psite<S>::update_()
const
602 template <
typename S>
604 p_indexed_psite<S>::operator util::index()
const
609 template <
typename S>
611 p_indexed_psite<S>::operator int()
const
616 template <
typename S>
618 p_indexed_psite<S>::operator unsigned()
const
620 mln_precondition(i_ >= 0);
627 template <
typename S>
633 template <
typename S>
637 this->change_target(s);
640 template <
typename S>
645 mln_invariant(p_.index() >= 0);
646 return p_.index() < int(s_->nsites());
649 template <
typename S>
652 p_indexed_fwd_piter<S>::invalidate_()
654 p_.change_index(s_->nsites());
657 template <
typename S>
660 p_indexed_fwd_piter<S>::start_()
665 template <
typename S>
668 p_indexed_fwd_piter<S>::next_()
673 template <
typename S>
684 template <
typename S>
690 template <
typename S>
694 this->change_target(s);
697 template <
typename S>
702 mln_invariant(p_.index() < int(s_->nsites()));
703 return p_.index() >= 0;
706 template <
typename S>
709 p_indexed_bkd_piter<S>::invalidate_()
714 template <
typename S>
717 p_indexed_bkd_piter<S>::start_()
719 p_.change_index(s_->nsites() - 1);
722 template <
typename S>
725 p_indexed_bkd_piter<S>::next_()
730 template <
typename S>
741 template <
typename P,
typename S>
742 int index_of_in(
const P&,
const S&)
747 template <
typename S>
748 int index_of_in(
const p_indexed_psite<S>& p,
const S& s)
750 if ((
void*)(p.target_()) == (
void*)(&s))
753 return index_of_in(p.unproxy_(), s);
756 template <
typename S,
typename A>
757 int index_of_in(
const p_indexed_psite<S>& p,
const A& a)
759 return index_of_in(p.unproxy_(), a);
762 template <
typename S,
typename A>
765 index_of_in(
const p_indexed_fwd_piter<S>& p,
const A& arr)
767 return index_of_in(p.unproxy_(), arr);
770 template <
typename S,
typename A>
773 index_of_in(
const p_indexed_bkd_piter<S>& p,
const A& arr)
775 return index_of_in(p.unproxy_(), arr);
778 # endif // ! MLN_INCLUDE_ONLY
783 #endif // ! MLN_CORE_SITE_SET_P_ARRAY_HH