Writing to and Reading from Compact Object Streams
This example outputs an object in compact format, using streams from the Streams package.
#include <rw/serial/RWCompactObjectOutputStreamImp.h>
#include <rw/stream/RWNativeDataToByteOutputStreamImp.h>
#include <rw/stream/RWByteToStreambufOutputStreamImp.h>
#include <fstream.h>
int main(void)
{
filebuf fbuf;
fbuf.open("RWCompactObjectOutputStreamImp.out",
ios::out | ios::binary);
RWByteOutputStream& tmpBStream =
RWByteToStreambufOutputStreamImp::make(fbuf);
RWDataOutputStream tmpDStream =
RWNativeDataToByteOutputStreamImp::make(tmpBStream);
RWObjectOutputStream out =
RWCompactObjectOutputStreamImp::make(tmpDStream);
int i = 5;
out << i;
return 0;
}
This example reads an object in that was output in compact form.
#include <rw/serial/RWCompactObjectInputStreamImp.h>
#include <rw/stream/RWNativeDataFromByteInputStreamImp.h>
#include <rw/stream/RWByteFromStreambufInputStreamImp.h>
#include <iostream.h>
#include <rw/rwfile.h>
#include <fstream.h>
int main(void)
{
filebuf fbuf;
if (!RWFile::Exists("RWCompactObjectOutputStreamImp.out") )
{
cout << "The file 'RWCompactObjectOutputStreamImp.out'"
<< " does not exist.\n"
<< "You must run "
<< "RWCompactObjectOuputStreamImp"
<< "before running this file." << endl;
}
else
{
fbuf.open("RWCompactObjectOutputStreamImp.out",
ios::in|ios::binary);
RWByteInputStream& tmpBStream =
RWByteFromStreambufInputStreamImp::make(fbuf);
RWDataInputStream tmpStream =
RWNativeDataFromByteInputStreamImp::make(tmpBStream);
RWObjectInputStream in =
RWCompactObjectInputStreamImp::make(tmpStream);
int i;
in >> i;
cout << i << endl;
}
return 0;
}