Polymorphically Persisting Custom Collections
The versions of saveGuts() and restoreGuts() that the Essential Tools Module built into class RWCollection are sufficient for most collection classes. The function RWCollection::saveGuts() works by repeatedly calling:
 
RWvostream& operator<<(RWvostream&, const RWCollectable&);
for each item in the collection. Similarly, RWCollection::restoreGuts() works by repeatedly calling:
 
RWvistream& operator>>(RWvistream&, RWCollectable*&);
This operator allocates a new object of the proper type off the heap, then calls insert(). Because all of the Rogue Wave Smalltalk-like collection classes inherit from RWCollection, they all use this mechanism.
If you decide to write your own collection classes that inherit from class RWCollection, you will rarely have to define your own saveGuts() or restoreGuts().
There are exceptions. For example, class RWBinaryTree has its own version of saveGuts(). This is necessary because the default version of saveGuts() stores items in order. For a binary tree, this would result in a severely unbalanced tree when the tree was read back in—essentially, the degenerate case of a linked list. Hence, RWBinaryTree’s version of saveGuts() stores the tree level-by-level.
When you design your class, you must determine whether it has similar special requirements which may need a custom version of saveGuts() and restoreGuts().