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

#include <forwardlist.hpp>

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

Class Description

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


This is a generic base type that represents a node of a single linked lists. The effective (instantiated) nodes of the list are to be derived from this type with specifying their very own type name as template parameter TElement. The following quick sample demonstrates this:

// The contents to store with each element of a list
class MyData
{
//....
};
// The custom list node derived from this type, giving its own type as template parameter
struct MyElement : public ForwardNode<MyElement> 4
{
MyData nodeValue;
};

This documentation, as well as the documentation of types ForwardList and ForwardListIterator, uses the terms "node" for this type and "element" for the custom derived type TElement that contains the custom (container) data.

With this simple mechanism in place, node instances may be used as "anchors" to the first element of a list. Pointers to nodes of this type may either point to a node or to an element. Instances of nodes always point to an element instance.

While pointers to nodes and elements are statically castable to each other (which is a "noop" because it does not change the pointer's address on common platforms/compilers), most methods accept and/or return pointers to derived type TElement, and if so, it has to be assured by the caller that the input parameters in fact point to those derived instances. Likewise it is assured by this type and types ForwardList and ForwardListIterator, that a returned pointer to an element does so.

This "contract" provides maximum type safety while dealing with start pointers to element lists (which are usually non-castable instances of this base type as provided with ForwardList), while avoiding the need of code clutter by inserting static_cast to TElement in the using code as much as possible. Furthermore, this concept allows to have field forward of type TElement which makes debugging much easier, because the custom values of the derived types are always visible.

Template Parameters
TElementThe "final" node type, containing custom data fields, that is to be derived from this struct.

Definition at line 75 of file forwardlist.hpp.

Public Types

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

Public Static Methods

static integer count (TElement *start, TElement *end=nullptr)
 
static void moveForward (TElement *&pointer)
 
static TElement * moveForward (TNode *&pointer)
 

Public Methods

 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 Fields

TElement * forward
 

Member Typedef Documentation

◆ ConstIterator

using ConstIterator = ForwardListIterator<const TElement>

The constant std::iterator type.

Definition at line 235 of file forwardlist.hpp.

◆ Iterator

using Iterator = ForwardListIterator<TElement>

The mutable std::iterator type.

Definition at line 232 of file forwardlist.hpp.

◆ TNode

using TNode = ForwardNode<TElement>

Alias name for the an instantiation of this template.

Definition at line 86 of file forwardlist.hpp.

Constructor & Destructor Documentation

◆ ForwardNode() [1/4]

ForwardNode ( )
defaultnoexcept

Default constructor. (Does not initialize the pointer!)

◆ ForwardNode() [2/4]

ForwardNode ( const TNode )
delete

Deleted copy constructor. This is deleted because it is dangerous, respectively often not possible and also mostly not wanted to be able to create copies of derived type TElement

◆ ForwardNode() [3/4]

ForwardNode ( TNode &&  )
defaultnoexcept

Defaulted move constructor.

◆ ForwardNode() [4/4]

ForwardNode ( TElement *  next)
inlinenoexcept

Constructor accepting a pointer to the next element.

Parameters
nextPointer to the next element. Assigned to field forward.

Definition at line 121 of file forwardlist.hpp.

Member Function Documentation

◆ addBehind() [1/2]

TElement* addBehind ( TElement *  elem)
inline

Hooks the given element behind this node or element.

Parameters
elemThe element to insert behind this node or element.
Returns
The element that given elem pointed to before the insertion.

Definition at line 207 of file forwardlist.hpp.

Here is the caller graph for this function:

◆ addBehind() [2/2]

TElement* addBehind ( TElement *  first,
TElement *  last 
)
inline

Hooks the given range of elements behind this node or element.

Parameters
firstThe first element of the range to insert.
lastThe last element of the range to insert.
Returns
The element that given last pointed to before the insertion.

Definition at line 220 of file forwardlist.hpp.

◆ begin() [1/2]

Iterator begin ( )
inline

Interprets (casts) this node to an element and returns an iterator referring to it constituting a start of a range of elements.

Returns
The first of element in the list.

Definition at line 240 of file forwardlist.hpp.

◆ begin() [2/2]

ConstIterator begin ( ) const
inline

Interprets (casts) this node to an element and returns an iterator referring to it constituting a start of a range of elements.

Returns
The first of element in the list.

Definition at line 249 of file forwardlist.hpp.

◆ cbegin()

ConstIterator cbegin ( ) const
inline

Interprets (casts) this node to an element and returns an iterator referring to it constituting a start of a range of elements.

Returns
The first of element in the list.

Definition at line 258 of file forwardlist.hpp.

◆ cend()

ConstIterator cend ( ) const
inline

Returns an iterator referring to the end of a range of elements (aka a nullptr).

Returns
The end of the list.

Definition at line 262 of file forwardlist.hpp.

◆ count()

static integer count ( TElement *  start,
TElement *  end = nullptr 
)
inlinestatic

Counts the number of elements found in the range starting with start and ending with the element before end.

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

Definition at line 274 of file forwardlist.hpp.

Here is the caller graph for this function:

◆ end() [1/2]

Iterator end ( )
inline

Returns an iterator referring to the end of a range of elements (aka a nullptr).

Returns
The end of the list.

Definition at line 244 of file forwardlist.hpp.

Here is the caller graph for this function:

◆ end() [2/2]

ConstIterator end ( ) const
inline

Returns an iterator referring to the end of a range of elements (aka a nullptr).

Returns
The end of the list.

Definition at line 253 of file forwardlist.hpp.

◆ hasNext()

bool hasNext ( ) const
inline

Test if this node or element has a next element linked.

Returns
false if field forward equals nullptr, otherwise true.

Definition at line 135 of file forwardlist.hpp.

Here is the caller graph for this function:

◆ isLast()

bool isLast ( ) const
inline

Test if this element is the last element of the list.

Returns
true if field forward equals nullptr, otherwise false.

Definition at line 128 of file forwardlist.hpp.

◆ makeLast()

TElement* makeLast ( )
inline

Sets field forward to nullptr.

Returns
The element that this node or element pointed to before the invocation.

Definition at line 150 of file forwardlist.hpp.

◆ makePointTo()

TElement* makePointTo ( TElement *  elem)
inline

Sets field forward to elem.

Parameters
elemThe element that this node or element is to point to.
Returns
The element that this node or element pointed to before the invocation.

Definition at line 160 of file forwardlist.hpp.

◆ moveForward() [1/2]

static void moveForward ( TElement *&  pointer)
inlinestatic

Moves the given element pointer reference to point to the next element.

Note
It is matter of taste to use this static method for better code readability.
Parameters
pointerA reference to the pointer to move forward.

Definition at line 300 of file forwardlist.hpp.

◆ moveForward() [2/2]

static TElement* moveForward ( TNode *&  pointer)
inlinestatic

Moves the given node pointer reference to point to the next node. The result is the moved pointer, casted to an element.

Note
It is matter of taste to use this static method for better code readability.
Parameters
pointerA reference to the pointer to move forward.
Returns
The moved pointer, casted to an element.

Definition at line 290 of file forwardlist.hpp.

Here is the caller graph for this function:

◆ next()

TElement* next ( ) const
inline

Returns the successor of this node or element.

Returns
The element following this one, respectively nullptr if this is the last element of the list.

Definition at line 171 of file forwardlist.hpp.

Here is the caller graph for this function:

◆ operator=() [1/2]

ForwardNode& operator= ( const TNode )
delete

Deleted copy assignment operator. This is deleted because it is dangerous, respectively often not possible and also mostly not wanted to created copies of derived type TElement

Returns
Not defined.

◆ operator=() [2/2]

ForwardNode& operator= ( TNode &&  )
defaultnoexcept

Defaulted move assignment operator.

Returns
A reference to this object.

◆ pointsTo()

bool pointsTo ( TElement *  elem) const
inline

Test if elem is the successor fo this node or element.

Parameters
elemThe element to test for being a successor of this.
Returns
true if field forward equals elem , otherwise false.

Definition at line 143 of file forwardlist.hpp.

Here is the caller graph for this function:

◆ removeNext()

TElement* removeNext ( )
inline

Unhooks and returns the element after this node or element.

Note
Field forward of the returned element is not set to nullptr.
Returns
The unhooked element.

Definition at line 181 of file forwardlist.hpp.

Here is the caller graph for this function:

◆ removeRangeBehind()

TElement* removeRangeBehind ( TElement *  last)
inline

Unhooks successors until last. If last equals field forward, only one element is unhooked.

Attention
Field forward of given last is not set to nullptr.
Parameters
lastThe last element of the range [forward, last] which is removed.
Returns
The start of the range (the current successor of this node or element).

Definition at line 197 of file forwardlist.hpp.

Here is the caller graph for this function:

Member Data Documentation

◆ forward

TElement* forward
private

In case of derived type TElement this is the pointer to the next element. In case of derived class ForwardList, this is the pointer to the first element of the list.

Definition at line 93 of file forwardlist.hpp.


The documentation for this struct was generated from the following file:
aworx::lib::ForwardNode::ForwardNode
ForwardNode() noexcept=default