25 template<
typename T,
class A>
28 template<
typename T,
class A>
31 template<
typename T,
class A>
41 template<
typename T,
class A=std::allocator<T> >
63 typedef typename A::template rebind<Element>::other
Allocator;
83 template<
typename T1,
typename A1>
187 inline bool empty()
const;
193 inline int size()
const;
213 Element(
const MemberType& item, Element* next_=0);
224 void deleteNext(Element* current);
239 template<
bool watchForTail>
240 void deleteNext(Element* current);
246 void insertAfter(Element* current,
const T& item);
268 template<
typename T,
class A>
278 : current_(item), list_(sllist)
282 : current_(0), list_(0)
286 : current_(other.iterator_.current_), list_(other.iterator_.list_)
295 return current_->item_;
305 return current_==other.current_;
315 return current_==other.current_;
325 return current_==other.iterator_.current_;
333 current_ = current_->next_;
344 list_->insertAfter(current_, v);
355 list_->deleteNext(current_);
368 template<
class T,
class A>
384 : current_(other.current_)
388 : current_(other.current_)
392 : current_(other.iterator_.current_)
401 return current_->item_;
411 return current_==other.current_;
419 current_ = current_->next_;
430 template<
typename T,
class A>
438 : beforeIterator_(beforeIterator), iterator_(_iterator)
442 : beforeIterator_(other.beforeIterator_), iterator_(other.iterator_)
446 : beforeIterator_(), iterator_()
465 return iterator_== other;
476 return iterator_== other;
487 return iterator_== other.iterator_;
514 beforeIterator_.insertAfter(v);
528 beforeIterator_.deleteNext();
542 template<
typename T,
typename A>
543 ostream& operator<<(ostream& os, const Dune::SLList<T,A> sllist)
546 Iterator end = sllist.end();
547 Iterator current= sllist.begin();
552 os<<*current<<
" ("<<
static_cast<const void*
>(&(*current))<<
")";
555 for(; current != end; ++current)
556 os<<
", "<<*current<<
" ("<<static_cast<const void*>(&(*current))<<
")";
566 template<
typename T,
class A>
568 : next_(next), item_(item)
571 template<
typename T,
class A>
576 template<
typename T,
class A>
582 template<
typename T,
class A>
584 : beforeHead_(), tail_(&beforeHead_), allocator_(), size_(0)
587 assert(&beforeHead_==tail_);
588 assert(tail_->next_==0);
591 template<
typename T,
class A>
593 : beforeHead_(), tail_(&beforeHead_), allocator_(),
size_(0)
598 template<
typename T,
class A>
599 template<
typename T1,
class A1>
601 : beforeHead_(), tail_(&beforeHead_), allocator_(),
size_(0)
606 template<
typename T,
typename A>
609 assert(tail_==&beforeHead_);
612 Iterator iend = other.
end();
613 for(Iterator element=other.
begin(); element != iend; ++element)
616 assert(other.
size()==size());
619 template<
typename T,
class A>
625 template<
typename T,
class A>
628 if(size()!=other.
size())
631 iter != end(); ++iter, ++oiter)
637 template<
typename T,
class A>
640 if(size()==other.
size()) {
642 iter != end(); ++iter, ++oiter)
649 template<
typename T,
class A>
657 template<
typename T,
class A>
660 assert(
size_>0 || tail_==&beforeHead_);
661 tail_->next_ = allocator_.allocate(1, 0);
662 assert(
size_>0 || tail_==&beforeHead_);
663 tail_ = tail_->next_;
664 ::new (static_cast<void*>(&(tail_->item_)))T(item);
666 assert(tail_->next_==0);
670 template<
typename T,
class A>
676 bool changeTail = (current == tail_);
682 assert(!changeTail || !tmp);
685 current->next_ = allocator_.allocate(1, 0);
688 allocator_.construct(current->next_,
Element(item,tmp));
692 if(!current->next_->next_) {
695 tail_ = current->next_;
698 assert(!tail_->next_);
701 template<
typename T,
class A>
704 if(tail_ == &beforeHead_) {
706 beforeHead_.next_ = tail_ = allocator_.allocate(1, 0);
707 ::new(static_cast<void*>(&beforeHead_.next_->item_))T(item);
708 beforeHead_.next_->next_=0;
710 Element* added = allocator_.allocate(1, 0);
711 ::new(static_cast<void*>(&added->item_))T(item);
712 added->next_=beforeHead_.next_;
713 beforeHead_.next_=added;
715 assert(tail_->next_==0);
720 template<
typename T,
class A>
723 this->
template deleteNext<true>(current);
726 template<
typename T,
class A>
727 template<
bool watchForTail>
728 inline void SLList<T,A>::deleteNext(Element* current)
730 assert(current->next_);
731 Element* next = current->next_;
739 current->next_ = next->next_;
740 allocator_.destroy(next);
741 allocator_.deallocate(next, 1);
743 assert(!watchForTail || &beforeHead_ != tail_ ||
size_==0);
746 template<
typename T,
class A>
749 deleteNext(&beforeHead_);
752 template<
typename T,
class A>
755 while(beforeHead_.next_ ) {
756 this->
template deleteNext<false>(&beforeHead_);
761 tail_ = &beforeHead_;
764 template<
typename T,
class A>
767 return (&beforeHead_ == tail_);
770 template<
typename T,
class A>
776 template<
typename T,
class A>
779 return iterator(beforeHead_.next_,
this);
782 template<
typename T,
class A>
788 template<
typename T,
class A>
794 template<
typename T,
class A>
801 template<
typename T,
class A>
808 template<
typename T,
class A>
SLListConstIterator< T, A > const_iterator
The constant iterator of the list.
Definition: sllist.hh:73
void pop_front()
Remove the first item in the list.
Definition: sllist.hh:747
bool equals(const SLListModifyIterator< T, A > &other) const
Test whether another iterator is equal.
Definition: sllist.hh:485
SLListIterator(const SLListModifyIterator< T, A > &other)
Definition: sllist.hh:285
iterator end()
Get an iterator pointing to the end of the list.
Definition: sllist.hh:789
bool equals(const SLListModifyIterator< T, A > &other) const
Equality test for the iterator facade.
Definition: sllist.hh:323
int size() const
Get the number of elements the list contains.
Definition: sllist.hh:771
SLListModifyIterator()
Definition: sllist.hh:445
void deleteNext() const
Delete the entry after the current position.
Definition: sllist.hh:352
void increment()
Increment function for the iterator facade.
Definition: sllist.hh:331
SLListModifyIterator< T, A > ModifyIterator
The type of the iterator capable of deletion and insertion.
Definition: sllist.hh:102
bool empty() const
Check whether the list is empty.
Definition: sllist.hh:765
SLListModifyIterator(SLListIterator< T, A > beforeIterator, SLListIterator< T, A > _iterator)
Definition: sllist.hh:436
This file implements iterator facade classes for writing stl conformant iterators.
SLListConstIterator(typename SLList< T, A >::Element *item)
Definition: sllist.hh:379
A::template rebind< Element >::other Allocator
The allocator to use.
Definition: sllist.hh:63
void push_back(const MemberType &item)
Add a new entry to the end of the list.
Definition: sllist.hh:658
SLListConstIterator(const SLListConstIterator< T, A > &other)
Definition: sllist.hh:387
MemberType item_
The element we hold.
Definition: sllist.hh:211
bool operator==(const SLList &sl) const
Definition: sllist.hh:626
bool equals(const SLListConstIterator< T, A > &other) const
Test whether another iterator is equal.
Definition: sllist.hh:463
const T & dereference() const
Dereferencing function for the facade.
Definition: sllist.hh:399
A mutable iterator for the SLList.
Definition: sllist.hh:32
void insertAfter(const T &v) const
Insert an element in the underlying list after the current position.
Definition: sllist.hh:341
void increment()
Increment function for the iterator facade.
Definition: sllist.hh:493
A::size_type size_type
The size type.
Definition: sllist.hh:53
ModifyIterator beginModify()
Get an iterator capable of deleting and inserting elements.
Definition: sllist.hh:802
SLListConstIterator()
Definition: sllist.hh:375
bool equals(const SLListIterator< T, A > &other) const
Test whether another iterator is equal.
Definition: sllist.hh:474
Element * next_
The next element in the list.
Definition: sllist.hh:207
SLList< T, A > & operator=(const SLList< T, A > &other)
Assignment operator.
Definition: sllist.hh:650
bool equals(const SLListConstIterator< T, A > &other) const
Equality test for the iterator facade.
Definition: sllist.hh:409
void push_front(const MemberType &item)
Add a new entry to the beginning of the list.
Definition: sllist.hh:702
void insert(const T &v)
Insert an element at the current position.
Definition: sllist.hh:512
bool operator!=(const SLList &sl) const
Definition: sllist.hh:638
T MemberType
The type we store.
Definition: sllist.hh:58
Base class for stl conformant forward iterators.
Definition: iteratorfacades.hh:136
iterator begin()
Get an iterator pointing to the first element in the list.
Definition: sllist.hh:777
SLListConstIterator(const SLListModifyIterator< T, A > &other)
Definition: sllist.hh:391
void clear()
Remove all elements from the list.
Definition: sllist.hh:753
bool equals(const SLListConstIterator< T, A > &other) const
Equality test for the iterator facade.
Definition: sllist.hh:303
bool equals(const SLListIterator< T, A > &other) const
Equality test for the iterator facade.
Definition: sllist.hh:313
std::size_t size_
The size of the buffer.
Definition: variablesizecommunicator.hh:132
T & dereference() const
Dereferencing function for the iterator facade.
Definition: sllist.hh:453
T & dereference() const
Dereferencing function for the iterator facade.
Definition: sllist.hh:293
Get the N-th element of a tuple.
Definition: tuples.hh:457
A mutable iterator for the SLList.
Definition: sllist.hh:26
SLListIterator(typename SLList< T, A >::Element *item, SLList< T, A > *sllist)
Definition: sllist.hh:276
A single linked list.
Definition: sllist.hh:42
void increment()
Increment function for the iterator facade.
Definition: sllist.hh:417
SLListModifyIterator(const SLListModifyIterator< T, A > &other)
Definition: sllist.hh:441
SLList()
Constructor.
Definition: sllist.hh:583
SLListIterator()
Definition: sllist.hh:281
SLListConstIterator(const SLListIterator< T, A > &other)
Definition: sllist.hh:383
~SLList()
Destructor.
Definition: sllist.hh:620
A constant iterator for the SLList.
Definition: sllist.hh:29
SLListIterator< T, A > iterator
The mutable iterator of the list.
Definition: sllist.hh:68
ModifyIterator endModify()
Get an iterator capable of deleting and inserting elements.
Definition: sllist.hh:795