Tools.h++ Manual
104011 Tandem Computers Incorporated 17-3
17
Note – how class Bus inherits from
RWCollectable
. We have chosen to
implement the set of customers by using class
RWSet
. This will guarantee that
the same person is not entered into the customer list more than once. For the
same reason, we have also chosen to implement the set of passengers using
class
RWSet
. However, for novelty, we have chosen to have this set live on the
heap. This will serve to illustrate some points in the coming discussion.
17.3 Steps to making an RWCollectable object
Here are the general steps to making your object inherit from
RWCollectable
. Specific details are given below.
Bus();
Bus(int busno, const RWCString& driver);
~Bus();
// Inherited from class "RWCollectable":
RWspace binaryStoreSize() const;
int compareTo(const RWCollectable*) const;
RWBoolean isEqual(const RWCollectable*) const;
unsigned hash() const;
void restoreGuts(RWFile&);
void restoreGuts(RWvistream&);
void saveGuts(RWFile&) const;
void saveGuts(RWvostream&) const;
void addPassenger(const char* name);
void addCustomer(const char* name);
size_t customers() const;
size_t passengers() const;
RWCString driver() const {return driver_;}
int number() const {return busNumber_;}
private:
RWSet customers_;
RWSet* passengers_;
int busNumber_;
RWCString driver_;
};