beautypg.com

HP Integrity NonStop J-Series User Manual

Page 193

background image

This code can distinguish between new Developers and existing

Developers because the insertion operators generated by RWDEFINE_PERSISTABLE(Developer)
keep track of Developers that have been stored previously. The insertion operator, operator<<, calls
the rwSaveGuts if and only if a Developer has not yet been stored in the stream by operator<<.

When a Developer object is restored, the extraction operator, operator>>, for Developer is called.
Like the insertion operators, the extraction operators are generated by
RWDEFINE_PERSISTABLE(Developer). If a Developer object has already been restored, then the
extraction operator will adjust the Developer::alias_ pointer so that it points to the already existing
Developer. If the Developer has not yet been restored, then rwRestoreGuts for Developer will be
called.

After restoring Developer::name_ , rwRestoreGuts for Developer restores a Boolean value to
determine whether Developer::alias_ should point to a Developer in memory or not. If the Boolean is
true, then alias_ should point to a Developer, so rwRestoreGuts restores the Developer object. Then
rwRestoreGuts updates alias_ to point to the restored Developer.

The isomorphic persistence storage and retrieval process described above for Developer.alias_ can
also be applied to the Developer pointers in Team.

Here is the code:

#include // For user output.
#include
#include
#include
#include
//------------------ Declarations ---------------------
//------------------- Developer -----------------------
class Developer {
public:
Developer
(const char* name = "", Developer* anAlias = rwnil)
: name_(name), alias_(anAlias) {}
RWCString name_;
Developer* alias_;
};
#include
RWDECLARE_PERSISTABLE(Developer)
//--------------------- Team --------------------------
class Team {
public:
Developer* member_[3];
};
RWDECLARE_PERSISTABLE(Team);
//---------- rwSaveGuts and rwRestoreGuts -------------
//------------------- Developer -----------------------
RWDEFINE_PERSISTABLE(Developer)
// This macro generates the following insertion and extraction

This manual is related to the following products: