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

#include <sidilist.hpp>

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

Class Description

template<typename TElement>
struct aworx::lib::detail::SidiNodeBase< TElement >


This is a generic base type that may be used to represent 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 aworx::lib::detail::SidiNodeBase<MyElement>
{
MyData nodeValue;
};

With this simple mechanism in place, pointers to nodes of this type may either point to a node or to an "full" element of derived class. This concept allows to have field pnext of this class of derived type TElement which makes debugging end-user code much easier, because the custom values of the derived types are visible within debugging tools.

This type provides some helper methods, which together with those of sibling struct detail::SidiListHelper, provide all basic mechanisms to implement a single linked list.

Because pointers to nodes and elements are statically castable to each other (which is a noop), most helper methods accept and/or return pointers to derived type TElement. It has to be assured by the caller that these pointers are only dereferenced when it is assured that they do not refer to this base type! Therefore, the helper classes are designed for "internal use" and reside in the detail namespace. As an example, class List of module ALib Memory is built using these helpers internally, but publishes a fully type safe interface, including iterator classes.

See also
Types detail::SidiListHelper,
detail::BidiNodeBase and
detail::BidiListHelper.
Template Parameters
TElementThe "final" node type, containing custom data fields, that is to be derived from this struct.

Definition at line 72 of file sidilist.hpp.

Public Fields

TElement * pnext
 

Public Methods

 SidiNodeBase () noexcept=default
 
 SidiNodeBase (const SidiNodeBase &)=delete
 
 SidiNodeBase (SidiNodeBase &&) noexcept=default
 
 SidiNodeBase (TElement *next) noexcept
 
TElement * addBehind (TElement *elem)
 
integer count (SidiNodeBase *end=nullptr) const
 
bool hasNext () const
 
TElement * next () const
 
void next (SidiNodeBase *p)
 
SidiNodeBaseoperator= (const SidiNodeBase &)=delete
 
SidiNodeBaseoperator= (SidiNodeBase &&) noexcept=default
 
bool pointsTo (const SidiNodeBase *elem) const
 
TElement * removeNext ()
 
TElement * removeRangeBehind (TElement *last)
 

Constructor & Destructor Documentation

◆ SidiNodeBase() [1/4]

SidiNodeBase ( )
defaultnoexcept

Default constructor. (Does not initialize the pointer.)

◆ SidiNodeBase() [2/4]

SidiNodeBase ( const SidiNodeBase< TElement > &  )
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

◆ SidiNodeBase() [3/4]

SidiNodeBase ( SidiNodeBase< TElement > &&  )
defaultnoexcept

Defaulted move constructor.

◆ SidiNodeBase() [4/4]

SidiNodeBase ( TElement *  next)
inlinenoexcept

Constructor accepting a pointer to the next element.

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

Definition at line 104 of file sidilist.hpp.

Member Function Documentation

◆ addBehind()

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 158 of file sidilist.hpp.

◆ count()

integer count ( SidiNodeBase< TElement > *  end = nullptr) const
inline

Counts the number of elements found in the range starting with the next node (in consideration that this node is the 'hook' node) and ending with the element before end.

Parameters
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 172 of file sidilist.hpp.

◆ hasNext()

bool hasNext ( ) const
inline

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

Returns
false if field pnext equals nullptr, otherwise true.

Definition at line 120 of file sidilist.hpp.

◆ next() [1/2]

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 116 of file sidilist.hpp.

◆ next() [2/2]

void next ( SidiNodeBase< TElement > *  p)
inline

Sets the successor of this node or element.

Parameters
pThe node that this node should point to, respectively nullptr if this node should represent the last element of the list.

Definition at line 111 of file sidilist.hpp.

◆ operator=() [1/2]

SidiNodeBase& operator= ( const SidiNodeBase< TElement > &  )
delete

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

Returns
Not defined.

◆ operator=() [2/2]

SidiNodeBase& operator= ( SidiNodeBase< TElement > &&  )
defaultnoexcept

Defaulted move assignment operator.

Returns
A reference to this object.

◆ pointsTo()

bool pointsTo ( const SidiNodeBase< 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 pnext equals elem , otherwise false.

Definition at line 125 of file sidilist.hpp.

◆ removeNext()

TElement* removeNext ( )
inline

Unhooks and returns the element after this node or element.

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

Definition at line 132 of file sidilist.hpp.

◆ removeRangeBehind()

TElement* removeRangeBehind ( TElement *  last)
inline

Unhooks successors until last. If last equals field pnext, only this next element is unhooked.

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

Definition at line 148 of file sidilist.hpp.

Member Data Documentation

◆ pnext

TElement* pnext

A pointer to the next element in the list.

Attention
In case of using type detail::BidiListHelper, this may point to an instance of the base type detail::BidiNodeBase.

Definition at line 78 of file sidilist.hpp.


The documentation for this struct was generated from the following file:
aworx::lib::detail::SidiNodeBase
Definition: sidilist.hpp:72