Base Framework
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Related Functions | List of all members
List< TYPE > Class Template Reference

List collection. More...

#include <base/collection/List.h>

Inherits Collection.

Classes

class  ListImpl
 

Public Types

typedef TYPE Value
 
typedef DoubleLinkedNode< ValueNode
 
typedef DoubleLinkedNodeIterator< TYPE > Iterator
 
typedef DoubleLinkedNodeReadIterator< TYPE > ReadIterator
 
typedef DoubleLinkedNodeEnumerator< EnumeratorTraits< TYPE > > Enumerator
 
typedef DoubleLinkedNodeReadEnumerator< ReadEnumeratorTraits< TYPE > > ReadEnumerator
 

Public Member Functions

 List ()
 
 List (std::initializer_list< TYPE > values)
 
 List (const List &copy) noexcept
 
Listoperator= (const List &copy) noexcept
 
Listoperator= (List &&move) noexcept
 
MemorySize getSize () const noexcept
 
bool isEmpty () const noexcept
 
TYPE & getFirst ()
 
const TYPE & getFirst () const
 
TYPE & getLast ()
 
const TYPE & getLast () const
 
Enumerator getEnumerator ()
 
ReadEnumerator getReadEnumerator () const noexcept
 
Iterator begin ()
 
Iterator end ()
 
ReadIterator begin () const noexcept
 
ReadIterator end () const noexcept
 
ReadIterator cbegin () const noexcept
 
ReadIterator cend () const noexcept
 
 operator ForwardIterable< Iterator > () noexcept
 
void append (const TYPE &value)
 
void append (TYPE &&value)
 
void add (const TYPE &value)
 
void add (TYPE &&value)
 
void prepend (const TYPE &value)
 
void prepend (TYPE &&value)
 
void insert (const Iterator &it, const TYPE &value)
 
void insert (const Iterator &it, TYPE &&value)
 
void remove (const Iterator &it)
 
void moveToFront (const Iterator &it)
 
void moveToBack (const Iterator &it)
 
void removeFirst ()
 
void removeLast ()
 
void removeAll ()
 
void sort ()
 
template<class PREDICATE >
void sort (PREDICATE predicate)
 
void shuffle ()
 
bool operator== (const List &compare) const
 
bool operator!= (const List &compare) const
 
bool operator< (const List &compare) const
 
bool operator>= (const List &compare) const
 
 operator bool () const noexcept
 
Listoperator<< (const TYPE &value)
 
Listoperator<< (TYPE &&value)
 

Protected Member Functions

NodegetFirstNode ()
 
const NodegetFirstNode () const noexcept
 
NodegetLastNode ()
 
const NodegetLastNode () const noexcept
 

Protected Attributes

Reference< ListImplelements
 

Related Functions

(Note that these are not member functions.)

template<class TYPE >
FormatOutputStreamoperator<< (FormatOutputStream &stream, const List< TYPE > &value)
 

Detailed Description

template<class TYPE>
class List< TYPE >

List collection.

Linked list data structure. Use of List reduces copying of elements.

You can enumerate the elements of a list like this (myMember is a member function of MyClass):

while (enu.hasNext()) {
enu.next()->myMember();
}
Examples
testsuite/client.cpp, testsuite/echod.cpp, testsuite/ftp.cpp, testsuite/http.cpp, testsuite/List.cpp, and testsuite/server.cpp.

Member Typedef Documentation

◆ Node

template<class TYPE >
typedef DoubleLinkedNode<Value> List< TYPE >::Node

The type of a node.

◆ Value

template<class TYPE >
typedef TYPE List< TYPE >::Value

The type of a value.

Constructor & Destructor Documentation

◆ List() [1/3]

template<class TYPE >
List< TYPE >::List ( )
inline

Initializes an empty list.

◆ List() [2/3]

template<class TYPE >
List< TYPE >::List ( std::initializer_list< TYPE >  values)
inline

Initializes list from initializer list.

◆ List() [3/3]

