WvStreams
|
00001 /* 00002 * A WvStringList example. 00003 * 00004 * Some text about this example... 00005 */ 00006 00007 #include "wvstring.h" 00008 #include "wvlinklist.h" 00009 00010 DeclareWvList(WvString); // creates class WvStringList 00011 00012 int main() 00013 { 00014 WvStringList l; 00015 WvStringList::Iter i(l); 00016 WvString autostr("bork bork"); 00017 00018 l.append(new WvString("blah blah"), true); // auto-free enabled 00019 l.append(&autostr, false); // auto-free disabled: C++ will do this one 00020 // etc 00021 00022 for (i.rewind(); i.next(); ) 00023 { 00024 // we will learn a nicer way to do this with WvStream later. 00025 // we could typecast i() to (const char *), but the cstr() member 00026 // function is nicer (we all avoid typecasts when possible, right?) 00027 printf("%s\n", i().cstr()); 00028 } 00029 00030 printf("Is the list empty? %s\n",l.isempty() ? "Yes" : "No"); 00031 00032 printf("The first element is: %s\n", l.first()->cstr()); 00033 printf("The last element is: %s\n", l.last()->cstr()); 00034 00035 // exiting this function will have C++ auto-free the list, which 00036 // causes the list to auto-free the "blah blah" string. C++ also 00037 // auto-frees the "bork bork" string automatically. It doesn't matter 00038 // that "bork bork" is freed before the list destructor is called; the 00039 // list doesn't refer to its members during destruction, unless it 00040 // needs to free the elements by itself. 00041 00042 }