6#ifndef DUNE_COMMON_ARRAYLIST_HH
7#define DUNE_COMMON_ARRAYLIST_HH
18 template<
class T,
int N,
class A>
19 class ArrayListIterator;
21 template<
class T,
int N,
class A>
22 class ConstArrayListIterator;
60 template<
class T,
int N=100,
class A=std::allocator<T> >
196 using SmartPointerAllocator =
typename std::allocator_traits<A>::template rebind_alloc< std::shared_ptr< std::array<MemberType,chunkSize_> > >;
201 using ArrayAllocator =
typename std::allocator_traits<A>::template rebind_alloc< std::array<MemberType,chunkSize_> >;
210 std::vector<std::shared_ptr<std::array<MemberType,chunkSize_> >,
211 SmartPointerAllocator> chunks_;
250 template<
class T,
int N,
class A>
252 typename A::value_type,
253 typename A::value_type &,
254 typename A::difference_type>
362 template<
class T,
int N,
class A>
365 const typename A::value_type,
366 typename A::value_type const&,
367 typename A::difference_type>
454 template<
class T,
int N,
class A>
456 : capacity_(0), size_(0), start_(0)
458 chunks_.reserve(100);
461 template<
class T,
int N,
class A>
469 template<
class T,
int N,
class A>
475 template<
class T,
int N,
class A>
478 size_t index=start_+size_;
481 chunks_.push_back(std::make_shared<std::array<MemberType,chunkSize_> >());
482 capacity_ += chunkSize_;
484 elementAt(index)=entry;
488 template<
class T,
int N,
class A>
491 return elementAt(start_+i);
495 template<
class T,
int N,
class A>
498 return elementAt(start_+i);
501 template<
class T,
int N,
class A>
504 return chunks_[i/chunkSize_]->operator[](i%chunkSize_);
508 template<
class T,
int N,
class A>
509 typename ArrayList<T,N,A>::const_reference ArrayList<T,N,A>::elementAt(size_type i)
const
511 return chunks_[i/chunkSize_]->operator[](i%chunkSize_);
514 template<
class T,
int N,
class A>
520 template<
class T,
int N,
class A>
526 template<
class T,
int N,
class A>
532 template<
class T,
int N,
class A>
538 template<
class T,
int N,
class A>
542 size_t distance = start_/chunkSize_;
545 size_t chunks = ((start_%chunkSize_ + size_)/chunkSize_ );
548 std::copy(chunks_.begin()+distance,
549 chunks_.begin()+(distance+chunks), chunks_.begin());
552 start_ = start_ % chunkSize_;
557 template<
class T,
int N,
class A>
563 template<
class T,
int N,
class A>
570 template<
class T,
int N,
class A>
574 assert(list_==(other.list_));
575 return position_==other.position_ ;
579 template<
class T,
int N,
class A>
583 assert(list_==(other.list_));
584 return position_==other.position_ ;
588 template<
class T,
int N,
class A>
592 assert(list_==(other.list_));
593 return position_==other.position_ ;
596 template<
class T,
int N,
class A>
602 template<
class T,
int N,
class A>
608 template<
class T,
int N,
class A>
614 template<
class T,
int N,
class A>
620 template<
class T,
int N,
class A>
623 return list_->elementAt(i+position_);
626 template<
class T,
int N,
class A>
629 return list_->elementAt(i+position_);
632 template<
class T,
int N,
class A>
635 return list_->elementAt(position_);
638 template<
class T,
int N,
class A>
641 return list_->elementAt(position_);
644 template<
class T,
int N,
class A>
648 assert(list_==(other.list_));
649 return other.position_ - position_;
652 template<
class T,
int N,
class A>
656 assert(list_==(other.list_));
657 return other.position_ - position_;
660 template<
class T,
int N,
class A>
663 list_->size_ -= ++position_ - list_->start_;
665 size_t posChunkStart = position_ / chunkSize_;
667 size_t chunks = (position_ - list_->start_ + list_->start_ % chunkSize_)
669 list_->start_ = position_;
672 for(
size_t chunk=0; chunk<chunks; chunk++) {
674 list_->chunks_[posChunkStart].reset();
679 assert(list_->start_+list_->size_<=list_->capacity_);
682 template<
class T,
int N,
class A>
684 : position_(position), list_(&arrayList)
688 template<
class T,
int N,
class A>
691 : position_(position), list_(&arrayList)
694 template<
class T,
int N,
class A>
696 : position_(other.position_), list_(other.list_)
This file implements iterator facade classes for writing stl conformant iterators.
reference operator[](size_type i)
Get the element at specific position.
Definition arraylist.hh:489
iterator begin()
Get an iterator that is positioned at the first element.
Definition arraylist.hh:515
bool equals(const ArrayListIterator< MemberType, N, A > &other) const
Compares two iterators.
Definition arraylist.hh:571
void increment()
Increment the iterator.
Definition arraylist.hh:597
size_type size() const
Get the number of elements in the list.
Definition arraylist.hh:470
ConstArrayListIterator(const ArrayListIterator< T, N, A > &other)
Definition arraylist.hh:695
void purge()
Purge the list.
Definition arraylist.hh:539
void decrement()
decrement the iterator.
Definition arraylist.hh:609
void eraseToHere()
Erase all entries before the current position and the one at the current position.
Definition arraylist.hh:661
ArrayList()
Constructs an Array list with one chunk.
Definition arraylist.hh:455
const_iterator begin() const
Get a random access iterator that is positioned at the first element.
Definition arraylist.hh:521
void increment()
Increment the iterator.
Definition arraylist.hh:603
reference elementAt(size_type i) const
Get the value of the list at an arbitrary position.
Definition arraylist.hh:627
iterator end()
Get a random access iterator positioned after the last element.
Definition arraylist.hh:527
reference dereference() const
Access the element at the current position.
Definition arraylist.hh:639
const_reference operator[](size_type i) const
Get the element at specific position.
Definition arraylist.hh:496
void decrement()
decrement the iterator.
Definition arraylist.hh:615
void advance(difference_type n)
Definition arraylist.hh:564
const_iterator end() const
Get a random access iterator positioned after the last element.
Definition arraylist.hh:533
void clear()
Delete all entries from the list.
Definition arraylist.hh:462
reference elementAt(size_type i) const
Get the value of the list at an arbitrary position.
Definition arraylist.hh:621
bool equals(const ConstArrayListIterator< MemberType, N, A > &other) const
Compares to iterators.
Definition arraylist.hh:589
void advance(difference_type n)
Definition arraylist.hh:558
difference_type distanceTo(const ConstArrayListIterator< T, N, A > &other) const
Definition arraylist.hh:653
reference dereference() const
Access the element at the current position.
Definition arraylist.hh:633
void push_back(const_reference entry)
Append an entry to the list.
Definition arraylist.hh:476
difference_type distanceTo(const ArrayListIterator< T, N, A > &other) const
Definition arraylist.hh:645
Dune namespace.
Definition alignedallocator.hh:13
A random access iterator for the Dune::ArrayList class.
Definition arraylist.hh:255
A::difference_type difference_type
Definition arraylist.hh:265
size_type position()
Definition arraylist.hh:329
ArrayListIterator()
Standard constructor.
Definition arraylist.hh:338
static constexpr int chunkSize_
The number of elements in one chunk of the list.
Definition arraylist.hh:278
A::size_type size_type
Definition arraylist.hh:267
typename A::value_type const & const_reference
Definition arraylist.hh:271
A::value_type MemberType
The member type.
Definition arraylist.hh:263
typename A::value_type & reference
Definition arraylist.hh:269
A constant random access iterator for the Dune::ArrayList class.
Definition arraylist.hh:368
static constexpr int chunkSize_
The number of elements in one chunk of the list.
Definition arraylist.hh:392
ConstArrayListIterator()
Definition arraylist.hh:429
typename A::value_type const & reference
Definition arraylist.hh:383
A::difference_type difference_type
Definition arraylist.hh:379
A::value_type MemberType
The member type.
Definition arraylist.hh:377
typename A::value_type const & const_reference
Definition arraylist.hh:385
A::size_type size_type
Definition arraylist.hh:381
A dynamically growing random access list.
Definition arraylist.hh:62
std::ptrdiff_t difference_type
The difference type.
Definition arraylist.hh:120
ArrayListIterator< MemberType, N, A > iterator
A random access iterator.
Definition arraylist.hh:105
std::size_t size_type
The size type.
Definition arraylist.hh:115
T MemberType
The member type that is stored.
Definition arraylist.hh:69
static constexpr int chunkSize_
The number of elements in one chunk of the list. This has to be at least one. The default is 100.
Definition arraylist.hh:100
T value_type
Value type for stl compliance.
Definition arraylist.hh:74
const T & const_reference
The type of a const reference to the type we store.
Definition arraylist.hh:84
ConstArrayListIterator< MemberType, N, A > const_iterator
A constant random access iterator.
Definition arraylist.hh:110
T * pointer
The type of a pointer to the type we store.
Definition arraylist.hh:89
const T * const_pointer
The type of a const pointer to the type we store.
Definition arraylist.hh:94
T & reference
The type of a reference to the type we store.
Definition arraylist.hh:79
Base class for stl conformant forward iterators.
Definition iteratorfacades.hh:435