template<class TYPE >
List< TYPE >::List ( const List< TYPE > &  copy)
inlinenoexcept

Initializes list from other list.

Member Function Documentation

◆ add() [1/2]

template<class TYPE >
void List< TYPE >::add ( const TYPE &  value)
inline

Appends the specified value to the end of this list.

Parameters
valueThe value to be appended to the list.

◆ add() [2/2]

template<class TYPE >
void List< TYPE >::add ( TYPE &&  value)
inline

Appends the specified value to the end of this list.

Parameters
valueThe value to be appended to the list.

◆ append() [1/2]

template<class TYPE >
void List< TYPE >::append ( const TYPE &  value)
inline

Appends the specified value to the end of this list.

Parameters
valueThe value to be appended to the list.

◆ append() [2/2]

template<class TYPE >
void List< TYPE >::append ( TYPE &&  value)
inline

Appends the specified value to the end of this list.

Parameters
valueThe value to be appended to the list.

◆ begin() [1/2]

template<class TYPE >
Iterator List< TYPE >::begin ( )
inline

Returns begin iterator.

◆ begin() [2/2]

template<class TYPE >
ReadIterator List< TYPE >::begin ( ) const
inlinenoexcept

Returns begin iterator.

◆ cbegin()

template<class TYPE >
ReadIterator List< TYPE >::cbegin ( ) const
inlinenoexcept

Returns begin iterator.

◆ cend()

template<class TYPE >
ReadIterator List< TYPE >::cend ( ) const
inlinenoexcept

Returns end iterator.

◆ end() [1/2]

template<class TYPE >
Iterator List< TYPE >::end ( )
inline

Returns end iterator.

◆ end() [2/2]

template<class TYPE >
ReadIterator List< TYPE >::end ( ) const
inlinenoexcept

Returns end iterator.

◆ getEnumerator()

template<class TYPE >
Enumerator List< TYPE >::getEnumerator ( )
inline

Returns a modifying enumerator of the list.

◆ getFirst() [1/2]

template<class TYPE >
TYPE& List< TYPE >::getFirst ( )
inline

Returns the first element.

◆ getFirst() [2/2]

template<class TYPE >
const TYPE& List< TYPE >::getFirst ( ) const
inline

Returns the first element.

◆ getFirstNode() [1/2]

template<class TYPE >
Node* List< TYPE >::getFirstNode ( )
inlineprotected

Returns the first node of the list.

◆ getFirstNode() [2/2]

template<class TYPE >
const Node* List< TYPE >::getFirstNode ( ) const
inlineprotectednoexcept

Returns the first node of the list.

◆ getLast() [1/2]

template<class TYPE >
TYPE& List< TYPE >::getLast ( )
inline

Returns the last element.

◆ getLast() [2/2]

template<class TYPE >
const TYPE& List< TYPE >::getLast ( ) const
inline

Returns the last element.

◆ getLastNode() [1/2]

template<class TYPE >
Node* List< TYPE >::getLastNode ( )
inlineprotected

Returns the last node of the list.

◆ getLastNode() [2/2]

template<class TYPE >
const Node* List< TYPE >::getLastNode ( ) const
inlineprotectednoexcept

Returns the last node of the list.

◆ getReadEnumerator()

template<class TYPE >
ReadEnumerator List< TYPE >::getReadEnumerator ( ) const
inlinenoexcept

Returns a non-modifying enumerator of the list.

◆ getSize()

template<class TYPE >
MemorySize List< TYPE >::getSize ( ) const
inlinenoexcept

Returns the number of elements in the list.

◆ insert() [1/2]

template<class TYPE >
void List< TYPE >::insert ( const Iterator it,
const TYPE &  value 
)
inline

Inserts the value before the specified position. If iterator is end iterator the value is inserted at the end.

Parameters
itInsert position.
valueThe value to be inserted.

◆ insert() [2/2]

template<class TYPE >
void List< TYPE >::insert ( const Iterator it,
TYPE &&  value 
)
inline

