WvStreams
WvList< T > Class Template Reference

A linked list container class. More...

#include <wvlinklist.h>

Inheritance diagram for WvList< T >:

Classes

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

Public Types

typedef class WvSorter< T, WvListBase, WvListBase::IterBaseSorter
 The sorted iterator type for linked lists.
typedef class WvSorter< T, WvListBase, WvListBase::IterBaseSorter
 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 autofree, const char *id=NULL)
 Adds the element after the specified link in the list.
void append (T *data, bool autofree, const char *id=NULL)
 Appends the element to the end of the list.
void add (T *data, bool autofree, const char *id=NULL)
 Synonym for append(T*, bool, char*).
void prepend (T *data, bool autofree, const 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.
 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 autofree, const char *id=NULL)
 Adds the element after the specified link in the list.
void append (T *data, bool autofree, const char *id=NULL)
 Appends the element to the end of the list.
void add (T *data, bool autofree, const char *id=NULL)
 Synonym for append(T*, bool, char*).
void prepend (T *data, bool autofree, const 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.
size_t count () const
 Returns the number of elements in the list.
void reverse ()
 Reverses the order 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.
bool isempty () const
 Quickly determines if the list is empty.

Public Attributes

WvLink head
WvLinktail

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 autofree 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:

  • DeclareWvList(Type): creates a subclass named TypeList that contains pointers to Type.
  • DeclareWvList2(name, Type): as the above, but calls the resulting class by the specified name.

"T" is the object type

Definition at line 197 of file debian/libwvstreams-dev/usr/include/wvstreams/wvlinklist.h.

Member Typedef Documentation

◆ Sorter [1/2]

template<class T>
typedef class WvSorter< T, WvListBase, WvListBase::IterBase > WvList< T >::Sorter

The sorted iterator type for linked lists.

Definition at line 417 of file debian/libwvstreams-dev/usr/include/wvstreams/wvlinklist.h.

◆ Sorter [2/2]

template<class T>
typedef class WvSorter< T, WvListBase, WvListBase::IterBase > WvList< T >::Sorter

The sorted iterator type for linked lists.

Definition at line 417 of file include/wvlinklist.h.

Constructor & Destructor Documentation

◆ WvList() [1/2]

template<class T>
WvList< T >::WvList ( )
inline

Creates an empty linked list.

Definition at line 204 of file debian/libwvstreams-dev/usr/include/wvstreams/wvlinklist.h.

◆ ~WvList() [1/2]

template<class T>
WvList< T >::~WvList ( )
inline

Destroys the linked list.

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

Definition at line 213 of file debian/libwvstreams-dev/usr/include/wvstreams/wvlinklist.h.

◆ WvList() [2/2]

template<class T>
WvList< T >::WvList ( )
inline

Creates an empty linked list.

Definition at line 204 of file include/wvlinklist.h.

◆ ~WvList() [2/2]

template<class T>
WvList< T >::~WvList ( )
inline

Destroys the linked list.

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

Definition at line 213 of file include/wvlinklist.h.

Member Function Documentation

◆ setup() [1/2]

template<class T>
void WvList< T >::setup ( )
inline

Invoked by subclasses after the linked list is first created.

Definition at line 217 of file debian/libwvstreams-dev/usr/include/wvstreams/wvlinklist.h.

◆ shutdown() [1/2]

template<class T>
void WvList< T >::shutdown ( )
inline

Invoked by subclasses before the linked list is destroyed.

Definition at line 220 of file debian/libwvstreams-dev/usr/include/wvstreams/wvlinklist.h.

◆ zap() [1/2]

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 autofree == true.

Definition at line 228 of file debian/libwvstreams-dev/usr/include/wvstreams/wvlinklist.h.

Referenced by WvList< Data >::~WvList().

◆ first() [1/2]

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

Definition at line 241 of file debian/libwvstreams-dev/usr/include/wvstreams/wvlinklist.h.

◆ last() [1/2]

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

Definition at line 251 of file debian/libwvstreams-dev/usr/include/wvstreams/wvlinklist.h.

◆ add_after() [1/2]

template<class T>
void WvList< T >::add_after ( WvLink * after,
T * data,
bool autofree,
const 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 "autofree" is if true, takes ownership of the element "id" is an optional string to associate with the element, or null

Definition at line 263 of file debian/libwvstreams-dev/usr/include/wvstreams/wvlinklist.h.

Referenced by WvList< Data >::append(), and WvList< Data >::prepend().

◆ append() [1/2]

template<class T>
void WvList< T >::append ( T * data,
bool autofree,
const char * id = NULL )
inline

Appends the element to the end of the list.

"data" is the element pointer, may be null "autofree" is if true, takes ownership of the element "id" is an optional string to associate with the element, or null

Definition at line 276 of file debian/libwvstreams-dev/usr/include/wvstreams/wvlinklist.h.

Referenced by WvList< Data >::add(), and wvtcl_decode().

◆ add() [1/2]

template<class T>
void WvList< T >::add ( T * data,
bool autofree,
const char * id = NULL )
inline

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

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

Definition at line 283 of file debian/libwvstreams-dev/usr/include/wvstreams/wvlinklist.h.

◆ prepend() [1/2]

template<class T>
void WvList< T >::prepend ( T * data,
bool autofree,
const char * id = NULL )
inline

Prepends the element to the beginning of the list.

"data" is the element pointer, may be null "autofree" is if true, takes ownership of the element "id" is an optional string to associate with the element, or null

Definition at line 293 of file debian/libwvstreams-dev/usr/include/wvstreams/wvlinklist.h.

◆ unlink() [1/2]

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 autofree == true.

"data" is the element pointer, may be null

Definition at line 303 of file debian/libwvstreams-dev/usr/include/wvstreams/wvlinklist.h.

◆ unlink_first() [1/2]

template<class T>
void WvList< T >::unlink_first ( )
inline

Unlinks the first element from the list.

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

Definition at line 312 of file debian/libwvstreams-dev/usr/include/wvstreams/wvlinklist.h.

◆ unlink_after() [1/2]

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 autofree == true and destroy == true.

"after" is the link preceeding the element to be removed, non-null

Definition at line 325 of file debian/libwvstreams-dev/usr/include/wvstreams/wvlinklist.h.

Referenced by WvList< Data >::zap().

◆ setup() [2/2]

template<class T>
void WvList< T >::setup ( )
inline

Invoked by subclasses after the linked list is first created.

Definition at line 217 of file include/wvlinklist.h.

◆ shutdown() [2/2]

template<class T>
void WvList< T >::shutdown ( )
inline

Invoked by subclasses before the linked list is destroyed.

Definition at line 220 of file include/wvlinklist.h.

◆ zap() [2/2]

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 autofree == true.

Definition at line 228 of file include/wvlinklist.h.

◆ first() [2/2]

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

Definition at line 241 of file include/wvlinklist.h.

◆ last() [2/2]

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

Definition at line 251 of file include/wvlinklist.h.

◆ add_after() [2/2]

template<class T>
void WvList< T >::add_after ( WvLink * after,
T * data,
bool autofree,
const 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 "autofree" is if true, takes ownership of the element "id" is an optional string to associate with the element, or null

Definition at line 263 of file include/wvlinklist.h.

◆ append() [2/2]

template<class T>
void WvList< T >::append ( T * data,
bool autofree,
const char * id = NULL )
inline

Appends the element to the end of the list.

"data" is the element pointer, may be null "autofree" is if true, takes ownership of the element "id" is an optional string to associate with the element, or null

Definition at line 276 of file include/wvlinklist.h.

◆ add() [2/2]

template<class T>
void WvList< T >::add ( T * data,
bool autofree,
const char * id = NULL )
inline

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

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

Definition at line 283 of file include/wvlinklist.h.

◆ prepend() [2/2]

template<class T>
void WvList< T >::prepend ( T * data,
bool autofree,
const char * id = NULL )
inline

Prepends the element to the beginning of the list.

"data" is the element pointer, may be null "autofree" is if true, takes ownership of the element "id" is an optional string to associate with the element, or null

Definition at line 293 of file include/wvlinklist.h.

◆ unlink() [2/2]

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 autofree == true.

"data" is the element pointer, may be null

Definition at line 303 of file include/wvlinklist.h.

◆ unlink_first() [2/2]

template<class T>
void WvList< T >::unlink_first ( )
inline

Unlinks the first element from the list.

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

Definition at line 312 of file include/wvlinklist.h.

◆ unlink_after() [2/2]

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 autofree == true and destroy == true.

"after" is the link preceeding the element to be removed, non-null

Definition at line 325 of file include/wvlinklist.h.

◆ count() [1/2]

size_t WvListBase::count ( ) const
inherited

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.

◆ count() [2/2]

size_t WvListBase::count ( ) const
inherited

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

◆ reverse() [1/2]

void WvListBase::reverse ( )
inherited

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.

◆ reverse() [2/2]

void WvListBase::reverse ( )
inherited

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

◆ isempty() [1/2]

bool WvListBase::isempty ( ) const
inlineinherited

Quickly determines if the list is empty.

This is much faster than checking count() == 0.

Returns: true if empty

Definition at line 62 of file debian/libwvstreams-dev/usr/include/wvstreams/wvlinklist.h.

◆ isempty() [2/2]

bool WvListBase::isempty ( ) const
inlineinherited

Quickly determines if the list is empty.

This is much faster than checking count() == 0.

Returns: true if empty

Definition at line 62 of file include/wvlinklist.h.

Member Data Documentation

◆ head

WvLink WvListBase::head
inherited

◆ tail

WvLink * WvListBase::tail
inherited

The documentation for this class was generated from the following files: