Go to the documentation of this file.
24 template<
typename T,
class A>
27 template<
typename T,
class A>
30 template<
typename T,
class A>
40 template<
typename T,
class A=std::allocator<T> >
62 typedef typename A::template rebind<Element>::other
Allocator;
82 template<
typename T1,
typename A1>
186 inline bool empty()
const;
192 inline int size()
const;
212 Element(
const MemberType& item, Element* next_=0);
223 void deleteNext(Element* current);
238 template<
bool watchForTail>
239 void deleteNext(Element* current);
245 void insertAfter(Element* current,
const T& item);
267 template<
typename T,
class A>
277 : current_(item), list_(sllist)
281 : current_(0), list_(0)
285 : current_(other.iterator_.current_), list_(other.iterator_.list_)
294 return current_->item_;
304 return current_==other.current_;
314 return current_==other.current_;
324 return current_==other.iterator_.current_;
332 current_ = current_->next_;
343 list_->insertAfter(current_, v);
354 list_->deleteNext(current_);
367 template<
class T,
class A>
383 : current_(other.current_)
387 : current_(other.current_)
391 : current_(other.iterator_.current_)
400 return current_->item_;
410 return current_==other.current_;
418 current_ = current_->next_;
429 template<
typename T,
class A>
437 : beforeIterator_(beforeIterator), iterator_(_iterator)
441 : beforeIterator_(other.beforeIterator_), iterator_(other.iterator_)
445 : beforeIterator_(), iterator_()
464 return iterator_== other;
475 return iterator_== other;
486 return iterator_== other.iterator_;
513 beforeIterator_.insertAfter(v);
527 beforeIterator_.deleteNext();
537 template<
typename T,
typename A>
541 Iterator end = sllist.
end();
542 Iterator current= sllist.
begin();
547 os<<*current<<
" ("<<
static_cast<const void*
>(&(*current))<<
")";
550 for(; current != end; ++current)
551 os<<
", "<<*current<<
" ("<<
static_cast<const void*
>(&(*current))<<
")";
557 template<
typename T,
class A>
559 : next_(next), item_(item)
562 template<
typename T,
class A>
567 template<
typename T,
class A>
573 template<
typename T,
class A>
575 : beforeHead_(), tail_(&beforeHead_), allocator_(), size_(0)
578 assert(&beforeHead_==tail_);
579 assert(tail_->next_==0);
582 template<
typename T,
class A>
584 : beforeHead_(), tail_(&beforeHead_), allocator_(), size_(0)
589 template<
typename T,
class A>
590 template<
typename T1,
class A1>
592 : beforeHead_(), tail_(&beforeHead_), allocator_(), size_(0)
597 template<
typename T,
typename A>
600 assert(tail_==&beforeHead_);
603 Iterator iend = other.
end();
604 for(Iterator element=other.
begin(); element != iend; ++element)
607 assert(other.
size()==size());
610 template<
typename T,
class A>
616 template<
typename T,
class A>
619 if(size()!=other.
size())
622 iter != end(); ++iter, ++oiter)
628 template<
typename T,
class A>
631 if(size()==other.
size()) {
633 iter != end(); ++iter, ++oiter)
640 template<
typename T,
class A>
648 template<
typename T,
class A>
651 assert(size_>0 || tail_==&beforeHead_);
652 tail_->next_ = allocator_.allocate(1, 0);
653 assert(size_>0 || tail_==&beforeHead_);
654 tail_ = tail_->next_;
655 ::new (
static_cast<void*
>(&(tail_->item_)))T(item);
657 assert(tail_->next_==0);
661 template<
typename T,
class A>
667 bool changeTail = (current == tail_);
671 Element* tmp = current->next_;
673 assert(!changeTail || !tmp);
676 current->next_ = allocator_.allocate(1, 0);
679 allocator_.construct(current->next_, Element(item,tmp));
683 if(!current->next_->next_) {
686 tail_ = current->next_;
689 assert(!tail_->next_);
692 template<
typename T,
class A>
695 if(tail_ == &beforeHead_) {
697 beforeHead_.next_ = tail_ = allocator_.allocate(1, 0);
698 ::new(
static_cast<void*
>(&beforeHead_.next_->item_))T(item);
699 beforeHead_.next_->next_=0;
701 Element* added = allocator_.allocate(1, 0);
702 ::new(
static_cast<void*
>(&added->item_))T(item);
703 added->next_=beforeHead_.next_;
704 beforeHead_.next_=added;
706 assert(tail_->next_==0);
711 template<
typename T,
class A>
714 this->
template deleteNext<true>(current);
717 template<
typename T,
class A>
718 template<
bool watchForTail>
719 inline void SLList<T,A>::deleteNext(Element* current)
721 assert(current->next_);
722 Element* next = current->next_;
730 current->next_ = next->next_;
731 allocator_.destroy(next);
732 allocator_.deallocate(next, 1);
734 assert(!watchForTail || &beforeHead_ != tail_ || size_==0);
737 template<
typename T,
class A>
740 deleteNext(&beforeHead_);
743 template<
typename T,
class A>
746 while(beforeHead_.next_ ) {
747 this->
template deleteNext<false>(&beforeHead_);
752 tail_ = &beforeHead_;
755 template<
typename T,
class A>
758 return (&beforeHead_ == tail_);
761 template<
typename T,
class A>
767 template<
typename T,
class A>
770 return iterator(beforeHead_.next_,
this);
773 template<
typename T,
class A>
776 return const_iterator(beforeHead_.next_);
779 template<
typename T,
class A>
785 template<
typename T,
class A>
792 template<
typename T,
class A>
799 template<
typename T,
class A>
802 return const_iterator();
SLListConstIterator(const SLListModifyIterator< T, A > &other)
Definition: sllist.hh:390
SLListModifyIterator(const SLListModifyIterator< T, A > &other)
Definition: sllist.hh:440
SLListModifyIterator(SLListIterator< T, A > beforeIterator, SLListIterator< T, A > _iterator)
Definition: sllist.hh:435
SLListConstIterator< T, A > const_iterator
The constant iterator of the list.
Definition: sllist.hh:72
SLListModifyIterator< T, A > ModifyIterator
The type of the iterator capable of deletion and insertion.
Definition: sllist.hh:101
ModifyIterator endModify()
Get an iterator capable of deleting and inserting elements.
Definition: sllist.hh:786
Base class for stl conformant forward iterators.
Definition: iteratorfacades.hh:138
bool equals(const SLListModifyIterator< T, A > &other) const
Test whether another iterator is equal.
Definition: sllist.hh:484
A constant iterator for the SLList.
Definition: sllist.hh:28
SLListIterator(typename SLList< T, A >::Element *item, SLList< T, A > *sllist)
Definition: sllist.hh:275
void remove()
Delete the entry at the current position.
Definition: sllist.hh:524
A single linked list.
Definition: sllist.hh:41
SLListConstIterator(const SLListIterator< T, A > &other)
Definition: sllist.hh:382
Element * next_
The next element in the list.
Definition: sllist.hh:206
A mutable iterator for the SLList.
Definition: sllist.hh:25
void deleteNext() const
Delete the entry after the current position.
Definition: sllist.hh:351
SLList()
Constructor.
Definition: sllist.hh:574
void push_front(const MemberType &item)
Add a new entry to the beginning of the list.
Definition: sllist.hh:693
void insert(const T &v)
Insert an element at the current position.
Definition: sllist.hh:511
This file implements iterator facade classes for writing stl conformant iterators.
bool equals(const SLListConstIterator< T, A > &other) const
Test whether another iterator is equal.
Definition: sllist.hh:462
std::ostream & operator<<(std::ostream &s, const bigunsignedint< k > &x)
Definition: bigunsignedint.hh:273
bool equals(const SLListModifyIterator< T, A > &other) const
Equality test for the iterator facade.
Definition: sllist.hh:322
SLListConstIterator(typename SLList< T, A >::Element *item)
Definition: sllist.hh:378
SLListConstIterator(const SLListConstIterator< T, A > &other)
Definition: sllist.hh:386
A::template rebind< Element >::other Allocator
The allocator to use.
Definition: sllist.hh:62
void clear()
Remove all elements from the list.
Definition: sllist.hh:744
void increment()
Increment function for the iterator facade.
Definition: sllist.hh:492
T & dereference() const
Dereferencing function for the iterator facade.
Definition: sllist.hh:452
ModifyIterator beginModify()
Get an iterator capable of deleting and inserting elements.
Definition: sllist.hh:793
bool empty() const
Check whether the list is empty.
Definition: sllist.hh:756
iterator begin()
Get an iterator pointing to the first element in the list.
Definition: sllist.hh:768
void pop_front()
Remove the first item in the list.
Definition: sllist.hh:738
void push_back(const MemberType &item)
Add a new entry to the end of the list.
Definition: sllist.hh:649
SLList< T, A > & operator=(const SLList< T, A > &other)
Assignment operator.
Definition: sllist.hh:641
void increment()
Increment function for the iterator facade.
Definition: sllist.hh:416
int size() const
Get the number of elements the list contains.
Definition: sllist.hh:762
bool operator==(const SLList &sl) const
Definition: sllist.hh:617
bool equals(const SLListConstIterator< T, A > &other) const
Equality test for the iterator facade.
Definition: sllist.hh:302
SLListConstIterator()
Definition: sllist.hh:374
bool equals(const SLListIterator< T, A > &other) const
Test whether another iterator is equal.
Definition: sllist.hh:473
iterator end()
Get an iterator pointing to the end of the list.
Definition: sllist.hh:780
bool equals(const SLListConstIterator< T, A > &other) const
Equality test for the iterator facade.
Definition: sllist.hh:408
SLListModifyIterator()
Definition: sllist.hh:444
MemberType item_
The element we hold.
Definition: sllist.hh:210
A::size_type size_type
The size type.
Definition: sllist.hh:52
~SLList()
Destructor.
Definition: sllist.hh:611
A mutable iterator for the SLList.
Definition: sllist.hh:31
SLListIterator< T, A > iterator
The mutable iterator of the list.
Definition: sllist.hh:67
T & dereference() const
Dereferencing function for the iterator facade.
Definition: sllist.hh:292
SLListIterator(const SLListModifyIterator< T, A > &other)
Definition: sllist.hh:284
void insertAfter(const T &v) const
Insert an element in the underlying list after the current position.
Definition: sllist.hh:340
const T & dereference() const
Dereferencing function for the facade.
Definition: sllist.hh:398
T MemberType
The type we store.
Definition: sllist.hh:57
void increment()
Increment function for the iterator facade.
Definition: sllist.hh:330
bool operator!=(const SLList &sl) const
Definition: sllist.hh:629
bool equals(const SLListIterator< T, A > &other) const
Equality test for the iterator facade.
Definition: sllist.hh:312
SLListIterator()
Definition: sllist.hh:280
Dune namespace.
Definition: alignedallocator.hh:13