Example
This example uses a simple object named book that holds an author name and a book title:
 
class book
{
public:
book ();
book (const RWCString& title, const RWCString& author);
private:
RWCString title_;
RWCString author_;
};
As described in the example in Chapter 3, you must add macros to the header and implementation files to prepare the object for serialization.
*To the header file, add the macro RW_DECLARE_VIRTUAL_STREAM_FNS(), which defines the streamContents() member function:
 
class book
{
RW_DECLARE_VIRTUAL_STREAM_FNS(book)
 
public:
book ();
book (const RWCString& title, const RWCString& author);
 
private:
RWCString title_;
RWCString author_;
};
Add to the header file:
// Add serialization support
RW_DECLARE_STREAMABLE_AS_SELF(book)
RW_DECLARE_STREAMABLE_POINTER(book)
 
*To the implementation file, first add macros that define insertion and extraction operators for the class members:
 
// Define how book will be serialized
RW_BEGIN_STREAM_CONTENTS(book)
RW_STREAM_ATTR_MEMBER(title,title_)
RW_STREAM_ATTR_MEMBER(author,author_)
RW_END_STREAM_CONTENTS
Then add macros that allow the book object itself to be serialized as a pointer reference:
 
// Allow a reference to a book to be serialized
RW_DEFINE_STREAMABLE_POINTER(book)
RW_DEFINE_STREAMABLE_AS_SELF(book)
Now you are ready to look at the example itself.