ALib C++ Library
Library Version: 1912 R0
Documentation generated by doxygen
Public Types | Public Methods | List of all members
ForwardList< TElement > Struct Template Reference

#include <forwardlist.hpp>

Inheritance diagram for ForwardList< TElement >:
[legend]
Collaboration diagram for ForwardList< TElement >:
[legend]

Class Description

template<typename TElement>
struct aworx::lib::ForwardList< TElement >


Implements a single linked list of TElement instances. This class inherits ForwardNode<TElement>, like TElement does (by contract). This way methods that return a pointer to ForwardNode<TElement> may return either this object itself (the "start hook" of the list) or a pointer to an element instance.

Other methods (the larger part) return an object of TElement. It has to be taken care that the result of methods that return type ForwardNode are not casted to pointers of TElement by the calling code (which is statically possible!). Only if a method returns TElement, it is assured that a custom element type is returned.

Note
A good sample that demonstrates this difference in return types are methods findLast and findLastBefore. The first returns a pointer to type TElement. In contrast to this, the second returns a pointer to type ForwardNode because the result may be a pointer to this list instance itself - which has no custom data attached!
Template Parameters
TElementThe "final" custom type that (by contract) is derived from ForwardNode the same type as this struct is.

Definition at line 22 of file forwardlist.hpp.

Public Types

using ConstIterator = ForwardListIterator< const TElement >
 
using Iterator = ForwardListIterator< TElement >
 
using TNode = ForwardNode< TElement >
 

Public Methods

 ForwardList () noexcept
 
 ForwardList (const ForwardList &copy) noexcept
 
 ForwardList (ForwardList &&move) noexcept
 
 ForwardList (TElement *first) noexcept
 
Iterator begin ()
 
ConstIterator begin () const
 
TNodecastToNode ()
 
ConstIterator cbegin () const
 
ConstIterator cend () const
 
integer count (TElement *end=nullptr) const
 
Iterator end ()
 
ConstIterator end () const
 
TNodefindAndRemove (TElement *elem)
 
TElement * findLast () const
 
TElement * findLast (TElement *hint) const
 
TNodefindLastBefore (TElement *elem)
 
bool isEmpty () const
 
bool isNotEmpty () const
 
ForwardListoperator= (const ForwardList &copy) noexcept
 
ForwardListoperator= (ForwardList &&move) noexcept
 
TElement * popFront ()
 
void pushFront (TElement *elem)
 
void pushFront (TElement *first, TElement *last)
 
void reset ()
 
void setStart (TElement *elem)
 
TElement * start () const
 

Additional Inherited Members

- Private Static Methods inherited from ForwardNode< TElement >
static integer count (TElement *start, TElement *end=nullptr)
 
static void moveForward (TElement *&pointer)
 
static TElement * moveForward (TNode *&pointer)
 
- Private Methods inherited from ForwardNode< TElement >
 ForwardNode () noexcept=default
 
 ForwardNode (const TNode &)=delete
 
 ForwardNode (TElement *next) noexcept
 
 ForwardNode (TNode &&) noexcept=default
 
TElement * addBehind (TElement *elem)
 
TElement * addBehind (TElement *first, TElement *last)
 
Iterator begin ()
 
ConstIterator begin () const
 
ConstIterator cbegin () const
 
ConstIterator cend () const
 
Iterator end ()
 
ConstIterator end () const
 
bool hasNext () const
 
bool isLast () const
 
TElement * makeLast ()
 
TElement * makePointTo (TElement *elem)
 
TElement * next () const
 
ForwardNodeoperator= (const TNode &)=delete
 
ForwardNodeoperator= (TNode &&) noexcept=default
 
bool pointsTo (TElement *elem) const
 
TElement * removeNext ()
 
TElement * removeRangeBehind (TElement *last)
 
- Private Types inherited from ForwardNode< TElement >
using ConstIterator = ForwardListIterator< const TElement >
 
