Isomorphic persistence of a user-designed class – HP Integrity NonStop J-Series User Manual
Page 192

stream >> isValid; // Is it a nil pointer?
if (isValid) // No,
stream >> gut.pointerToAnObject_; // restore the pointer.
else // Yes,
gut.pointerToAnObject_ = rwnil; // set pointer to nil.
}
void rwRestoreGuts(RWFile& stream, Gut& gut) {
// The body of this function is identical to
// rwRestoreGuts(RWvostream& stream, Gut& gut).
}
Isomorphic Persistence of a User-designed Class
described some example code that implements simple persistence on a collection that
includes pointers. That example illustrated how simple persistence does not maintain the original
collection's morphology.
This example implements isomorphic persistence on the collection we set up in Example Two: Team,
which contains three Developers. Figure 7 shows the morphology of the original Team collection and
of the Team collection after we saved and restored it with isomorphic persistence.
Figure 7. Isomorphic Persistence
As you read the code, notice how the Developer::alias_ member, which points to other Developers, is
saved and restored. You'll find that after saving Developer::name_ , the rwSaveGuts function for
Developer checks to see if alias_ is pointing to a Developer in memory. If not, rwSaveGuts stores a
Boolean false to signify that alias_ is a nil pointer. If alias_ is pointing to a Developer, rwSaveGuts
stores a Boolean true. It is only afterwards that rwSaveGuts finally stores the value of the Developer
that alias_ is pointing to.