Add RW_DEFINE_PERSISTABLE to One Source File
After you have declared the global storage and retrieval operators, you must define them. The Essential Tools Module provides macros that add code to your source file to define the global functions operator<< and operator>> for storage to and retrieval from RWvistream, RWvostream, and RWFile. RW_DEFINE_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. (You may find, for template classes, that with some compilers the source file must have the same base name as the header file where RW_DECLARE_PERSISTABLE was used.) 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 RW_DEFINE_PERSISTABLE.
RW_DEFINE_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 <rw/epersist.h>
RW_DEFINE_PERSISTABLE(YourClass)
RW_DEFINE_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 RW_DEFINE_PERSISTABLE_TEMPLATE.
RW_DEFINE_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 <rw/epersist.h>
RW_DEFINE_PERSISTABLE_TEMPLATE(YourClass)
RW_DEFINE_PERSISTABLE_TEMPLATE(YourClass) will expand to generate the source code for the following global functions:
 
template<class T>
RWvostream& operator<<
(RWvostream& strm, const YourClass<T>& item)
 
template<class T>
RWvistream& operator>>
(RWvistream& strm, YourClass<T>& obj)
 
template<class T>
RWvistream& operator>>
(RWvistream& strm, YourClass<T>*& pObj)
 
template<class T>
RWFile& operator<<(RWFile& strm, const YourClass<T>& item)
 
template<class T>
RWFile& operator>>(RWFile& strm, YourClass<T>& obj)
 
template<class T>
RWFile& operator>>(RWFile& strm, YourClass<T>*& pObj)
*For templatized classes with more than one and less than five template parameters, use one of the following macros from rw/epersist.h:
 
// For YourClass<T1,T2>:
RW_DEFINE_PERSISTABLE_TEMPLATE_2(YourClass)
// For YourClass<T1,T2,T3>:
RW_DEFINE_PERSISTABLE_TEMPLATE_3(YourClass)
// For YourClass<T1,T2,T3,T4>:
RW_DEFINE_PERSISTABLE_TEMPLATE_4(YourClass)
*If you need to persist templatized classes with five or more template parameters, you can write additional macros for RW_DEFINE_PERSISTABLE_TEMPLATE_n. The macros are found in the header file rw/epersist.h.