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:
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.
TElement | The "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>
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) |
SidiNodeBase & | operator= (const SidiNodeBase &)=delete |
SidiNodeBase & | operator= (SidiNodeBase &&) noexcept=default |
bool | pointsTo (const SidiNodeBase *elem) const |
TElement * | removeNext () noexcept |
TElement * | removeRangeBehind (TElement *last) noexcept |
TElement* n |
A pointer to the next element in the list.
Definition at line 68 of file sidilist.hpp.
|
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
|
inlineexplicitnoexcept |
Constructor accepting a pointer to the next element.
next | Pointer to the next element. Assigned to field n. |
Definition at line 95 of file sidilist.hpp.
|
inlinenoexcept |
Hooks the given element behind this node or element.
elem | The element to insert behind this node or element. |
Definition at line 150 of file sidilist.hpp.
|
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.
end | Pointer to the element after the last one to count. Defaults to nullptr , marking the end of a list. |
Definition at line 165 of file sidilist.hpp.
|
inlinenodiscard |
Test if this node or element has set an element in filed n.
false
if field n equals nullptr
, otherwise true
. Definition at line 111 of file sidilist.hpp.
|
inline |
Returns the successor of this node or element.
nullptr
if this is the last element of the list. Definition at line 106 of file sidilist.hpp.
|
inline |
Sets the successor of this node or element.
p | The 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.
|
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
|
defaultnoexcept |
Defaulted move assignment operator.
|
inlinenodiscard |
Test if elem is the successor for this node or element.
elem | The element to test for being a successor of this. |
true
if field n equals elem , otherwise false
. Definition at line 117 of file sidilist.hpp.
|
inlinenoexcept |
Unhooks and returns the element after this node or element.
nullptr
.Definition at line 124 of file sidilist.hpp.
|
inlinenoexcept |
Unhooks successors until last
. If last
equals field n, only this next element is unhooked.
nullptr
.last | The last element of the range [n, last] which is removed. |
Definition at line 140 of file sidilist.hpp.