Tools.h++ Manual
17-12 104011 Tandem Computers Incorporated
17
With these rules in mind, here is a possible deļ¬nition for our
Bus
example:
Member data
busNumber_
is a C++ primitive, that is, an
int
. It is stored
directly using
RWFile::Write(int)
in the case of
RWFiles
, or
RWvostream::operator<<(int)
in the case of virtual streams.
Member data
driver_
is a
RWCString
. It does not inherit from
RWCollectable
. It is stored using
RWvostream& operator<<(RWvostream&, const RWCString&);
Member data
customers_
is a
RWSet
. It does inherit from
RWCollectable
.
It is stored using
RWvostream& operator<<(RWvostream&, const
RWCollectable&);
Finally, member data passengers_ is a little tricky. It is a pointer to an
RWSet
which inherits from
RWCollectable
. However, there is the possibility that
the pointer is nil. If it were, then passing it to
RWvostream& operator<<(RWvostream&, const
RWCollectable&);
void Bus::saveGuts(RWFile& f) const
{
RWCollectable::saveGuts(f); // Save base class
f.Write(busNumber_); // Write primitive directly
f << driver_ << customers_; // Use Tools.h++ provided
versions
f << passengers_; // Will detect nil pointer
automatically
}
void Bus::saveGuts(RWvostream& strm) const
{
RWCollectable::saveGuts(strm); // Save base class
strm << busNumber_; // Write primitives directly
strm << driver_ << customers_; // Use Tools.h++ provided
versions
strm << passengers_; // Will detect nil pointer
automatically
}