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>
364 template<
class T,
int N,
class A>
367 const typename A::value_type,
368 typename A::value_type const&,
369 typename A::difference_type>
456 template<
class T,
int N,
class A>
458 : capacity_(0), size_(0), start_(0)
460 chunks_.reserve(100);
463 template<
class T,
int N,
class A>
471 template<
class T,
int N,
class A>
477 template<
class T,
int N,
class A>
480 size_t index=start_+size_;
483 chunks_.push_back(std::make_shared<std::array<MemberType,chunkSize_> >());
484 capacity_ += chunkSize_;
486 elementAt(index)=entry;
490 template<
class T,
int N,
class A>
493 return elementAt(start_+i);
497 template<
class T,
int N,
class A>
500 return elementAt(start_+i);
503 template<
class T,
int N,
class A>
506 return chunks_[i/chunkSize_]->operator[](i%chunkSize_);
510 template<
class T,
int N,
class A>
511 typename ArrayList<T,N,A>::const_reference ArrayList<T,N,A>::elementAt(size_type i)
const
513 return chunks_[i/chunkSize_]->operator[](i%chunkSize_);
516 template<
class T,
int N,
class A>
522 template<
class T,
int N,
class A>
528 template<
class T,
int N,
class A>
534 template<
class T,
int N,
class A>
540 template<
class T,
int N,
class A>
544 size_t distance = start_/chunkSize_;
547 size_t chunks = ((start_%chunkSize_ + size_)/chunkSize_ );
550 std::copy(chunks_.begin()+distance,
551 chunks_.begin()+(distance+chunks), chunks_.begin());
554 start_ = start_ % chunkSize_;
559 template<
class T,
int N,
class A>
565 template<
class T,
int N,
class A>
572 template<
class T,
int N,
class A>
576 assert(list_==(other.list_));
577 return position_==other.position_ ;
581 template<
class T,
int N,
class A>
585 assert(list_==(other.list_));
586 return position_==other.position_ ;
590 template<
class T,
int N,
class A>
594 assert(list_==(other.list_));
595 return position_==other.position_ ;
598 template<
class T,
int N,
class A>
604 template<
class T,
int N,
class A>
610 template<
class T,
int N,
class A>
616 template<
class T,
int N,
class A>
622 template<
class T,
int N,
class A>
625 return list_->elementAt(i+position_);
628 template<
class T,
int N,
class A>
631 return list_->elementAt(i+position_);
634 template<
class T,
int N,
class A>
637 return list_->elementAt(position_);
640 template<
class T,
int N,
class A>
643 return list_->elementAt(position_);
646 template<
class T,
int N,
class A>
650 assert(list_==(other.list_));
651 return other.position_ - position_;
654 template<
class T,
int N,
class A>
658 assert(list_==(other.list_));
659 return other.position_ - position_;
662 template<
class T,
int N,
class A>
665 list_->size_ -= ++position_ - list_->start_;
667 size_t posChunkStart = position_ / chunkSize_;
669 size_t chunks = (position_ - list_->start_ + list_->start_ % chunkSize_)
671 list_->start_ = position_;
674 for(
size_t chunk=0; chunk<chunks; chunk++) {
676 list_->chunks_[posChunkStart].reset();
681 assert(list_->start_+list_->size_<=list_->capacity_);
684 template<
class T,
int N,
class A>
686 : position_(position), list_(&arrayList)
690 template<
class T,
int N,
class A>
693 : position_(position), list_(&arrayList)
696 template<
class T,
int N,
class A>
698 : 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:491
iterator begin()
Get an iterator that is positioned at the first element.
Definition arraylist.hh:517
bool equals(const ArrayListIterator< MemberType, N, A > &other) const
Comares two iterators.
Definition arraylist.hh:573
void increment()
Increment the iterator.
Definition arraylist.hh:599
size_type size() const
Get the number of elements in the list.
Definition arraylist.hh:472
ConstArrayListIterator(const ArrayListIterator< T, N, A > &other)
Definition arraylist.hh:697
void purge()
Purge the list.
Definition arraylist.hh:541
void decrement()
decrement the iterator.
Definition arraylist.hh:611
void eraseToHere()
Erase all entries before the current position and the one at the current position.
Definition arraylist.hh:663
ArrayList()
Constructs an Array list with one chunk.
Definition arraylist.hh:457
const_iterator begin() const
Get a random access iterator that is positioned at the first element.
Definition arraylist.hh:523
void increment()
Increment the iterator.
Definition arraylist.hh:605
iterator end()
Get a random access iterator positioned after the last element.
Definition arraylist.hh:529
const_reference elementAt(size_type i) const
Get the value of the list at an arbitrary position.
Definition arraylist.hh:629
const_reference operator[](size_type i) const
Get the element at specific position.
Definition arraylist.hh:498
void decrement()
decrement the iterator.
Definition arraylist.hh:617
void advance(difference_type n)
Definition arraylist.hh:566
const_iterator end() const
Get a random access iterator positioned after the last element.
Definition arraylist.hh:535
const_reference dereference() const
Access the element at the current position.
Definition arraylist.hh:641
void clear()
Delete all entries from the list.
Definition arraylist.hh:464
reference elementAt(size_type i) const
Get the value of the list at an arbitrary position.
Definition arraylist.hh:623
bool equals(const ConstArrayListIterator< MemberType, N, A > &other) const
Comares to iterators.
Definition arraylist.hh:591
void advance(difference_type n)
Definition arraylist.hh:560
difference_type distanceTo(const ConstArrayListIterator< T, N, A > &other) const
Definition arraylist.hh:655
reference dereference() const
Access the element at the current position.
Definition arraylist.hh:635
void push_back(const_reference entry)
Append an entry to the list.
Definition arraylist.hh:478
difference_type distanceTo(const ArrayListIterator< T, N, A > &other) const
Definition arraylist.hh:647
Dune namespace.
Definition alignedallocator.hh:13
A random access iterator for the Dune::ArrayList class.
Definition arraylist.hh:255
size_type position()
Definition arraylist.hh:331
A::value_type MemberType
The member type.
Definition arraylist.hh:263
ArrayListIterator()
Standard constructor.
Definition arraylist.hh:340
A::difference_type difference_type
Definition arraylist.hh:265
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
typename A::value_type & reference
Definition arraylist.hh:269
A constant random access iterator for the Dune::ArrayList class.
Definition arraylist.hh:370
static constexpr int chunkSize_
The number of elements in one chunk of the list.
Definition arraylist.hh:394
typename A::value_type & reference
Definition arraylist.hh:385
ConstArrayListIterator()
Definition arraylist.hh:431
A::value_type MemberType
The member type.
Definition arraylist.hh:379
A::difference_type difference_type
Definition arraylist.hh:381
typename A::value_type const & const_reference
Definition arraylist.hh:387
A::size_type size_type
Definition arraylist.hh:383
A dynamically growing random access list.
Definition arraylist.hh:62
T value_type
Value type for stl compliance.
Definition arraylist.hh:74
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
const T * const_pointer
The type of a const pointer to the type we store.
Definition arraylist.hh:94
ArrayListIterator< MemberType, N, A > iterator
A random access iterator.
Definition arraylist.hh:105
const T & const_reference
The type of a const reference to the type we store.
Definition arraylist.hh:84
T & reference
The type of a reference to the type we store.
Definition arraylist.hh:79
std::size_t size_type
The size type.
Definition arraylist.hh:115
T MemberType
The member type that is stored.
Definition arraylist.hh:69
T * pointer
The type of a pointer to the type we store.
Definition arraylist.hh:89
ConstArrayListIterator< MemberType, N, A > const_iterator
A constant random access iterator.
Definition arraylist.hh:110
std::ptrdiff_t difference_type
The difference type.
Definition arraylist.hh:120
Base class for stl conformant forward iterators.
Definition iteratorfacades.hh:434