using Iterator = ForwardListIterator< TElement >
 
using TNode = ForwardNode< TElement >
 

Member Typedef Documentation

◆ ConstIterator

using ConstIterator = ForwardListIterator<const TElement>

The constant iterator type.

Definition at line 625 of file forwardlist.hpp.

◆ Iterator

using Iterator = ForwardListIterator< TElement>

The mutable iterator type.

Definition at line 622 of file forwardlist.hpp.

◆ TNode

using TNode = ForwardNode<TElement>

An alias for the node type of this list, which is also the type this struct is derived from.

Definition at line 422 of file forwardlist.hpp.

Constructor & Destructor Documentation

◆ ForwardList() [1/4]

ForwardList ( )
inlinenoexcept

Default constructor. Initializes this list to be empty.

Definition at line 427 of file forwardlist.hpp.

◆ ForwardList() [2/4]

ForwardList ( const ForwardList< TElement > &  copy)
inlinenoexcept

Copy constructor. After construction, this instance points to the first start object as copy does.

Parameters
copyThe list to copy the link from.

Definition at line 435 of file forwardlist.hpp.

◆ ForwardList() [3/4]

ForwardList ( ForwardList< TElement > &&  move)
inlinenoexcept

Move constructor. Copies the link from move and sets the link of move to nullptr.

Parameters
moveThe list to move.

Definition at line 444 of file forwardlist.hpp.

◆ ForwardList() [4/4]

ForwardList ( TElement *  first)
inlinenoexcept

Constructor accepting a pointer to the first element.

Parameters
firstThe element to use as the first element of this list.

Definition at line 473 of file forwardlist.hpp.

Member Function Documentation

◆ begin() [1/2]

Iterator begin ( )
inline

Returns an iterator referring to a mutable element at the start of this list.

Returns
An iterator to the first element in the list.

Definition at line 629 of file forwardlist.hpp.

◆ begin() [2/2]

ConstIterator begin ( ) const
inline

Returns an iterator referring to a constant element at the start of this list.

Returns
An iterator to the first element in the list, limited to constant element access.

Definition at line 637 of file forwardlist.hpp.

◆ castToNode()

TNode* castToNode ( )
inline

Casts this list to the node type. This method is needed because this list type inherits the node type privately.

Note
This method simply returns this, which performs the static cast. If this type inherited ForwardNode publically, a simple ampersand operator (&) could be used on a value of this type instead of invoking this method.
Returns
Returns this list as a pointer to base type ForwardNode.

Definition at line 487 of file forwardlist.hpp.

Here is the caller graph for this function:

◆ cbegin()

ConstIterator cbegin ( ) const
inline

Returns an iterator referring to a constant element at the start of this list.

Returns
An iterator to the first element in the list, limited to constant element access.

Definition at line 645 of file forwardlist.hpp.

◆ cend()

ConstIterator cend ( ) const
inline

Returns an iterator referring to a constant, non-existing element.

Returns
The end of the list.

Definition at line 649 of file forwardlist.hpp.

◆ count()

integer count ( TElement *  end = nullptr) const
inline

Counts the number of elements found in the range starting with this list's first element and ending with the element before end.

Parameters
endThe element after the last one to count. Defaults to a nullptr marking the end of the list.
Returns
The number of elements in the range.

Definition at line 615 of file forwardlist.hpp.

◆ end() [1/2]

Iterator end ( )
inline

Returns an iterator referring to a mutable, non-existing element.

Returns
The end of the list.

Definition at line 633 of file forwardlist.hpp.

Here is the caller graph for this function:

◆ end() [2/2]

ConstIterator end ( ) const
inline

Returns an iterator referring to a constant, non-existing element.

Returns
The end of the list.

Definition at line 641 of file forwardlist.hpp.

◆ findAndRemove()

TNode* findAndRemove ( TElement *  elem)
inline

