VxWorks Reference Manual : Wind Foundation Classes
VXWList - simple linked list class
VXWList::VXWList( ) - initialize a list
VXWList::VXWList( ) - initialize a list as a copy of another
VXWList::~VXWList( ) - free up a list
VXWList::add( ) - add a node to the end of list
VXWList::concat( ) - concatenate two lists
VXWList::count( ) - report the number of nodes in a list
VXWList::extract( ) - extract a sublist from list
VXWList::find( ) - find a node in list
VXWList::first( ) - find first node in list
VXWList::get( ) - delete and return the first node from list
VXWList::insert( ) - insert a node in list after a specified node
VXWList::last( ) - find the last node in list
VXWList::next( ) - find the next node in list
VXWList::nStep( ) - find a list node nStep steps away from a specified node
VXWList::nth( ) - find the Nth node in a list
VXWList::previous( ) - find the previous node in list
VXWList::remove( ) - delete a specified node from list
The VXWList class supports the creation and maintenance of a doubly linked list. The class contains pointers to the first and last nodes in the list, and a count of the number of nodes in the list. The nodes in the list are derived from the structure NODE, which provides two pointers: NODE::next and NODE::previous. Both the forward and backward chains are terminated with a NULL pointer.
The VXWList class simply manipulates the linked-list data structures; no kernel functions are invoked. In particular, linked lists by themselves provide no task synchronization or mutual exclusion. If multiple tasks will access a single linked list, that list must be guarded with some mutual-exclusion mechanism (such as a mutual-exclusion semaphore).
--------- -------- -------- | head--------------->| next----------->| next--------- | | | | | | | | | ------- prev |<---------- prev | | | | | | | | | | | tail------ | | ... | ----->| ... | | | | | v | v |count=2| | ----- | ----- --------- | --- | --- | - | - | | ------------------------
----------- | head------------------ | | | | tail---------- | | | | v | count=0 | ----- ----- ----------- --- --- - -
Use only single inheritance! This class is an interface to the VxWorks library lstLib. More sophisticated alternatives are available in the Tools.h++ class libraries.
The following example illustrates how to create a list by deriving elements from NODE and putting them on a VXWList.
class myListNode : public NODE { public: myListNode () { } private: }; VXWList myList; myListNode a, b, c; NODE * pEl = &c; void useList () { myList.add (&a); myList.insert (pEl, &b); }
vxwLstLib.h
VXWList::VXWList( ) - initialize a list
VXWList ()
This constructor initializes a list as an empty list.
N/A
VXWList::VXWList( ) - initialize a list as a copy of another
VXWList ( const VXWList & )
This constructor builds a new list as a copy of an existing list.
N/A
VXWList::~VXWList( ) - free up a list
~VXWList ()
This destructor frees up memory used for nodes.
N/A
VXWList::add( ) - add a node to the end of list
void add ( NODE * pNode )
This routine adds a specified node to the end of the list.
N/A
VXWList::concat( ) - concatenate two lists
void concat ( VXWList &aList )
This routine concatenates the specified list to the end of the current list. The specified list is left empty. Either list (or both) can be empty at the beginning of the operation.
N/A
VXWList::count( ) - report the number of nodes in a list
int count ()
This routine returns the number of nodes in a specified list.
The number of nodes in the list.
VXWList::extract( ) - extract a sublist from list
LIST extract ( NODE * pStart, NODE * pEnd )
This routine extracts the sublist that starts with pStart and ends with pEnd. It returns the extracted list.
The extracted sublist.
VXWList::find( ) - find a node in list
int find ( NODE * pNode ) const
This routine returns the node number of a specified node (the first node is 1).
The node number, or ERROR if the node is not found.
VXWList::first( ) - find first node in list
NODE * first ()
This routine finds the first node in its list.
A pointer to the first node in the list, or NULL if the list is empty.
VXWList::get( ) - delete and return the first node from list
NODE * get ()
This routine gets the first node from its list, deletes the node from the list, and returns a pointer to the node gotten.
A pointer to the node gotten, or NULL if the list is empty.
VXWList::insert( ) - insert a node in list after a specified node
void insert ( NODE * pPrev, NODE * pNode )
This routine inserts a specified node into the list. The new node is placed following the list node pPrev. If pPrev is NULL, the node is inserted at the head of the list.
N/A
VXWList::last( ) - find the last node in list
NODE * last ()
This routine finds the last node in its list.
A pointer to the last node in the list, or NULL if the list is empty.
VXWList::next( ) - find the next node in list
NODE * next ( NODE * pNode ) const
This routine locates the node immediately following a specified node.
A pointer to the next node in the list, or NULL if there is no next node.
VXWList::nStep( ) - find a list node nStep steps away from a specified node
NODE * nStep ( NODE * pNode, int nStep ) const
This routine locates the node nStep steps away in either direction from a specified node. If nStep is positive, it steps toward the tail. If nStep is negative, it steps toward the head. If the number of steps is out of range, NULL is returned.
A pointer to the node nStep steps away, or NULL if the node is out of range.
VXWList::nth( ) - find the Nth node in a list
NODE * nth ( int nodeNum ) const
This routine returns a pointer to the node specified by a number nodeNum where the first node in the list is numbered 1. Note that the search is optimized by searching forward from the beginning if the node is closer to the head, and searching back from the end if it is closer to the tail.
A pointer to the Nth node, or NULL if there is no Nth node.
VXWList::previous( ) - find the previous node in list
NODE * previous ( NODE * pNode ) const
This routine locates the node immediately preceding the node pointed to by pNode.
A pointer to the previous node in the list, or NULL if there is no previous node.
VXWList::remove( ) - delete a specified node from list
void remove ( NODE * pNode )
This routine deletes a specified node from its list.
N/A