/**** * * Class StrList specializes class List, defined in list.h. Each List selector * is specialized to return StrListElem's instead of plain ListElem's. This * avoids the need for casts in outside calling functions. This is the * recommended specialization for subclasses of List and ListElem. * * In addition to selector specializations, ListElem is specialized to * StrListElem, with the abstract structure. * * |-------------------------------| * | string key | * |-------------------------------| * | void* auxilliary data | * |-------------------------------| * * Nested (Lisp-like) lists can be constructed by using the aux data field as a * sublist pointer. Such nested lists are obviously weakly typed. * Strongly-typed list specializations can be defined by further specializing * StrListElem, and supplying appropriately typed access functions. * */ #ifndef strlistIncluded #define strlistIncluded #include "list.h" #include "str.h" class StrListElem; class StrList : public List { public: StrListElem* Pull(); StrListElem* Pop(); StrListElem* GetNth(int n); StrListElem* RemoveNth(int n); StrListElem* Find(String* k); int FindPos(String* k); StrListElem* Find(const char* k); int FindPos(const char* k); StrListElem* Enum(); StrList* Sort(bool ascending = true); }; /* * StrListElem specializes list.h:ListElem. */ class StrListElem : public ListElem { public: StrListElem(String* initval, void* initauxval = null); /* * Construct a new element with the given initial values for data and * auxdata. */ StrListElem(char* initval, void* initauxval = null); /* * Obvious overload of preceding constructor. */ virtual ~StrListElem(); /* * Deep delete this; i.e., delete this->data. */ virtual ListElemKey* GetKey(); int Compare(ListElem* e); /* * Compare this with e as pointers. */ virtual int Compare(ListElemKey* k); /* * Compare this->data with e->data, using String::Compare. */ void Print(); /* * Print this by string printing this->data->ConstConvert(). */ String* GetData(); /* * Return this->data. */ void* GetAuxData(); /* * Return this->auxdata. */ protected: String* data; // The string rep of this. void* auxdata; // The untyped whatever-you-like rep of this }; #endif