beautypg.com

HP Integrity NonStop J-Series User Manual

Page 207

background image


// Create a value for elroyPtr_ in memory
// and change elroyPtr_ to point to that
// value in memory:
file >> elroyPtr_;

// Assign reference to value.
// If elroyPtr_ == &elroy then the value of
// elroy_ will already be created but now
// elroyPtr_ != &elroy so an
// RWTOOL_REF exception will be thrown:
file >> elroy_;
}

/* _ */
RWFile file("elmer.dat");
Elmer elmer;
Elmer elmer2;
elmer.elroyPtr_ = &(elmer.elroy_);
/* _ */
file << elmer; // Trouble is coming_
/* _ */
file >> elmer2; // Trouble has arrived. RWTOOL_REF exception!
/* _ */

In the above code, the following statement isomorphically saves elmer to file:

file << elmer;

First, the statement calls the insertion operator:

operator<<(RWFile&, const Elmer&)

Since elmer hasn't been saved yet, the value of elmer will be saved to file and that value will be
added to the isomorphic save table. However, elmer has the members elroy_ and elroyPtr_,
which must be saved as part of saving elmer. The members of elmer are saved in
rwSaveGuts(RWFile&, const Elmer&).

The function rwSaveGuts(RWFile&, const Elmer&) saves elroyPtr_ first, then elroy_. When
rwSaveGuts saves the value *elroyPtr_, it calls the insertion operator operator<<(RWFile&,
const Elroy&).

The insertion operator operator<<(RWFile&, const Elroy&) sees that elmer.elroyPtr_ hasn't been
stored yet, so it saves the value *(elmer.elroyPtr_) to file, and makes a note in the isomorphic
save table that this value has been stored. Then operator<<(RWFile&, const Elroy&) returns to
rwSaveGuts(RWFile&, const Elmer&).

Back in rwSaveGuts(RWFile&, const Elmer&), it's time for elmer.elroy_ to be saved. In this
example, elmer.elroyPtr_ has the same address as elmer.elroy_. Once again the insertion operator

This manual is related to the following products: