SourcePro : Essential Tools Module User's Guide : Persistence : Isomorphic Persistence : Designing Your Class to Use Isomorphic Persistence
Designing Your Class to Use Isomorphic Persistence
Table 17 lists the Essential Tools Module classes that implement isomorphic persistence. You can also add isomorphic persistence to an existing class, even if you only have the header files for that class. Before you can add isomorphic persistence to a class, it must meet the following requirements:
*Class T must have appropriate default and copy constructors defined or generated by the compiler:
 
T(); // default constructor
T(T& t); // copy constructor
*Class T must have an assignment operator defined as a member or as a global function:
 
T& operator=(const T& t); // member function
T& operator=(T& lhs, const T& rhs); // global function
*On some older compilers, Class T cannot have any non-type template parameters. For example, in RWTBitVec<Size>, “size” is placeholder for a value rather than a type. The global functions used to implement isomorphic persistence (rwRestoreGuts() and rwSaveGuts()) are function templates when they are used to persist templatized classes.
*Class T must use the macros RW_DECLARE_PERSISTABLE and RW_DEFINE_PERSISTABLE or their equivalents. More about this in Add RW_DECLARE_PERSISTABLE to Your Header File and Add RW_DEFINE_PERSISTABLE to One Source File.
*All the data necessary to recreate an instance of Class T must be globally available (have accessor functions). If you can't make this data available, you can't implement isomorphic persistence. More about this in Make All Necessary Class Data Available.
If your class T will be stored in a C++ Standard Library container or a C++ Standard Library-based collection, you may need to implement operator<(const T&, const T&) and operator==(const T&, const T&). See Example Using the Essential Tools Module with the C++ Standard Library for more information.
To create an isomorphically persistent class or to add isomorphic persistence to an existing class, follow these steps:
1. Make all necessary class data available.
2. Add RW_DECLARE_PERSISTABLE to your header file.
3. Add RW_DEFINE_PERSISTABLE to one source file.
4. Check for possible problems.
5. Define rwSaveGuts() and rwRestoreGuts().