HP Integrity NonStop J-Series User Manual
Page 225

Member data busNumber_ is an int, a C++ primitive. It is stored directly using either
RWFile::Write(int), or RWvostream::operator<<(int).
Member data driver_ is an
RWCString
. It does not inherit from
RWCollectable
. It is stored using:
RWvostream& operator<<(RWvostream&, const RWCString&);
Member data customers_ is an
RWSet
. It does inherit from
RWCollectable
. It is stored using:
RWvostream& operator<<(RWvostream&, const RWCollectable&);
Finally, member data passengers_ is a little tricky. This data is a pointer to an
RWSet,
which
inherits from
RWCollectable
. However, there is the possibility that the pointer is nil. If it is nil, then
passing it to:
RWvostream& operator<<(RWvostream&, const RWCollectable&);
would be disastrous, as we would have to dereference passengers_:
strm << *passengers_;
Instead, since our class has declared passenger_ as an
RWSet
*, we pass it to:
RWvostream& operator<<(RWvostream&, const RWCollectable*);
which automatically detects the nil pointer and stores a record of it.
Virtual Functions restoreGuts(RWFile&) and restoreGuts(RWvistream&)
In a manner similar to saveGuts(), these virtual functions are used to restore the internal state of an
RWCollectable
from a file or stream. Here is a definition of these functions for the Bus class:
void Bus::restoreGuts(RWFile& f)
{ RWCollectable::restoreGuts(f); // Restore base class
f.Read(busNumber_); // Restore primitive
f >> driver_ >> customers_; // Uses Rogue Wave provided
// versions
delete passengers_; // Delete old RWSet
f >> passengers_; // Replace with a new one
}
void Bus::restoreGuts(RWvistream& strm)
{ RWCollectable::restoreGuts(strm); // Restore base class
strm >> busNumber_ >> driver_ >> customers_;
delete passengers_; // Delete old RWSet
strm >> passengers_; // Replace with a new one
}
Note that the pointer passengers_ is restored using:
RWvistream& operator>>(RWvistream&, RWCollectable*&);