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