Source File Macros
Preparing the source file to define a serializable class is nearly as straightforward as modifying the header file. As in the case of the class declaration, there are two primary macros you must place in the source file.
*RW_DEFINE_STREAMABLE_POINTER(className)
Apply this macro to all classes involved in the serialization, including abstract base classes, non-abstract base classes, and derived classes. For abstract base classes, apply only this macro.
*RW_DEFINE_STREAMABLE_AS_SELF(className)
Apply this macro to a class if its instantiations will be serialized as pointers directly to the instantiations. This macro can be applied to non-abstract base classes or derived classes. It cannot be applied to abstract base classes because the macro generates code for the instantiation of the class, which is impossible for abstract base classes.
*RW_DEFINE_STREAMABLE_AS_BASE(derivedClass,baseClass)
Apply this macro to a class derived from a base class if its instantiations will be serialized as pointers to the base class. The base class may be either abstract or non-abstract. The important distinction is that the derived class is being serialized through virtual indirection.
Be sure to indicate all inheritance relationships with RW_DEFINE_STREAMABLE_AS_BASE. For instance, if you have the inheritance relationship C->B->A (C inherits from B, which inherits from A), you need to add the following three lines:
RW_DEFINE_STREAMABLE_AS_BASE(B, A)
RW_DEFINE_STREAMABLE_AS_BASE(C, B)
RW_DEFINE_STREAMABLE_AS_BASE(C, A)
Just having
RW_DEFINE_STREAMABLE_AS_BASE(B, A)
RW_DEFINE_STREAMABLE_AS_BASE(C, B)
is not enough to allow serializing a C* through an A*.
The streaming support macros also include a set of helper macros to help you define the streamContents() member function used for object serialization. The ones you’ll use most often are:
*RW_BEGIN_STREAM_CONTENTS(className)
Begins the streamContents() function.
*RW_END_STREAM_CONTENTS
Ends the streamContents() function.
*RW_STREAM_ATTR_GET_SET(attrName, attrType, get, set)
Streams the member data accessed by get() and set() member functions.
*RW_STREAM_ATTR_MEMBER(attrName, memberName)
Streams the member data indicated by memberName using the label attrName.
*RW_STREAM_PARENT(parentClass)
If your serializable class is derived from a serializable base class, place RW_STREAM_PARENT(parentClass) just after the begin macro. This calls streamContents() on the base class, effectively chaining the function calls to stream the contents of the base class before streaming the derived class.