Chapter 3. WvLinkList - type-safe linked lists and iterators

WvLinkList allows you to create type-safe lists of objects, along with appropriate iterators. Lists are used all over the Weaver and WvStreams, and the best way to learn about them is by example -- so read the source code and look at the sample program in testlist.cc.

You might also want to read the top of wvlinklist.h for some implementation details.

A typical use of WvLinkList would be something like this:

	  
#include "wvstring.h"
#include "wvlinklist.h"
   
DeclareWvList(WvString);   // creates class WvStringList
   
int main()
{
    WvStringList l;
    WvStringList::Iter i(l);
    WvString autostr("bork bork");
    
    l.append(new WvString("blah blah"), true); // auto-free enabled
    l.append(&autostr, false); // auto-free disabled: C++ will do this one
    // etc
    
    for (i.rewind(); i.next(); )
    {
	// we will learn a nicer way to do this with WvStream later.
	printf("%s\n", (const char *)i());
    }
    
    // exiting this function will have C++ auto-free the list, which
    // causes the list to auto-free the "blah blah" string.  C++ also
    // auto-frees the "bork bork" string automatically.  It doesn't matter
    // that "bork bork" is freed before the list destructor is called; the
    // list doesn't refer to its members during destruction, unless it
    // needs to free the elements by itself.
}