casacore
|
#include <Link.h>
Public Member Functions | |
t & | val () |
The val() member function will return a reference to the contents of the current node. More... | |
const t & | val () const |
Link< t > *& | next () |
These member functions allow traversal of the list. More... | |
const Link< t > * | next () const |
Link< t > *& | prev () |
const Link< t > * | prev () const |
Link (t e, Link< t > *p=0, Link< t > *n=0) | |
This is where the maintenance of the list happens. More... | |
~Link () | |
This destructor destroys the rest of the list, i.e. More... | |
Link< t > * | unlink (Link< t > *=0) |
This function unlinks a given element of the list. More... | |
Protected Attributes | |
t | store |
Link< t > * | Next |
Link< t > * | Prev |
doubly linked list primitive
Public interface
This class provides the primitives for creating a class of linked data structures. Thus it is called Link
.
This class provides a minimal doubly linked list implementation. All of the work is performed by the constructor. This class does not keep track of the head of the list; this is left to the user of the class. This class can be thought of as the "nodes" of a linked list, but conceptually each of the nodes is a list itself. This class will typically not be used by the average user because although it is a functional doubly linked list implementation, List<t>
provides a higher level of abstraction.
This example makes Link
behave like a stack:
The output from the previous example would be:
10 19 12 23
As each new link is being created, the new element goes at the beginning of the list because the previous head of the list, hed
, is being passed in as the next list element.
This next example demonstrates how a queue could be created instead of a stack:
The output here would be:
23 12 19 10
|
inline |
This is where the maintenance of the list happens.
The parameters are:
If the previous element is non-null it is used to get all of the information necessary to add this new element to the list. If the previous element is null and the next element is non-null it is assumed that the new element is being added to the beginning of the list, i.e. before the next element but with no previous element.
Clean up previous list if inserting in the middle of a list with "p==0".
Definition at line 159 of file Link.h.
References casacore::Link< t >::Next, and casacore::Link< t >::Prev.
casacore::Link< t >::~Link | ( | ) |
This destructor destroys the rest of the list, i.e.
this object and all that follow.
Warning: If the destructor is called for a Link<t>
in the middle of a list the elements which occur before the object will be left dangling, and the objects which follow the deleted object will also be deleted;
|
inline |
These member functions allow traversal of the list.
the next()
functions retrieve the next element in the list, and prev()
retrieves the previous element.
Tip: The non-const versions of these functions return a reference to the pointer to the next element in the list; This allows for modification of the list if necessary, e;g; for removal of elements;
Definition at line 139 of file Link.h.
References casacore::Link< t >::Next.
|
inline |
Definition at line 140 of file Link.h.
References casacore::Link< t >::Next.
|
inline |
Definition at line 141 of file Link.h.
References casacore::Link< t >::Prev.
|
inline |
Definition at line 142 of file Link.h.
References casacore::Link< t >::Prev.
Link<t>* casacore::Link< t >::unlink | ( | Link< t > * | = 0 | ) |
This function unlinks a given element of the list.
It requires no parameters because the node has links to the previous and next elements in the list. This is useful when removing a single element from the list because the destructor, Link::~Link
, will delete the rest of the list elements if they are linked in with this
. This function returns the next element in the list.
Tip: The Link<t>*
parameter is unused; It is a historical artifact which will be removed;
Referenced by casacore::Stack< elem >::pop(), and casacore::Stack< elem >::popVal().
|
inline |
The val()
member function will return a reference to the contents of the current node.
Definition at line 125 of file Link.h.
References casacore::Link< t >::store.
Referenced by casacore::Stack< elem >::popVal().
|
inline |
Definition at line 126 of file Link.h.
References casacore::Link< t >::store.
|
protected |
Definition at line 119 of file Link.h.
Referenced by casacore::Link< t >::Link(), and casacore::Link< t >::next().
|
protected |
Definition at line 120 of file Link.h.
Referenced by casacore::Link< t >::Link(), and casacore::Link< t >::prev().
|
protected |
Definition at line 118 of file Link.h.
Referenced by casacore::Link< t >::val().