20 #define AGX_USE_AGX_LIST_IMPL 1
22 #if AGX_USE_AGX_LIST_IMPL
33 #define AGX_LIST_ITERATOR_TYPEDEFS \
34 typedef std::bidirectional_iterator_tag iterator_category; \
35 typedef T& reference; \
36 typedef const T& const_reference; \
38 typedef const T* const_pointer; \
39 typedef T value_type; \
40 typedef ptrdiff_t difference_type
42 template <
typename T >
61 template<
typename T >
70 template<
typename T >
81 template<
typename ItT,
typename Op >
94 template<
typename ItT >
100 template<
typename ItT >
106 template <
typename T >
181 return m_ptr == i.m_ptr;
185 return m_ptr != i.m_ptr;
250 return m_ptr == i.m_ptr;
254 return m_ptr == i.m_ptr;
258 return m_ptr != i.m_ptr;
262 return m_ptr != i.m_ptr;
349 return m_ptr == i.m_ptr;
353 return m_ptr != i.m_ptr;
425 return m_ptr == i.m_ptr;
429 return m_ptr != i.m_ptr;
480 : m_size( 0 ), m_end( allocate() ), m_front( m_end )
488 : m_size( 0 ), m_end( allocate() ), m_front( m_end )
499 if ( m_front == m_end && m_front !=
nullptr )
500 deallocate( m_front );
511 if (
this == &other )
529 for ( const_iterator myIt =
begin(), otherIt = other.
begin(), endIt =
end(); myIt != endIt; ++myIt, ++otherIt )
530 if ( *myIt != *otherIt )
544 iterator iend(m_end);
545 for ( ; i != iend; ++i ) {
546 if ( *i == _val )
return i;
559 iterator iend(m_end);
560 for ( ; i != iend; ++i ) {
561 if ( *i == _val )
return i;
579 inline iterator
begin() {
return iterator( m_front ); }
584 inline const_iterator
begin()
const {
return const_iterator( m_front ); }
589 inline iterator
end() {
return iterator( m_end ); }
594 inline const_iterator
end()
const {
return const_iterator( m_end ); }
599 inline reverse_iterator
rbegin() {
return reverse_iterator( m_end ); }
604 inline const_reverse_iterator
rbegin()
const {
return const_reverse_iterator( m_end ); }
609 inline reverse_iterator
rend() {
return reverse_iterator( m_front ); }
614 inline const_reverse_iterator
rend()
const {
return const_reverse_iterator( m_front ); }
624 inline bool empty()
const {
return m_size == 0; }
661 node->
m_next = _where.m_ptr;
662 _where.m_ptr->
m_prev = node;
664 if ( node->
m_prev ==
nullptr ) {
670 return iterator(node);
679 template<
typename InputIterator >
680 void insert( const_iterator _where, InputIterator _first, InputIterator _last )
682 for ( ; _first != _last; ++_first ) {
683 insert( _where, *_first );
740 inline iterator
erase( const_iterator _where )
742 if ( _where.m_ptr == m_front ) {
743 m_front = m_front->
m_next;
744 m_front->
m_prev =
nullptr;
746 deallocate( _where.m_ptr );
750 agxAssert( m_size > 0 || (m_size == 0 && m_front == m_end) );
752 return iterator(m_front);
755 _where.m_ptr->m_prev->m_next = _where.m_ptr->m_next;
756 _where.m_ptr->m_next->m_prev = _where.m_ptr->m_prev;
760 deallocate( _where.m_ptr );
765 return iterator(ret);
773 template<
typename Pred >
778 while ( node != m_end ) {
780 node =
erase( const_iterator( node ) ).m_ptr;
801 template<
typename Pred >
804 if (
this != &other ) {
805 iterator myIt =
begin();
806 iterator myEnd =
end();
808 const_iterator otherIt = other.
begin();
809 const_iterator otherEnd = other.
end();
811 while ( myIt != myEnd && otherIt != otherEnd ) {
812 if ( pred( *otherIt, *myIt ) ) {
813 const_iterator otherNext = otherIt;
814 splice( myIt, other, otherIt, ++otherNext, 1 );
820 if ( otherIt != otherEnd )
821 splice( myEnd, other, otherIt, otherEnd, other.m_size );
834 merge( other, LessPred2() );
841 template<
typename Pred >
847 const const_iterator endIt =
end();
848 iterator curr =
begin();
849 iterator prev = curr++;
850 while ( curr != endIt ) {
853 if ( pred( *prev, *curr ) )
854 curr = ++
erase( curr );
882 if ( node == m_end ) {
885 m_front->
m_prev =
nullptr;
899 std::swap( m_front, other.m_front );
900 std::swap( m_end, other.m_end );
901 std::swap( m_size, other.m_size );
907 template<
typename Pred >
915 my_type binList[ MAXBINS + 1 ];
922 for ( ; bin < maxBin && !binList[ bin ].
empty(); ++bin ) {
923 binList[ bin ].
merge( tmpList, pred );
924 binList[ bin ].
swap( tmpList );
927 if ( bin == MAXBINS )
928 binList[ bin - 1 ].
merge( tmpList, pred );
930 binList[ bin ].
swap( tmpList );
935 for (
size_type bin = 1; bin < maxBin; ++bin )
936 binList[ bin ].
merge( binList[ bin - 1 ], pred );
938 splice(
end(), binList[ maxBin - 1 ], binList[ maxBin - 1 ].
begin(), binList[ maxBin - 1 ].
end(), binList[ maxBin - 1 ].
size() );
954 if (
this != &other ) {
956 other.m_size -= count;
960 if ( first.m_ptr->m_prev ==
nullptr )
961 other.m_front = last.m_ptr;
967 if ( _where.m_ptr->m_prev ==
nullptr )
968 m_front = first.m_ptr;
975 first.m_ptr->
m_prev = node;
996 void splice( const_iterator _where,
my_type& other, const_iterator first, const_iterator last )
999 if ( first == other.
begin() && last == other.
end() )
1000 count = other.
size();
1001 else for ( const_iterator i = first; i != last; ++i, ++count )
1003 splice( _where, other, first, last, count );
1011 sort( LessPred2() );
1039 template<
typename T >
1040 class List :
public std::list< T > {};
bool operator()(const_reference obj) const
bool operator==(const my_type &other) const
Comparison of lists of same size.
AGX_LIST_ITERATOR_TYPEDEFS
iterator(const iterator &rhs)
bool operator()(const_reference left, const_reference right) const
void sort(Pred pred)
Sorts the content in this list given pred.
AGX_LIST_ITERATOR_TYPEDEFS
LNode< T > & node_ref_type
const_reverse_iterator(const const_iterator &rhs)
iterator operator+(const agx::ItOp &inc) const
AGX_LIST_ITERATOR_TYPEDEFS
const_reverse_iterator operator-(const agx::ItOp &inc) const
reverse_iterator(const iterator &rhs)
const_pointer operator->() const
List(const List &other)
Copy constructor.
reverse_iterator(node_ptr_type ptr)
void swap(my_type &other)
Swap this with other.
pointer operator->() const
void remove_if(Pred pred)
Erase (all) elements matching pred.
LNode< T > * node_ptr_type
reverse_iterator & operator=(const const_reverse_iterator &rhs)
reverse_iterator operator-(const agx::ItOp &inc) const
const_iterator & operator=(const const_iterator &rhs)
bool operator!=(const iterator &i) const
void pop_back()
Remove last element in this list.
void push_front(const_reference c_ref)
Add element to the front of this list.
iterator operator-(const agx::ItOp &inc) const
const_iterator operator-(const agx::ItOp &inc) const
bool operator==(const iterator &i) const
T & operator()(T &val) const
const_iterator begin() const
void sort()
Sorts the content in this list given operator<.
EqualPred1(const_reference obj)
void merge(my_type &other, Pred pred)
Merge in elements from other, both this and other are ordered by pred.
const_iterator operator+(const agx::ItOp &inc) const
const_reference front() const
reverse_iterator & operator++()
const_iterator(node_ptr_type ptr)
bool operator==(const const_iterator &i) const
reverse_iterator rbegin()
const_reverse_iterator(const const_reverse_iterator &rhs)
const_iterator operator++(int)
const_reference operator*() const
bool operator==(const const_iterator &i) const
void pop_front()
Remove first element in this list.
AgXString< T > operator+(const Indentation &indentation, const AgXString< T > &str)
iterator insert(const_iterator _where, const_reference c_ref)
Insert an element c_ref before _where.
const_reverse_iterator & operator=(const const_iterator &rhs)
void merge(my_type &other)
Merge in elements from other, both this and other are ordered by operator<.
const_reverse_iterator operator--(int)
bool operator!=(const const_iterator &i) const
reference operator*() const
iterator(node_ptr_type ptr)
const_iterator & operator--()
void insert(const_iterator _where, InputIterator _first, InputIterator _last)
Insert N elements before _where.
const_pointer operator->() const
const T & const_reference
const_reference operator*() const
bool operator==(const const_reverse_iterator &i) const
bool operator!=(const const_reverse_iterator &i) const
reference operator*() const
List()
Default constructor, size zero and begin() == end().
reverse_iterator operator--(int)
bool contains(const_reference _val)
Check if a value _val is part of this list (at least one time).
void clear()
Clear this list of all elements.
ItT operator-(const ItT &it, const agx::ItOp &inc)
const_reverse_iterator & operator++()
reverse_iterator & operator=(const iterator &rhs)
const_reverse_iterator(node_ptr_type ptr)
const_iterator operator--(int)
const_reverse_iterator & operator=(const iterator &rhs)
void splice(const_iterator _where, my_type &other)
Splice other [other.begin(), other.end()) at _where.
const_reference back() const
const_reverse_iterator rbegin() const
bool operator==(const reverse_iterator &i) const
iterator find(const_reference _val)
Find iterator to FIRST element with value _val.
const_reverse_iterator & operator=(const const_reverse_iterator &rhs)
reverse_iterator(const reverse_iterator &rhs)
reverse_iterator operator++(int)
const_reverse_iterator operator+(const agx::ItOp &inc) const
const_iterator find(const_reference _val) const
Find iterator to FIRST element with value _val.
List & operator=(const my_type &other)
Assignment operator.
const_iterator & operator++()
bool operator()(const_reference left, const_reference right) const
reverse_iterator & operator--()
bool operator!=(const const_iterator &i) const
iterator & operator=(const iterator &rhs)
const_reverse_iterator(const iterator &rhs)
const_iterator end() const
void reverse()
Reverse sequence.
iterator erase(const_iterator _where)
Erase element at _where.
const_iterator(const const_iterator &rhs)
LessPred1(const_reference obj)
bool operator!=(const reverse_iterator &i) const
const_reverse_iterator & operator--()
void splice(const_iterator _where, my_type &other, const_iterator first, const_iterator last)
Splice other [first, last) at _where.
AGX_LIST_ITERATOR_TYPEDEFS
const_reverse_iterator operator++(int)
void splice(const_iterator _where, my_type &other, const_iterator first, const_iterator last, size_type count)
Splice other [first, last) at _where.
T & operator()(T &val) const
void unique(Pred pred)
Erases each element satisfying pred with previous.
bool operator()(const_reference obj) const
void unique()
Erases each element satisfying operator== with previous.
ItT operator()(const ItT &org, Op op) const
pointer operator->() const
const_reverse_iterator rend() const
void push_back(const_reference c_ref)
Add element to the back of this list.
reverse_iterator operator+(const agx::ItOp &inc) const