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); }
304 { Iter i(*
this);
while (i.find(data)) i.unlink(); }
314 if(head.next != NULL)
315 { Iter i(*
this); i.rewind(); i.next(); i.unlink(); }
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_)
426 #endif // __WVLINKLIST_H
Iter(const WvList &l)
Binds the iterator to the specified list.
T * last() const
Returns a pointer to the last element in the linked list.
void add(T *data, bool autofree, const char *id=NULL)
Synonym for append(T*, bool, char*).
void rewind()
Rewinds the iterator to make it point to an imaginary element preceeding the first element of the lis...
bool get_autofree() const
Returns the state of autofree for the current element.
WvListBase()
Creates an empty linked list.
IterBase(const WvListBase &l)
Binds the iterator to the specified list.
T * ptr() const
Returns a pointer to the current element.
void * vptr() const
Returns a void pointer to the object at the iterator's current location.
void unlink(T *data)
Unlinks the specified element from the list.
void set_autofree(bool autofree)
Sets the state of autofree for the current element.
void zap(bool destroy=true)
Clears the linked list.
~WvList()
Destroys 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.
WvLink * next()
Moves the iterator along the list to point to the next element.
void setup()
Invoked by subclasses after the linked list is first created.
WvLink is one element of a WvList.
void unlink(bool destroy=true)
Unlinks the current element from the list and automatically increments the iterator to point to the n...
WvList()
Creates an empty linked list.
void append(T *data, bool autofree, const char *id=NULL)
Appends the element to the end of the list.
void prepend(T *data, bool autofree, const char *id=NULL)
Prepends the element to the beginning of the list.
void shutdown()
Invoked by subclasses before the linked list is destroyed.
WvLink * find_next(const void *data)
Repositions the iterator over the element that matches the specified value.
void unlink_after(WvLink *after, bool destroy=true)
Unlinks the element that follows the specified link in the list.
T * first() const
Returns a pointer to the first element in the linked list.
bool isempty() const
Quickly determines if the list is empty.
A linked list container class.
class WvSorter< UniGenMount, WvListBase, WvListBase::IterBase > Sorter
The sorted iterator type for linked lists.
void reverse()
Reverses the order of elements in the list.
The iterator type for linked lists.
void unlink_first()
Unlinks the first element from the list.
WvLink * cur() const
Returns a pointer to the WvLink at the iterator's current location.
void xunlink(bool destroy=true)
Unlinks the current element from the list but unlike unlink() automatically returns the iterator to t...
size_t count() const
Returns the number of elements in the list.
WvLink * find(const void *data)
Rewinds the iterator and repositions it over the element that matches the specified value...