#include <wvlinklist.h>
Inherits WvListBase.
Collaboration diagram for WvList< T >:
Some rather horrible macros are used to declare actual concrete list types.
Example:
int main() { WvStringList l; WvStringList::Iter i(l);
... fill the list ...
i.rewind(); while (i.next()) printf("%s\\n", i.str); }
Deallocating list will free all of the WvLinks in the list, but will only free the user objects that were added with auto_free set to true.
We need to malloc memory for each WvLink as well as the data it stores; this is unnecessarily slow. I would rather have made a base "Link" class for object types that could be stored as links in a list, and then used object->next instead of all the List Iterator stuff, but the end result was pure ugliness, so I gave up. At least this way, the same object can be in multiple lists.
List type construction is facilitated by the following macros:
"T" is the object type
Definition at line 185 of file wvlinklist.h.
Public Types | |
| typedef WvSorter< T, WvListBase, WvListBase::IterBase > | Sorter |
| The sorted iterator type for linked lists. | |
Public Member Functions | |
| WvList () | |
| Creates an empty linked list. | |
| ~WvList () | |
| Destroys the linked list. | |
| void | setup () |
| Invoked by subclasses after the linked list is first created. | |
| void | shutdown () |
| Invoked by subclasses before the linked list is destroyed. | |
| void | zap (bool destroy=true) |
| Clears the linked list. | |
| T * | first () const |
| Returns a pointer to the first element in the linked list. | |
| T * | last () const |
| Returns a pointer to the last element in the linked list. | |
| void | add_after (WvLink *after, T *data, bool auto_free, char *id=NULL) |
| Adds the element after the specified link in the list. | |
| void | append (T *data, bool auto_free, char *id=NULL) |
| Appends the element to the end of the list. | |
| void | add (T *data, bool auto_free, char *id=NULL) |
| Synonym for append(T*, bool, char*). | |
| void | prepend (T *data, bool auto_free, char *id=NULL) |
| Prepends the element to the beginning of the list. | |
| void | unlink (T *data) |
| Unlinks the specified element from the list. | |
| void | unlink_first () |
| Unlinks the first element from the list. | |
| void | unlink_after (WvLink *after, bool destroy=true) |
| Unlinks the element that follows the specified link in the list. | |
| size_t | count () const |
| Returns the number of elements in the list. | |
| void | reverse () |
| Reverses the order of elements in the list. | |
| bool | isempty () const |
| Quickly determines if the list is empty. | |
Public Attributes | |
| WvLink | head |
| WvLink * | tail |
|
|||||
|
The sorted iterator type for linked lists.
Definition at line 383 of file wvlinklist.h. |
|
|||||||||
|
Creates an empty linked list.
Definition at line 191 of file wvlinklist.h. |
|
|||||||||
|
Destroys the linked list. Destroys any elements that were added with auto_free == true. Definition at line 200 of file wvlinklist.h. |
|
||||||||||||||||||||
|
Synonym for append(T*, bool, char*).
Definition at line 271 of file wvlinklist.h. |
|
||||||||||||||||||||||||
|
Adds the element after the specified link in the list. "link" is the link preceeding the desired location of the element to be inserted, non-null "data" is the element pointer, may be null "auto_free" is if true, takes ownership of the element "id" is an optional string to associate with the element, or null Definition at line 253 of file wvlinklist.h. Referenced by WvList< UniGenMount >::append(), and WvList< UniGenMount >::prepend(). |
|
||||||||||||||||||||
|
Appends the element to the end of the list. "data" is the element pointer, may be null "auto_free" is if true, takes ownership of the element "id" is an optional string to associate with the element, or null Definition at line 264 of file wvlinklist.h. Referenced by WvList< UniGenMount >::add(), WvDeserialize< WvList< T > * >::go(), and wvtcl_decode(). |
|
|
Returns the number of elements in the list. This function causes a full traversal of the list which may be overly inefficient depending on how and when it is used. Returns: the number of elements Definition at line 24 of file wvlinklist.cc. References WvLink::next. Referenced by _wv_serialize(), and WvHashTableBase::count(). |
|
|||||||||
|
Returns a pointer to the first element in the linked list. The list must be non-empty. Returns: the element pointer, possibly null Definition at line 228 of file wvlinklist.h. |
|
|
Quickly determines if the list is empty. This is much faster than checking count() == 0. Returns: true if empty Definition at line 61 of file wvlinklist.h. References WvLink::next. Referenced by WvList< UniGenMount >::first(), and WvHashTableBase::isempty(). |
|
|||||||||
|
Returns a pointer to the last element in the linked list. The list must be non-empty. Returns: the element pointer, possibly null Definition at line 241 of file wvlinklist.h. |
|
||||||||||||||||||||
|
Prepends the element to the beginning of the list. "data" is the element pointer, may be null "auto_free" is if true, takes ownership of the element "id" is an optional string to associate with the element, or null Definition at line 281 of file wvlinklist.h. Referenced by UniMountGen::mountgen(). |
|
|
Reverses the order of elements in the list. This function traverses the list and rearranges the pointers and updates the pointers to head & tail appropriately. It does nothing for lists of count<2 Definition at line 35 of file wvlinklist.cc. References WvLink::next, and WvListBase::tail. |
|
|||||||||
|
Invoked by subclasses after the linked list is first created.
Definition at line 204 of file wvlinklist.h. |
|
|||||||||
|
Invoked by subclasses before the linked list is destroyed.
Definition at line 207 of file wvlinklist.h. |
|
||||||||||
|
Unlinks the specified element from the list. Destroys the element if it was added with auto_free == true. "data" is the element pointer, may be null Definition at line 291 of file wvlinklist.h. |
|
||||||||||||||||
|
Unlinks the element that follows the specified link in the list. Destroys the element if it was added with auto_free == true and destroy == true. "after" is the link preceeding the element to be removed, non-null Definition at line 311 of file wvlinklist.h. Referenced by WvList< UniGenMount >::zap(). |
|
|||||||||
|
Unlinks the first element from the list. Destroys the element if it was added with auto_free == true. Definition at line 300 of file wvlinklist.h. |
|
||||||||||
|
Clears the linked list. If destroy is true, destroys any elements that were added with auto_free == true. Definition at line 215 of file wvlinklist.h. Referenced by WvList< UniGenMount >::~WvList(). |
|
|
Definition at line 28 of file wvlinklist.h. Referenced by WvHashTableBase::IterBase::next(), and WvHashTableBase::IterBase::rewind(). |
|
|
Definition at line 28 of file wvlinklist.h. Referenced by WvListBase::reverse(), and WvListBase::WvListBase(). |
1.3.6-20040222