10 #include "wvtypetraits.h"
63 {
return head.next == NULL; }
84 { list = &l; link = NULL; }
91 { prev = NULL; link = &((
WvListBase *)list)->head; }
104 { prev = link;
return link = link->next; }
119 {
return link->data; }
228 void zap(
bool destroy =
true)
242 {
return (T*)head.next->data; }
252 {
return (T*)tail->data; }
264 const char *
id = NULL )
266 (void)
new WvLink((
void *)data, after, tail, autofree, id);
276 void append(T *data,
bool autofree,
const char *
id = NULL)
283 void add(T *data,
bool autofree,
const char *
id = NULL)
284 {
append(data, autofree,
id); }
293 void prepend(T *data,
bool autofree,
const char *
id = NULL)
294 {
add_after(&head, data, autofree,
id); }
314 if(head.next != NULL)
327 WvLink *next = after->next;
330 T *obj = (destroy && next->get_autofree()) ?
331 static_cast<T*
>(next->data) : NULL;
332 if (next == tail) tail = after;
365 {
return (T *)link->data; }
374 return link->get_autofree();
382 link->set_autofree(autofree);
392 if (prev) ((
WvList *)list)->unlink_after(prev, destroy);
411 if (prev) ((
WvList *)list)->unlink_after(prev, destroy);
420 #define DeclareWvList2(_classname_, _type_) \
421 typedef class WvList<_type_> _classname_
423 #define DeclareWvList(_type_) DeclareWvList2(_type_##List, _type_)
WvLink is one element of a WvList<T>.
IterBase(const WvListBase &l)
Binds the iterator to the specified list.
void rewind()
Rewinds the iterator to make it point to an imaginary element preceeding the first element of the lis...
void * vptr() const
Returns a void pointer to the object at the iterator's current location.
WvLink * next()
Moves the iterator along the list to point to the next element.
WvLink * find_next(const void *data)
Repositions the iterator over the element that matches the specified value.
WvLink * cur() const
Returns a pointer to the WvLink at the iterator's current location.
WvLink * find(const void *data)
Rewinds the iterator and repositions it over the element that matches the specified value.
WvListBase()
Creates an empty linked list.
void reverse()
Reverses the order of elements in the list.
size_t count() const
Returns the number of elements in the list.
bool isempty() const
Quickly determines if the list is empty.
The iterator type for linked lists.
void set_autofree(bool autofree)
Sets the state of autofree for the current element.
bool get_autofree() const
Returns the state of autofree for the current element.
T * ptr() const
Returns a pointer to the current element.
void unlink(bool destroy=true)
Unlinks the current element from the list and automatically increments the iterator to point to the n...
void xunlink(bool destroy=true)
Unlinks the current element from the list but unlike unlink() automatically returns the iterator to t...
Iter(const WvList &l)
Binds the iterator to the specified list.
A linked list container class.
void append(T *data, bool autofree, const char *id=NULL)
Appends the element to the end of the list.
void unlink_first()
Unlinks the first element from the list.
~WvList()
Destroys the linked list.
void shutdown()
Invoked by subclasses before the linked list is destroyed.
void prepend(T *data, bool autofree, const char *id=NULL)
Prepends the element to the beginning of the list.
WvList()
Creates an empty linked list.
class WvSorter< T, WvListBase, WvListBase::IterBase > Sorter
The sorted iterator type for linked lists.
void unlink_after(WvLink *after, bool destroy=true)
Unlinks the element that follows the specified link in the list.
void add(T *data, bool autofree, const char *id=NULL)
Synonym for append(T*, bool, char*).
T * first() const
Returns a pointer to the first element in the linked list.
void setup()
Invoked by subclasses after the linked list is first created.
void zap(bool destroy=true)
Clears the linked list.
void unlink(T *data)
Unlinks the specified element from the list.
T * last() const
Returns a pointer to the last element in the linked list.
void add_after(WvLink *after, T *data, bool autofree, const char *id=NULL)
Adds the element after the specified link in the list.