Tools.h++ Manual
16-2 104011 Tandem Computers Incorporated
16
These function not only allow the storage and retrieval of collections and their
inserted objects, but also their morphology. For example, a collection with
multiple pointers to the same object could be be saved and restored. Or a
circularly linked list.
Note – this ability to restore the morphology of an object is a property of the
base class
RWCollectable
. It can be used by any object that inherits from
RWCollectable
, not just the “Smalltalk-like” collection classes (which inherit
from
RWCollection
, a derived class of
RWCollectable
). We will see how to
do this in folowing chapter.
16.2 Example
Here’s an example of the use of these functions that builds on “Example” on
page 4 in Chapter 15, “Smalltalk-like Collection Classes.”
#define RW_STD_TYPEDEFS 1
#include <rw/bintree.h>
#include <rw/collstr.h>
#include <rw/pstream.h>
main()
{
// Construct an empty collection:
SortedCollection sc;
// Insert, but to make things interesting,
// add an object twice.
RWCollectableString* george = new
RWCollectableString("George");
sc.insert(george); // Insert once
sc.insert(new RWCollectableString("Mary"));
sc.insert(george); // Insert twice
sc.insert(new RWCollectableString("Bill"));
sc.insert(new RWCollectableString("Throkmorton"));