beautypg.com

Writing rwsaveguts and rwrestoreguts functions, Note – HP Integrity NonStop J-Series User Manual

Page 189

background image

rwRestoreGuts(RWFile& f, YourClass& t) {/*_*/}
templatevoid
rwRestoreGuts(RWvistream& s, YourClass& t) {/*_*/}

For templatized classes with more than one template parameter, define rwRestoreGuts and
rwSaveGuts with the appropriate number of template parameters.

Function rwSaveGuts saves the state of each class member necessary persistence to an

RWvostream

or an

RWFile

. If the members of your class can be persisted (see Table 2 above), and if the necessary

class members are accessible to rwSaveGuts, you can use operator<< to save the class members.

Function rwRestoreGuts restores the state of each class member necessary for persistence from an

RWvistream

or an

RWFile

. Provided that the members of your class are types that can be persisted,

and provided that the members of your class are accessible to rwRestoreGuts, you can use operator>>
to restore the class members.

Writing rwSaveGuts and rwRestoreGuts Functions

The next two sections discuss guidelines for writing rwSaveGuts and rwRestoreGuts global functions.
To illustrate these guidelines, the following class will be used:

class Gut {
public:
int fundamentalType_;
RWCString aRogueWaveObject_;
RWTValDlist anotherRogueWaveObject_;
RWCollectableString anRWCollectable_
RWCollectableString* pointerToAnRWCollectable_;
Gut* pointerToAnObject_;
};

The discussion in the next two sections describes how to write rwSaveGuts and rwRestoreGuts
functions for non-templatized classes. However, the descriptions also apply to the templatized
rwSaveGuts and rwRestoreGuts that are written for templatized classes.

Guidelines for Writing rwSaveGuts

The global overloaded functions:

rwSaveGuts(RWFile& f, const YourClass& t)
rwSaveGuts (RWvostream& s, const YourClass& t)

are responsible for saving the internal state of a YourClass object to either a binary file (using class

RWFile

) or to a virtual output stream (an

RWvostream

). This allows the object to be restored at some

later time.

The rwSaveGuts functions that you write must save the state of each member in YourClass, including
the members of the class that you inherited from
.

How you write the functions depends upon the type of the member data:

To save member data that are either C++ fundamental types (int, char, float,_), or most Rogue

This manual is related to the following products: