4#ifndef DUNE_COMMON_ARRAYLIST_HH
5#define DUNE_COMMON_ARRAYLIST_HH
16 template<
class T,
int N,
class A>
17 class ArrayListIterator;
19 template<
class T,
int N,
class A>
20 class ConstArrayListIterator;
58 template<
class T,
int N=100,
class A=std::allocator<T> >
197 typedef typename A::template rebind<std::shared_ptr<std::array<MemberType,chunkSize_> > >::other
198 SmartPointerAllocator;
203 typedef typename A::template rebind<std::array<MemberType,chunkSize_> >::other
213 std::vector<std::shared_ptr<std::array<MemberType,chunkSize_> >,
214 SmartPointerAllocator> chunks_;
253 template<
class T,
int N,
class A>
255 typename A::value_type,
256 typename A::reference,
257 typename A::difference_type>
373 template<
class T,
int N,
class A>
376 const typename A::value_type,
377 typename A::const_reference,
378 typename A::difference_type>
469 template<
class T,
int N,
class A>
471 : capacity_(0), size_(0), start_(0)
473 chunks_.reserve(100);
476 template<
class T,
int N,
class A>
484 template<
class T,
int N,
class A>
490 template<
class T,
int N,
class A>
493 size_t index=start_+size_;
496 chunks_.push_back(std::make_shared<std::array<MemberType,chunkSize_> >());
497 capacity_ += chunkSize_;
499 elementAt(index)=entry;
503 template<
class T,
int N,
class A>
506 return elementAt(start_+i);
510 template<
class T,
int N,
class A>
513 return elementAt(start_+i);
516 template<
class T,
int N,
class A>
519 return chunks_[i/chunkSize_]->operator[](i%chunkSize_);
523 template<
class T,
int N,
class A>
524 typename ArrayList<T,N,A>::const_reference ArrayList<T,N,A>::elementAt(size_type i)
const
526 return chunks_[i/chunkSize_]->operator[](i%chunkSize_);
529 template<
class T,
int N,
class A>
535 template<
class T,
int N,
class A>
541 template<
class T,
int N,
class A>
547 template<
class T,
int N,
class A>
553 template<
class T,
int N,
class A>
557 size_t distance = start_/chunkSize_;
560 size_t chunks = ((start_%chunkSize_ + size_)/chunkSize_ );
563 std::copy(chunks_.begin()+distance,
564 chunks_.begin()+(distance+chunks), chunks_.begin());
567 start_ = start_ % chunkSize_;
572 template<
class T,
int N,
class A>
578 template<
class T,
int N,
class A>
585 template<
class T,
int N,
class A>
589 assert(list_==(other.list_));
590 return position_==other.position_ ;
594 template<
class T,
int N,
class A>
598 assert(list_==(other.list_));
599 return position_==other.position_ ;
603 template<
class T,
int N,
class A>
607 assert(list_==(other.list_));
608 return position_==other.position_ ;
611 template<
class T,
int N,
class A>
617 template<
class T,
int N,
class A>
623 template<
class T,
int N,
class A>
629 template<
class T,
int N,
class A>
635 template<
class T,
int N,
class A>
638 return list_->elementAt(i+position_);
641 template<
class T,
int N,
class A>
644 return list_->elementAt(i+position_);
647 template<
class T,
int N,
class A>
650 return list_->elementAt(position_);
653 template<
class T,
int N,
class A>
656 return list_->elementAt(position_);
659 template<
class T,
int N,
class A>
663 assert(list_==(other.list_));
664 return other.position_ - position_;
667 template<
class T,
int N,
class A>
671 assert(list_==(other.list_));
672 return other.position_ - position_;
675 template<
class T,
int N,
class A>
678 position_=other.position_;
683 template<
class T,
int N,
class A>
686 position_=other.position_;
691 template<
class T,
int N,
class A>
694 list_->size_ -= ++position_ - list_->start_;
696 size_t posChunkStart = position_ / chunkSize_;
698 size_t chunks = (position_ - list_->start_ + list_->start_ % chunkSize_)
700 list_->start_ = position_;
703 for(
size_t chunk=0; chunk<chunks; chunk++) {
705 list_->chunks_[posChunkStart].reset();
710 assert(list_->start_+list_->size_<=list_->capacity_);
713 template<
class T,
int N,
class A>
715 : position_(position), list_(&arrayList)
719 template<
class T,
int N,
class A>
722 : position_(position), list_(&arrayList)
725 template<
class T,
int N,
class A>
727 : 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:504
iterator begin()
Get an iterator that is positioned at the first element.
Definition arraylist.hh:530
bool equals(const ArrayListIterator< MemberType, N, A > &other) const
Comares two iterators.
Definition arraylist.hh:586
void increment()
Increment the iterator.
Definition arraylist.hh:612
size_type size() const
Get the number of elements in the list.
Definition arraylist.hh:485
ConstArrayListIterator(const ArrayListIterator< T, N, A > &other)
Definition arraylist.hh:726
void purge()
Purge the list.
Definition arraylist.hh:554
const ConstArrayListIterator< T, N, A > & operator=(const ConstArrayListIterator< T, N, A > &other)
Definition arraylist.hh:684
void decrement()
decrement the iterator.
Definition arraylist.hh:624
void eraseToHere()
Erase all entries before the current position and the one at the current position.
Definition arraylist.hh:692
ArrayList()
Constructs an Array list with one chunk.
Definition arraylist.hh:470
const_iterator begin() const
Get a random access iterator that is positioned at the first element.
Definition arraylist.hh:536
void increment()
Increment the iterator.
Definition arraylist.hh:618
iterator end()
Get a random access iterator positioned after the last element.
Definition arraylist.hh:542
const_reference elementAt(size_type i) const
Get the value of the list at an arbitrary position.
Definition arraylist.hh:642
const_reference operator[](size_type i) const
Get the element at specific position.
Definition arraylist.hh:511
void decrement()
decrement the iterator.
Definition arraylist.hh:630
void advance(difference_type n)
Definition arraylist.hh:579
const_iterator end() const
Get a random access iterator positioned after the last element.
Definition arraylist.hh:548
const_reference dereference() const
Access the element at the current position.
Definition arraylist.hh:654
void clear()
Delete all entries from the list.
Definition arraylist.hh:477
reference elementAt(size_type i) const
Get the value of the list at an arbitrary position.
Definition arraylist.hh:636
bool equals(const ConstArrayListIterator< MemberType, N, A > &other) const
Comares to iterators.
Definition arraylist.hh:604
void advance(difference_type n)
Definition arraylist.hh:573
ArrayListIterator< T, N, A > & operator=(const ArrayListIterator< T, N, A > &other)
Definition arraylist.hh:676
difference_type distanceTo(const ConstArrayListIterator< T, N, A > &other) const
Definition arraylist.hh:668
reference dereference() const
Access the element at the current position.
Definition arraylist.hh:648
void push_back(const_reference entry)
Append an entry to the list.
Definition arraylist.hh:491
difference_type distanceTo(const ArrayListIterator< T, N, A > &other) const
Definition arraylist.hh:660
Dune namespace.
Definition alignment.hh:11
A random access iterator for the Dune::ArrayList class.
Definition arraylist.hh:258
size_type position()
Definition arraylist.hh:337
A::value_type MemberType
The member type.
Definition arraylist.hh:266
A::reference reference
Definition arraylist.hh:272
A::const_reference const_reference
Definition arraylist.hh:274
ArrayListIterator()
Standard constructor.
Definition arraylist.hh:349
A::difference_type difference_type
Definition arraylist.hh:268
@ chunkSize_
The number of elements in one chunk of the list.
Definition arraylist.hh:283
A::size_type size_type
Definition arraylist.hh:270
A constant random access iterator for the Dune::ArrayList class.
Definition arraylist.hh:379
ConstArrayListIterator()
Definition arraylist.hh:444
A::value_type MemberType
The member type.
Definition arraylist.hh:388
@ chunkSize_
The number of elements in one chunk of the list.
Definition arraylist.hh:404
A::const_reference const_reference
Definition arraylist.hh:396
A::difference_type difference_type
Definition arraylist.hh:390
A::size_type size_type
Definition arraylist.hh:392
A::reference reference
Definition arraylist.hh:394
A dynamically growing random access list.
Definition arraylist.hh:60
T value_type
Value type for stl compliance.
Definition arraylist.hh:72
@ 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:92
ArrayListIterator< MemberType, N, A > iterator
A random access iterator.
Definition arraylist.hh:106
const T & const_reference
The type of a const reference to the type we store.
Definition arraylist.hh:82
T & reference
The type of a reference to the type we store.
Definition arraylist.hh:77
std::size_t size_type
The size type.
Definition arraylist.hh:116
T MemberType
The member type that is stored.
Definition arraylist.hh:67
T * pointer
The type of a pointer to the type we store.
Definition arraylist.hh:87
ConstArrayListIterator< MemberType, N, A > const_iterator
A constant random access iterator.
Definition arraylist.hh:111
std::ptrdiff_t difference_type
The difference type.
Definition arraylist.hh:121
Base class for stl conformant forward iterators.
Definition iteratorfacades.hh:433