ALib C++ Library
Library Version: 2412 R0
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 list. The effective (instantiated) nodes of the list are to be derived from this type by 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 mechanism in place, pointers to nodes of this type may either point to a node or to a "full" element of derived class. This concept allows having field n 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::SidiListHook, 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 ensured by the caller that these pointers are only dereferenced when it is ensured 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 Containers is built using these helpers internally but publishes a full type safe interface, including iterator classes.

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

Definition at line 62 of file sidilist.hpp.

#include <sidilist.hpp>

Inheritance diagram for SidiNodeBase< TElement >:
[legend]

Public Field Index:

TElement * n
 

Public Method Index:

 SidiNodeBase () noexcept=default
 Default constructor. (Does not initialize the pointer.)
 
 SidiNodeBase (const SidiNodeBase &)=delete
 
 SidiNodeBase (SidiNodeBase &&) noexcept=default
 Defaulted move constructor.
 
 SidiNodeBase (TElement *next) noexcept
 
TElement * addBehind (TElement *elem) noexcept
 
integer count (SidiNodeBase *end=nullptr) const noexcept
 
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 () noexcept
 
TElement * removeRangeBehind (TElement *last) noexcept
 

Field Details:

◆ n

template<typename TElement >
TElement* n

A pointer to the next element in the list.

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

Definition at line 68 of file sidilist.hpp.

Constructor(s) / Destructor Details:

◆ SidiNodeBase() [1/2]

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() [2/2]

template<typename TElement >
SidiNodeBase ( TElement * next)
inlineexplicitnoexcept

Constructor accepting a pointer to the next element.

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

Definition at line 95 of file sidilist.hpp.

Method Details:

◆ addBehind()

template<typename TElement >
TElement * addBehind ( TElement * elem)
inlinenoexcept

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

Here is the call graph for this function:

◆ count()

template<typename TElement >
integer count ( SidiNodeBase< TElement > * end = nullptr) const
inlinenodiscardnoexcept

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

Here is the call graph for this function:

◆ hasNext()

template<typename TElement >
bool hasNext ( ) const
inlinenodiscard

Test if this node or element has set an element in filed n.

Returns
false if field n equals nullptr, otherwise true.

Definition at line 111 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 106 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 101 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
inlinenodiscard

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

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

Definition at line 117 of file sidilist.hpp.

◆ removeNext()

template<typename TElement >
TElement * removeNext ( )
inlinenoexcept

Unhooks and returns the element after this node or element.

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

Definition at line 124 of file sidilist.hpp.

Here is the call graph for this function:

◆ removeRangeBehind()

template<typename TElement >
TElement * removeRangeBehind ( TElement * last)
inlinenoexcept

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

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

Definition at line 140 of file sidilist.hpp.

Here is the call graph for this function:

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