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*&);
If the original
passengers_ is non-nil, then this function restores a new
RWSet off the heap and returns a pointer to it. Otherwise, it returns a nil pointer. Either way, the old contents of
passengers_ are replaced. Hence, we must call
delete passengers_ first.