Writing to and Reading from Compact Object Streams With Virtual Streams
This example outputs an object in compact form using virtual streams.
#include <rw/serial/RWCompactObjectOutputStreamImp.h>
#include <rw/serial/RWDataToVirtualOutputStreamImp.h>
#include <rw/pstream.h>
#include <fstream.h>
int main(void)
{
ofstream of(
"RWCompactObjectOutputStreamImpUsingVirtualStreams.out",
ios::out);
RWpostream pstrm(of);
RWDataOutputStream tmpStream =
RWDataToVirtualOutputStreamImp::make(pstrm);
RWObjectOutputStream out =
RWCompactObjectOutputStreamImp::make(tmpStream);
int i = 10;
out << i;
return 0;
}
This example reads in an object, using virtual streams, that was output in compact form.
#include <rw/serial/RWCompactObjectInputStreamImp.h>
#include <rw/serial/RWDataFromVirtualInputStreamImp.h>
#include <rw/pstream.h>
#include <iostream.h>
#include <fstream.h>
int main(void)
{
ifstream ifstrm;
ifstrm.open(
"RWCompactObjectOutputStreamImpUsingVirtualStreams.out",
ios::in | ios::nocreate);
if (!ifstrm)
{
cout << "The file "
<< "'RWCompactObjectOutputStreamImpUsingVirtualStreams.out'"
<< " does not\nexist. "
<< "Please run "
<< "RWCompactObjectInputStreamImpUsingVirtualStreams\n"
<< "before running this file." << endl;
}
else
{
RWpistream pstream(ifstrm);
RWDataInputStream tmpStream =
RWDataFromVirtualInputStreamImp::make(pstream);
RWObjectInputStream in =
RWCompactObjectInputStreamImp::make(tmpStream);
int i;
in >> i;
cout << i << endl;
}
return 0;
}