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:
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.
TElement | The "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>
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) |
SidiNodeBase & | operator= (const SidiNodeBase &)=delete |
SidiNodeBase & | operator= (SidiNodeBase &&) noexcept=default |
bool | pointsTo (const SidiNodeBase *elem) const |
TElement * | removeNext () |
TElement * | removeRangeBehind (TElement *last) |
TElement* pnext |
A pointer to the next element in the list.
Definition at line 74 of file sidilist.hpp.
|
defaultnoexcept |
Default constructor. (Does not initialize the pointer.)
|
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
|
defaultnoexcept |
Defaulted move constructor.
|
inlinenoexcept |
Constructor accepting a pointer to the next element.
next | Pointer to the next element. Assigned to field pnext. |
Definition at line 100 of file sidilist.hpp.
|
inline |
Hooks the given element behind this node or element.
elem | The element to insert behind this node or element. |
Definition at line 154 of file sidilist.hpp.
|
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 .
end | Pointer to the element after the last one to count. Defaults to nullptr , marking the end of a list. |
Definition at line 168 of file sidilist.hpp.
|
inline |
Test if this node or element has a next element linked.
false
if field pnext equals nullptr
, otherwise true
. Definition at line 116 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 112 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 107 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.
|
inline |
Test if elem is the successor fo this node or element.
elem | The element to test for being a successor of this. |
true
if field pnext equals elem , otherwise false
. Definition at line 121 of file sidilist.hpp.
|
inline |
Unhooks and returns the element after this node or element.
nullptr
.Definition at line 128 of file sidilist.hpp.
|
inline |
Unhooks successors until last
. If last
equals field pnext, only this next element is unhooked.
nullptr
.last | The last element of the range [pnext, last ] which is removed. |
Definition at line 144 of file sidilist.hpp.