5 #ifndef DUNE_ARRAYLIST_HH
6 #define DUNE_ARRAYLIST_HH
17 template<
class T,
int N,
class A>
20 template<
class T,
int N,
class A>
59 template<
class T,
int N=100,
class A=std::allocator<T> >
135 const_iterator
begin()
const;
147 const_iterator
end()
const;
153 inline void push_back(const_reference entry);
167 inline const_reference
operator[](size_type i)
const;
173 inline size_type
size()
const;
198 typedef typename A::template rebind<shared_ptr<array<MemberType,chunkSize_> > >::other
199 SmartPointerAllocator;
204 typedef typename A::template rebind<array<MemberType,chunkSize_> >::other
214 std::vector<shared_ptr<array<MemberType,chunkSize_> >,
215 SmartPointerAllocator> chunks_;
237 inline reference elementAt(size_type i);
247 inline const_reference elementAt(size_type i)
const;
254 template<
class T,
int N,
class A>
256 typename A::value_type,
257 typename A::reference,
258 typename A::difference_type>
305 inline void increment();
310 inline void decrement();
316 inline reference elementAt(size_type i)
const;
322 inline reference dereference()
const;
335 inline void eraseToHere();
341 inline void advance(difference_type n);
374 template<
class T,
int N,
class A>
375 class ConstArrayListIterator
376 :
public RandomAccessIteratorFacade<ConstArrayListIterator<T,N,A>,
377 const typename A::value_type,
378 typename A::const_reference,
379 typename A::difference_type>
418 inline void increment();
423 inline void decrement();
426 inline void advance(difference_type n);
435 inline const_reference elementAt(size_type i)
const;
441 inline const_reference dereference()
const;
470 template<
class T,
int N,
class A>
472 : capacity_(0),
size_(0), start_(0)
474 chunks_.reserve(100);
477 template<
class T,
int N,
class A>
485 template<
class T,
int N,
class A>
491 template<
class T,
int N,
class A>
494 size_t index=start_+
size_;
498 capacity_ += chunkSize_;
500 elementAt(index)=entry;
504 template<
class T,
int N,
class A>
507 return elementAt(start_+i);
511 template<
class T,
int N,
class A>
514 return elementAt(start_+i);
517 template<
class T,
int N,
class A>
520 return chunks_[i/chunkSize_]->operator[](i%chunkSize_);
524 template<
class T,
int N,
class A>
525 typename ArrayList<T,N,A>::const_reference ArrayList<T,N,A>::elementAt(size_type i)
const
527 return chunks_[i/chunkSize_]->operator[](i%chunkSize_);
530 template<
class T,
int N,
class A>
536 template<
class T,
int N,
class A>
542 template<
class T,
int N,
class A>
548 template<
class T,
int N,
class A>
554 template<
class T,
int N,
class A>
558 size_t distance = start_/chunkSize_;
561 size_t chunks = ((start_%chunkSize_ +
size_)/chunkSize_ );
564 std::copy(chunks_.begin()+distance,
565 chunks_.begin()+(distance+chunks), chunks_.begin());
568 start_ = start_ % chunkSize_;
573 template<
class T,
int N,
class A>
579 template<
class T,
int N,
class A>
586 template<
class T,
int N,
class A>
590 assert(list_==(other.list_));
595 template<
class T,
int N,
class A>
599 assert(list_==(other.list_));
604 template<
class T,
int N,
class A>
608 assert(list_==(other.list_));
612 template<
class T,
int N,
class A>
618 template<
class T,
int N,
class A>
624 template<
class T,
int N,
class A>
630 template<
class T,
int N,
class A>
636 template<
class T,
int N,
class A>
642 template<
class T,
int N,
class A>
648 template<
class T,
int N,
class A>
654 template<
class T,
int N,
class A>
660 template<
class T,
int N,
class A>
664 assert(list_==(other.list_));
668 template<
class T,
int N,
class A>
672 assert(list_==(other.list_));
676 template<
class T,
int N,
class A>
684 template<
class T,
int N,
class A>
692 template<
class T,
int N,
class A>
695 list_->size_ -= ++
position_ - list_->start_;
697 size_t posChunkStart =
position_ / chunkSize_;
699 size_t chunks = (
position_ - list_->start_ + list_->start_ % chunkSize_)
704 for(
size_t chunk=0; chunk<chunks; chunk++) {
706 list_->chunks_[posChunkStart].reset();
711 assert(list_->start_+list_->size_<=list_->capacity_);
714 template<
class T,
int N,
class A>
720 template<
class T,
int N,
class A>
726 template<
class T,
int N,
class A>
difference_type distanceTo(const ConstArrayListIterator< T, N, A > &other) const
Definition: arraylist.hh:669
T & reference
The type of a reference to the type we store.
Definition: arraylist.hh:78
A::size_type size_type
Definition: arraylist.hh:393
std::size_t size_type
The size type.
Definition: arraylist.hh:117
const ConstArrayListIterator< T, N, A > & operator=(const ConstArrayListIterator< T, N, A > &other)
Definition: arraylist.hh:685
iterator end()
Get a random access iterator positioned after the last element.
Definition: arraylist.hh:543
Dune namespace.
Definition: alignment.hh:13
difference_type distanceTo(const ArrayListIterator< T, N, A > &other) const
Definition: arraylist.hh:661
bool equals(const ConstArrayListIterator< MemberType, N, A > &other) const
Comares to iterators.
Definition: arraylist.hh:605
T value_type
Value type for stl compliance.
Definition: arraylist.hh:73
const_reference dereference() const
Access the element at the current position.
Definition: arraylist.hh:655
size_type position()
Definition: arraylist.hh:338
void advance(difference_type n)
Definition: arraylist.hh:580
std::size_t size_
The size of the buffer.
Definition: variablesizecommunicator.hh:132
void eraseToHere()
Erase all entries before the current position and the one at the current position.
Definition: arraylist.hh:693
A constant random access iterator for the Dune::ArrayList class.
Definition: arraylist.hh:21
A::difference_type difference_type
Definition: arraylist.hh:391
ArrayList()
Constructs an Array list with one chunk.
Definition: arraylist.hh:471
const_reference elementAt(size_type i) const
Get the value of the list at an arbitrary position.
Definition: arraylist.hh:643
std::size_t position_
The current position in the buffer.
Definition: variablesizecommunicator.hh:136
A::reference reference
Definition: arraylist.hh:273
A::reference reference
Definition: arraylist.hh:395
std::ptrdiff_t difference_type
The difference type.
Definition: arraylist.hh:122
T MemberType
The member type that is stored.
Definition: arraylist.hh:68
reference operator[](size_type i)
Get the element at specific position.
Definition: arraylist.hh:505
size_type size() const
Get the number of elements in the list.
Definition: arraylist.hh:486
void decrement()
decrement the iterator.
Definition: arraylist.hh:625
The number of elements in one chunk of the list. This has to be at least one. The default is 100...
Definition: arraylist.hh:101
bool equals(const ArrayListIterator< MemberType, N, A > &other) const
Comares two iterators.
Definition: arraylist.hh:587
ArrayListIterator< T, N, A > & operator=(const ArrayListIterator< T, N, A > &other)
Definition: arraylist.hh:677
void increment()
Increment the iterator.
Definition: arraylist.hh:613
A::value_type MemberType
The member type.
Definition: arraylist.hh:267
A::const_reference const_reference
Definition: arraylist.hh:275
A::difference_type difference_type
Definition: arraylist.hh:269
This file implements the class shared_ptr (a reference counting pointer), for those systems that don'...
ConstArrayListIterator()
Definition: arraylist.hh:445
void increment()
Increment the iterator.
Definition: arraylist.hh:619
A random access iterator for the Dune::ArrayList class.
Definition: arraylist.hh:18
Fallback implementation of the std::array class (a static array)
A::const_reference const_reference
Definition: arraylist.hh:397
void push_back(const_reference entry)
Append an entry to the list.
Definition: arraylist.hh:492
void purge()
Purge the list.
Definition: arraylist.hh:555
ArrayListIterator()
Standard constructor.
Definition: arraylist.hh:350
A reference counting smart pointer.
Definition: shared_ptr.hh:63
A::size_type size_type
Definition: arraylist.hh:271
ConstArrayListIterator< MemberType, N, A > const_iterator
A constant random access iterator.
Definition: arraylist.hh:112
const T & const_reference
The type of a const reference to the type we store.
Definition: arraylist.hh:83
iterator begin()
Get an iterator that is positioned at the first element.
Definition: arraylist.hh:531
const T * const_pointer
The type of a const pointer to the type we store.
Definition: arraylist.hh:93
ArrayListIterator< MemberType, N, A > iterator
A random access iterator.
Definition: arraylist.hh:107
Base class for stl conformant forward iterators.
Definition: iteratorfacades.hh:425
T * pointer
The type of a pointer to the type we store.
Definition: arraylist.hh:88
A::value_type MemberType
The member type.
Definition: arraylist.hh:389
reference dereference() const
Access the element at the current position.
Definition: arraylist.hh:649
void advance(difference_type n)
Definition: arraylist.hh:574
This file implements iterator facade classes for writing stl conformant iterators.
void decrement()
decrement the iterator.
Definition: arraylist.hh:631
reference elementAt(size_type i) const
Get the value of the list at an arbitrary position.
Definition: arraylist.hh:637
A dynamically growing random access list.
Definition: arraylist.hh:60
void clear()
Delete all entries from the list.
Definition: arraylist.hh:478