Searches the predecessor of the given element using findLastBefore and unhooks the element from the list.

Note
It is not checked whether a predecessor was found, aka whether elem is an element of this list. If not, behavior is undefined (nullptr access).
Furthermore, the successor of given elem is not changed, although it is removed from the list.
Parameters
elemThe element to remove.
Returns
The node (this object) or element that pointed to given elem before the invocation and now points to the successor of elem.

Definition at line 603 of file forwardlist.hpp.

◆ findLast() [1/2]

TElement* findLast ( ) const
inline

Searches and returns the last element.

Note
This method must only be invoked on non-empty lists (isNotEmpty returns true). Otherwise this method has undefined behavior (dereference of a nullptr). To find the pointer to the last element use findLastBefore providing nullptr.
Returns
The last element of this list.

Definition at line 562 of file forwardlist.hpp.

◆ findLast() [2/2]

TElement* findLast ( TElement *  hint) const
inline

Searches and returns the last element.

Parameters
hintAn element of this list used to start the search.
Returns
The last element of this list.

Definition at line 573 of file forwardlist.hpp.

◆ findLastBefore()

TNode* findLastBefore ( TElement *  elem)
inline

Searches the node or element that points to the given element.

Parameters
elemThe element to search for.
Returns
The node (this object) or element pointing to elem.

Definition at line 584 of file forwardlist.hpp.

Here is the caller graph for this function:

◆ isEmpty()

bool isEmpty ( ) const
inline

Tests if this list is empty.

Returns
false if the list is empty, true otherwise.

Definition at line 494 of file forwardlist.hpp.

Here is the caller graph for this function:

◆ isNotEmpty()

bool isNotEmpty ( ) const
inline

Tests if this list is not empty.

Returns
true if the list is empty, false otherwise.

Definition at line 501 of file forwardlist.hpp.

◆ operator=() [1/2]

ForwardList& operator= ( const ForwardList< TElement > &  copy)
inlinenoexcept

Copy assignment operator. Copies the link to the first element from copy.

Parameters
copyThe list to copy the link from.
Returns
A reference to this list object.

Definition at line 454 of file forwardlist.hpp.

◆ operator=() [2/2]

ForwardList& operator= ( ForwardList< TElement > &&  move)
inlinenoexcept

Move assignment operator. Copies the link to the first element from move and sets the link in move to nullptr.

Parameters
moveThe list to move the link from.
Returns
A reference to this list object.

Definition at line 464 of file forwardlist.hpp.

◆ popFront()

TElement* popFront ( )
inline

Removes and returns the first element from this list.

Returns
A pointer to the element, respectively nullptr if the list was empty.

Definition at line 546 of file forwardlist.hpp.

◆ pushFront() [1/2]

void pushFront ( TElement *  elem)
inline

Hooks the given element to the beginning of this list.

Parameters
elemThe element to insert to at the start.

Definition at line 529 of file forwardlist.hpp.

Here is the caller graph for this function:

◆ pushFront() [2/2]

void pushFront ( TElement *  first,
TElement *  last 
)
inline

Hooks the given range of elements to the front of this list.

Parameters
firstThe first element of the range to insert.
lastThe last element of the range to insert.

Definition at line 538 of file forwardlist.hpp.

◆ reset()

void reset ( )
inline

Resets this list to zero elements.

Definition at line 507 of file forwardlist.hpp.

Here is the caller graph for this function:

◆ setStart()

void setStart ( TElement *  elem)
inline

Sets given element elem as the start of this list.

Parameters
elemThe element to set as the new start of this list.

Definition at line 522 of file forwardlist.hpp.

Here is the caller graph for this function:

◆ start()

TElement* start ( ) const
inline

Returns the start element of this list.

Returns
The first element of this list, respectively nullptr if this list is empty.

Definition at line 514 of file forwardlist.hpp.

Here is the caller graph for this function:

The documentation for this struct was generated from the following file: