Second Change
Define the streamContents() function for this class. Some of the macros that do this are:
RW_BEGIN_STREAM_CONTENTS() RW_STREAM_PARENT() RW_STREAM_ATTR_GET_SET() RW_STREAM_ATTR_MEMBER() RW_END_STREAM_CONTENTS() Using these macros provides a built-in symmetry between the input and the output operations on the class. The macros defining the streamContents() function can be placed in any module, but are normally put in the same source file as the other definitions for that class. The following example from shows what it looks like for the real_property class.
// examples\serial\simple\real_property.cpp
RW_BEGIN_STREAM_CONTENTS(real_property) // 1
{
RW_STREAM_ATTR_MEMBER(address, address_) // 2
RW_STREAM_ATTR_MEMBER(size, size_)
}
RW_END_STREAM_CONTENTS // 3
Now that these macros have been added to real_property, this class can be written to and read from object streams using the operators operator<<(RWObjectOutputStream&, const real_property&) and operator>>(RWObjectInputStream&, real_property&), respectively. The following code shows how an instance of class real_property can be written to a file and read back.
// examples\serial\simple\real_estate.cpp
real_property real1("1980 Main St. Corvallis, Oregon","50x100"); // 1
real_property real2;
{ // 2
ofstream fout("real_estate.dat"); // 3
RWpostream posstr(fout);
RWObjectOutputStream out = RWCompactObjectOutputStreamImp::make(
RWDataToVirtualOutputStreamImp::make(
postr)); // 4
out << real1; // 5
}
ifstream fin("real_estate.dat"); // 6
RWpistream pistr(fin);
RWObjectInputStream in = RWCompactObjectInputStreamImp::
make(RWDataFromVirtualInputStreamImp::
make(pistr)); // 7
in >> real2; // 8