Tools.h++ Manual
17-2 104011 Tandem Computers Incorporated
17
(RWBoolean is a typedef for an 
int
, 
RWspace 
is a typedef for 
unsigned 
long
, and 
RWClassID 
is a typedef for an 
unsigned short
.) Any class that 
derives from class 
RWCollectable 
should be able to understand any of these 
methods. Although default definitions are given for all of them in the base 
class 
RWCollectable
, it is best for the class designer to provide definitions 
that are tailored to the class at hand.
17.2 Example
Suppose we are running a bus company. We want to write a class that 
represents a bus, its set of potential customers, and its set of actual passengers. 
In order to be a passenger, you must be a customer. Hence, the set of 
customers is a superset of the set of passengers. Because a person can 
physically be on the bus only once, and there is no point in putting the same 
person on the customer list more than once, we want to make sure there are no 
duplicates in either list.
We must be careful when it comes time to persist the bus. If we naïvely iterate 
over the set of customers and then over the set of passengers, saving each one, 
then if a person is both a customer and a passenger we will save him twice. 
When the bus is restored, instead of the list of passengers referring to people 
already in the customer list, it will have its own separate instances.
We need some way of recognizing when a person has already been saved to 
the stream and, instead of saving him or her again, merely save a reference to 
the previous instance.
This is the job of class 
RWCollectable
. Objects inheriting from 
RWCollectable 
have the ability to save not only their contents, but also their 
relationships with other objects inheriting from 
RWCollectable
. We call this 
isomorphic persistence.
Here’s how we might declare our class Bus:
class Bus : public RWCollectable
{
RWDECLARE_COLLECTABLE(Bus)
public:










