beautypg.com

Add rwdefine_persistable to, One source file – HP Integrity NonStop J-Series User Manual

Page 186

background image

// For YourClass:
RWDECLARE_PERSISTABLE_TEMPLATE_4(YourClass)

Remember, if your templatized class has any non-type template parameters, it cannot be
isomorphically persisted.

If you need to persist templatized classes with five or more

template parameters, you can write additional macros for
RWDECLARE_PERSISTABLE_TEMPLATE_n. The macros are found in the header file
rw/edefs.h.

Add RWDEFINE_PERSISTABLE to One Source File

After you have declared the global storage and retrieval operators, you must define them. Tools.h++
provides macros that add code to your source file

[20]

to define the global functions operator<< and

operator>> for storage to and retrieval from

RWvistream

,

RWvostream

, and

RWFile

.

RWDEFINE_PERSISTABLE macros will automatically create global operator<< and operator>>
functions that perform isomorphic persistence duties and call the global persistence functions
rwSaveGuts and rwRestoreGuts for your class. More about rwSaveGuts and rwRestoreGuts later.

Again, your choice of which macro to use is determined by whether your class is templatized, and if
so, how many parameters it requires.

For non-templatized classes, use RWDEFINE_PERSISTABLE.

RWDEFINE_PERSISTABLE is a macro found in rw/epersist.h. To use it, add the following
lines to one and only one source file (*.cpp or *.C):

#include
RWDEFINE_PERSISTABLE(YourClass)

RWDEFINE_PERSISTABLE(YourClass) will expand to generate the source code for (that is,
to define) the following global functions:

RWvostream& operator<<(RWvostream& strm, const YourClass& item)
RWvistream& operator>>(RWvistream& strm, YourClass& obj)
RWvistream& operator>>(RWvistream& strm, YourClass*& pObj)

RWFile& operator<<(RWFile& strm, const YourClass& item)
RWFile& operator>>(RWFile& strm, YourClass& obj)
RWFile& operator>>(RWFile& strm, YourClass*& pObj)

For templatized classes with a single template parameter T, use
RWDEFINE_PERSISTABLE_TEMPLATE.

RWDEFINE_PERSISTABLE_TEMPLATE is also found in rw/epersist.h. To use it, add the
following lines to one and only one source file (*.cpp or *.C):

#include
RWDEFINE_PERSISTABLE_TEMPLATE(YourClass)

This manual is related to the following products: