Laxkit
0.0.7.1
|
A simple doubly linked list of pointers. More...
Classes | |
struct | node |
Public Member Functions | |
virtual | ~PtrList () |
List destructor, just call flush() | |
virtual void | flush () |
Flush the list. | |
virtual int | howmany () |
virtual int | push (T *nd, char local=1, int where=-1) |
Push a pointer onto the list before index where. Transfers pointer, does not duplicate. | |
virtual int | pop (T *&popped, int which=-1, char *local=NULL) |
Pop element with index which (defaults to top), and make popped point to it. | |
virtual T * | pop (int which=-1) |
Pop element with index which, or the top if which not specified. | |
virtual int | findindex (T *t) |
Find the index (in the range [0,n-1]) corresponding to the pointer t. | |
virtual int | remove (int which=-1) |
Pop and delete (if islocal) the element at index which. | |
virtual int | pushnodup (T *nd, char local) |
Pushes an element only if it is not already in the list. |
Protected Attributes | |
int | num |
struct Laxkit::PtrList::node * | first |
A simple doubly linked list of pointers.
An instance of this is really a linked list head, and the actual list is stored internally. For a linked list whose nodes can be subclassed directly, see LinkedList.
******PLEASE NOTE that this class is not really finished or tested, and is not used by anything in the Laxkit at the moment.
If you define LAX_DONT_INCLUDE_LINKEDLIST_CC before including linkedlist.h, then linkedlist.cc is not included. Otherwise, linkedlist.cc is included (the default).
The member functions are the same as for PtrStack. The difference is the data are stored in a doubly linked list rather than an array, which might be better in some ways when dealing with huge amounts of data.
Please note that there is no copy constructor or assignement operator defined.
|
virtual |
Find the index (in the range [0,n-1]) corresponding to the pointer t.
If the element is not in the list, then -1 is returned.
|
virtual |
Flush the list.
If PtrList::arrays==1 then the elements are delete with delete[]
rather than just delete
. If the islocal flag for the element is zero, then the element is not delete'd at all.
Referenced by Laxkit::PtrList< T >::~PtrList().
|
virtual |
Pop element with index which (defaults to top), and make popped point to it.
If there is no element to return, popped is set to NULL. If which is out of bounds, then the top most element is popped.
Returns the number of elements still in the list.
Referenced by Laxkit::PtrList< T >::pop(), and Laxkit::PtrList< T >::remove().
|
virtual |
Pop element with index which, or the top if which not specified.
References Laxkit::PtrList< T >::pop().
|
virtual |
Push a pointer onto the list before index where. Transfers pointer, does not duplicate.
If called without where, pointer is pushed onto the top (highest n) position. If local==1, then when the list flushes or the the element is removed, then it is delete'd. If local==2 then the pointer is delete[]'d. Note that it is ok to push NULL.
Returns the number of elements on the stack.
Referenced by Laxkit::PtrList< T >::pushnodup().
|
virtual |
Pushes an element only if it is not already in the list.
Please note that this checks for whether anything in the list points to the same thing that the supplied pointer points to, and NOT whether the contents of whatever the pointer points to match the contents of any element in the list. Always pushes on the end.
Returns 1 if the item was pushed, otherwise 0 if the item was already there.
References Laxkit::PtrList< T >::push().
|
virtual |
Pop and delete (if islocal) the element at index which.
This purges the element by popping and then (if islocal) deleting it. Default if no index is specified is to remove the top element.
References Laxkit::PtrList< T >::pop().