Inserts the value before the specified position. If iterator is end iterator the value is inserted at the end.

Parameters
itInsert position.
valueThe value to be inserted.

◆ isEmpty()

template<class TYPE >
bool List< TYPE >::isEmpty ( ) const
inlinenoexcept

Returns true if the list is empty.

◆ moveToBack()

template<class TYPE >
void List< TYPE >::moveToBack ( const Iterator it)
inline

Moves the value at the specified position to the back.

◆ moveToFront()

template<class TYPE >
void List< TYPE >::moveToFront ( const Iterator it)
inline

Moves the value at the specified position to the front.

◆ operator bool()

template<class TYPE >
List< TYPE >::operator bool ( ) const
inlinenoexcept

Returns true if not empty.

◆ operator!=()

template<class TYPE >
bool List< TYPE >::operator!= ( const List< TYPE > &  compare) const
inline

Returns true if not equal.

◆ operator<()

template<class TYPE >
bool List< TYPE >::operator< ( const List< TYPE > &  compare) const
inline

Returns true if less than.

◆ operator<<() [1/2]

template<class TYPE >
List& List< TYPE >::operator<< ( const TYPE &  value)
inline

Appends value.

◆ operator<<() [2/2]

template<class TYPE >
List& List< TYPE >::operator<< ( TYPE &&  value)
inline

Appends value.

◆ operator=() [1/2]

template<class TYPE >
List& List< TYPE >::operator= ( const List< TYPE > &  copy)
inlinenoexcept

Assignment of list by list.

◆ operator=() [2/2]

template<class TYPE >
List& List< TYPE >::operator= ( List< TYPE > &&  move)
inlinenoexcept

Assignment of list by list.

◆ operator==()

template<class TYPE >
bool List< TYPE >::operator== ( const List< TYPE > &  compare) const
inline

Returns true if equal.

◆ operator>=()

template<class TYPE >
bool List< TYPE >::operator>= ( const List< TYPE > &  compare) const
inline

Returns true if greater than or equal.

◆ prepend() [1/2]

template<class TYPE >
void List< TYPE >::prepend ( const TYPE &  value)
inline

Prepends the value to the beginning of this list.

Parameters
valueThe value to be prepended to the list.

◆ prepend() [2/2]

template<class TYPE >
void List< TYPE >::prepend ( TYPE &&  value)
inline

Prepends the value to the beginning of this list.

Parameters
valueThe value to be prepended to the list.

◆ remove()

template<class TYPE >
void List< TYPE >::remove ( const Iterator it)
inline

Removes the node specified by the iterator from this list.

Parameters
itIterator specifying the element to be removed.

◆ removeAll()

template<class TYPE >
void List< TYPE >::removeAll ( )
inline

Removes all the elements from this list.

◆ removeFirst()

template<class TYPE >
void List< TYPE >::removeFirst ( )
inline

Removes this first node of this list.

◆ removeLast()

template<class TYPE >
void List< TYPE >::removeLast ( )
inline

Removes the last node of this list.

◆ shuffle()

template<class TYPE >
void List< TYPE >::shuffle

Shuffles elements. See https ://en.wikipedia.org/wiki/FisherE2%80%93Yates_shuffle::Modern_method.

Uses temporary buffer but avoid copy construction of values.

◆ sort() [1/2]

template<class TYPE >
void List< TYPE >::sort ( )
inline

Sorts the elements of this list. Requires operator<= for TYPE.

◆ sort() [2/2]

template<class TYPE >
template<class PREDICATE >
void List< TYPE >::sort ( PREDICATE  predicate)
inline

Sorts the array.

Friends And Related Function Documentation

◆ operator<<()

template<class TYPE >
FormatOutputStream & operator<< ( FormatOutputStream stream,
const List< TYPE > &  value 
)
related

Writes a string representation of a list to a format stream.

Member Data Documentation

◆ elements

template<class TYPE >
Reference<ListImpl> List< TYPE >::elements
protected

The elements of the list.

List
List collection.
Definition: List.h:45