ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
SidiNodeBase< TElement > Struct Template Reference

Description:

template<typename TElement>
struct alib::lang::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 lang::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 lang::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 Monomem is built using these helpers internally, but publishes a fully type safe interface, including iterator classes.

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

Definition at line 68 of file sidilist.hpp.

#include <sidilist.hpp>

Inheritance diagram for SidiNodeBase< TElement >:
[legend]

Public Field Index:

TElement * pnext
 

Public Method Index:

 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)
 

Field Details:

◆ pnext

template<typename TElement >
TElement* pnext

A pointer to the next element in the list.

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

Definition at line 74 of file sidilist.hpp.

Constructor(s) / Destructor Details::

◆ SidiNodeBase() [1/4]

template<typename TElement >
SidiNodeBase ( )
defaultnoexcept

Default constructor. (Does not initialize the pointer.)

◆ SidiNodeBase() [2/4]

template<typename TElement >
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]

template<typename TElement >
SidiNodeBase ( SidiNodeBase< TElement > && )
defaultnoexcept

Defaulted move constructor.

◆ SidiNodeBase() [4/4]

template<typename TElement >
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 100 of file sidilist.hpp.

Method Details:

◆ addBehind()

template<typename TElement >
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 154 of file sidilist.hpp.

Here is the call graph for this function:

◆ count()

template<typename TElement >
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 168 of file sidilist.hpp.

Here is the call graph for this function:

◆ hasNext()

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

◆ next() [1/2]

template<typename TElement >
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 112 of file sidilist.hpp.

◆ next() [2/2]

template<typename TElement >
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 107 of file sidilist.hpp.

◆ operator=() [1/2]

template<typename TElement >
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]

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

Defaulted move assignment operator.

Returns
A reference to this object.

◆ pointsTo()

template<typename TElement >
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 121 of file sidilist.hpp.

◆ removeNext()

template<typename TElement >
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 128 of file sidilist.hpp.

Here is the call graph for this function:

◆ removeRangeBehind()

template<typename TElement >
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 144 of file sidilist.hpp.

Here is the call graph for this function:

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