Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

WvList< T > Class Template Reference

#include <wvlinklist.h>

Inheritance diagram for WvList< T >:

Inheritance graph
[legend]
List of all members.

Detailed Description

template<class T>
class WvList< T >

A linked list container class.

Some rather horrible macros are used to declare actual concrete list types.

Example:

DeclareWvList(WvString);

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


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.

Classes

class  Iter
 The iterator type for linked lists. More...


Constructor & Destructor Documentation

template<class T>
WvList< T >::~WvList  )  [inline]
 

Destroys the linked list.

Destroys any elements that were added with auto_free == true.


Member Function Documentation

template<class T>
void WvList< T >::zap bool  destroy = true  )  [inline]
 

Clears the linked list.

If destroy is true, destroys any elements that were added with auto_free == true.

template<class T>
T* WvList< T >::first  )  const [inline]
 

Returns a pointer to the first element in the linked list.

The list must be non-empty.

Returns: the element pointer, possibly null

template<class T>
T* WvList< T >::last  )  const [inline]
 

Returns a pointer to the last element in the linked list.

The list must be non-empty.

Returns: the element pointer, possibly null

template<class T>
void WvList< T >::add_after WvLink after,
T *  data,
bool  auto_free,
char *  id = NULL
[inline]
 

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

template<class T>
void WvList< T >::append T *  data,
bool  auto_free,
char *  id = NULL
[inline]
 

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

template<class T>
void WvList< T >::add T *  data,
bool  auto_free,
char *  id = NULL
[inline]
 

Synonym for append(T*, bool, char*).

See also:
append(T*, bool, char*)

template<class T>
void WvList< T >::prepend T *  data,
bool  auto_free,
char *  id = NULL
[inline]
 

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

template<class T>
void WvList< T >::unlink T *  data  )  [inline]
 

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

template<class T>
void WvList< T >::unlink_first  )  [inline]
 

Unlinks the first element from the list.

Destroys the element if it was added with auto_free == true.

template<class T>
void WvList< T >::unlink_after WvLink after,
bool  destroy = true
[inline]
 

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


The documentation for this class was generated from the following file:
Generated on Sun Jul 10 17:31:18 2005 for WvStreams by  doxygen 1.4.0