4 #ifndef DUNE_ARRAYLIST_HH
5 #define DUNE_ARRAYLIST_HH
16 template<
class T,
int N,
class A>
19 template<
class T,
int N,
class A>
58 template<
class T,
int N=100,
class A=std::allocator<T> >
134 const_iterator
begin()
const;
146 const_iterator
end()
const;
172 inline size_type
size()
const;
197 typedef typename A::template rebind<shared_ptr<array<MemberType,chunkSize_> > >::other
198 SmartPointerAllocator;
203 typedef typename A::template rebind<array<MemberType,chunkSize_> >::other
213 std::vector<shared_ptr<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>
304 inline void increment();
309 inline void decrement();
334 inline void eraseToHere();
373 template<
class T,
int N,
class A>
374 class ConstArrayListIterator
375 :
public RandomAccessIteratorFacade<ConstArrayListIterator<T,N,A>,
376 const typename A::value_type,
377 typename A::const_reference,
378 typename A::difference_type>
417 inline void increment();
422 inline void decrement();
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(shared_ptr<array<MemberType,chunkSize_> >(
new 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_));
594 template<
class T,
int N,
class A>
598 assert(list_==(other.list_));
603 template<
class T,
int N,
class A>
607 assert(list_==(other.list_));
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>
641 template<
class T,
int N,
class A>
647 template<
class T,
int N,
class A>
653 template<
class T,
int N,
class A>
659 template<
class T,
int N,
class A>
663 assert(list_==(other.list_));
667 template<
class T,
int N,
class A>
671 assert(list_==(other.list_));
675 template<
class T,
int N,
class A>
683 template<
class T,
int N,
class A>
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_)
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>
719 template<
class T,
int N,
class A>
725 template<
class T,
int N,
class A>
ArrayListIterator()
Standard constructor.
Definition: arraylist.hh:349
std::size_t size_type
The size type.
Definition: arraylist.hh:116
A::value_type MemberType
The member type.
Definition: arraylist.hh:388
iterator end()
Get a random access iterator positioned after the last element.
Definition: arraylist.hh:542
std::ptrdiff_t difference_type
The difference type.
Definition: arraylist.hh:121
T & reference
The type of a reference to the type we store.
Definition: arraylist.hh:77
reference dereference() const
Access the element at the current position.
Definition: arraylist.hh:648
void advance(difference_type n)
Definition: arraylist.hh:573
size_type position()
Definition: arraylist.hh:337
Base class for stl conformant forward iterators.
Definition: iteratorfacades.hh:424
This file implements iterator facade classes for writing stl conformant iterators.
ArrayList()
Constructs an Array list with one chunk.
Definition: arraylist.hh:470
const_reference elementAt(size_type i) const
Get the value of the list at an arbitrary position.
Definition: arraylist.hh:642
void decrement()
decrement the iterator.
Definition: arraylist.hh:624
A::difference_type difference_type
Definition: arraylist.hh:268
void clear()
Delete all entries from the list.
Definition: arraylist.hh:477
difference_type distanceTo(const ArrayListIterator< T, N, A > &other) const
Definition: arraylist.hh:660
A::reference reference
Definition: arraylist.hh:394
difference_type distanceTo(const ConstArrayListIterator< T, N, A > &other) const
Definition: arraylist.hh:668
A random access iterator for the Dune::ArrayList class.
Definition: arraylist.hh:17
Fallback implementation of the std::array class (a static array)
void advance(difference_type n)
Definition: arraylist.hh:579
T value_type
Value type for stl compliance.
Definition: arraylist.hh:72
T MemberType
The member type that is stored.
Definition: arraylist.hh:67
void push_back(const_reference entry)
Append an entry to the list.
Definition: arraylist.hh:491
void purge()
Purge the list.
Definition: arraylist.hh:554
A::size_type size_type
Definition: arraylist.hh:270
A::difference_type difference_type
Definition: arraylist.hh:390
bool equals(const ConstArrayListIterator< MemberType, N, A > &other) const
Comares to iterators.
Definition: arraylist.hh:604
std::size_t size_
The size of the buffer.
Definition: variablesizecommunicator.hh:132
const T * const_pointer
The type of a const pointer to the type we store.
Definition: arraylist.hh:92
void eraseToHere()
Erase all entries before the current position and the one at the current position.
Definition: arraylist.hh:692
A::size_type size_type
Definition: arraylist.hh:392
A dynamically growing random access list.
Definition: arraylist.hh:59
This file implements the class shared_ptr (a reference counting pointer), for those systems that don'...
bool equals(const ArrayListIterator< MemberType, N, A > &other) const
Comares two iterators.
Definition: arraylist.hh:586
void decrement()
decrement the iterator.
Definition: arraylist.hh:630
iterator begin()
Get an iterator that is positioned at the first element.
Definition: arraylist.hh:530
ArrayListIterator< T, N, A > & operator=(const ArrayListIterator< T, N, A > &other)
Definition: arraylist.hh:676
A::const_reference const_reference
Definition: arraylist.hh:274
A constant random access iterator for the Dune::ArrayList class.
Definition: arraylist.hh:20
const ConstArrayListIterator< T, N, A > & operator=(const ConstArrayListIterator< T, N, A > &other)
Definition: arraylist.hh:684
void increment()
Increment the iterator.
Definition: arraylist.hh:618
A::value_type MemberType
The member type.
Definition: arraylist.hh:266
A::reference reference
Definition: arraylist.hh:272
ConstArrayListIterator()
Definition: arraylist.hh:444
size_type size() const
Get the number of elements in the list.
Definition: arraylist.hh:485
A pair consisting of a global and local index.
Definition: indexset.hh:30
reference elementAt(size_type i) const
Get the value of the list at an arbitrary position.
Definition: arraylist.hh:636
const_reference dereference() const
Access the element at the current position.
Definition: arraylist.hh:654
std::size_t position_
The current position in the buffer.
Definition: variablesizecommunicator.hh:136
ArrayListIterator< MemberType, N, A > iterator
A random access iterator.
Definition: arraylist.hh:106
reference operator[](size_type i)
Get the element at specific position.
Definition: arraylist.hh:504
T * pointer
The type of a pointer to the type we store.
Definition: arraylist.hh:87
A::const_reference const_reference
Definition: arraylist.hh:396
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
ConstArrayListIterator< MemberType, N, A > const_iterator
A constant random access iterator.
Definition: arraylist.hh:111
const T & const_reference
The type of a const reference to the type we store.
Definition: arraylist.hh:82
void increment()
Increment the iterator.
Definition: arraylist.hh:612