WvStreams
wvlistex.cc
1 /*
2  * A WvStringList example.
3  *
4  * Some text about this example...
5  */
6 
7 #include "wvstring.h"
8 #include "wvlinklist.h"
9 
10 DeclareWvList(WvString); // creates class WvStringList
11 
12 int main()
13 {
14  WvStringList l;
15  WvStringList::Iter i(l);
16  WvString autostr("bork bork");
17 
18  l.append(new WvString("blah blah"), true); // auto-free enabled
19  l.append(&autostr, false); // auto-free disabled: C++ will do this one
20  // etc
21 
22  for (i.rewind(); i.next(); )
23  {
24  // we will learn a nicer way to do this with WvStream later.
25  // we could typecast i() to (const char *), but the cstr() member
26  // function is nicer (we all avoid typecasts when possible, right?)
27  printf("%s\n", i().cstr());
28  }
29 
30  printf("Is the list empty? %s\n",l.isempty() ? "Yes" : "No");
31 
32  printf("The first element is: %s\n", l.first()->cstr());
33  printf("The last element is: %s\n", l.last()->cstr());
34 
35  // exiting this function will have C++ auto-free the list, which
36  // causes the list to auto-free the "blah blah" string. C++ also
37  // auto-frees the "bork bork" string automatically. It doesn't matter
38  // that "bork bork" is freed before the list destructor is called; the
39  // list doesn't refer to its members during destruction, unless it
40  // needs to free the elements by itself.
41 
42 }
WvString
WvString is an implementation of a simple and efficient printable-string class.
Definition: wvstring.h:329
WvStringList
This is a WvList of WvStrings, and is a really handy way to parse strings.
Definition: wvstringlist.h:27