Tools.h++ Class Reference

Table Of Contents
An XDR stream must first be created by calling the appropriate creation routine. XDR streams
currently exist for encoding/decoding of data to or from standard iostreams and file streams,
TCP/IP connections and Unix files, and memory. These creation routines take arguments that
are tailored to the specific properties of the stream. After the XDR stream has been created, it
can then be used as the argument to the constructor for a RWXDRistream object.
RWXDRistream can be interrogated as to the status of the stream using member functions
bad(), clear(), eof(), fail(), good(), and rdstate().
Persistence
None
Example
The example that follows is a "reader" program that decodes an XDR structure from a file
stream. The example for class RWXDRostream is the "writer" program that encodes the XDR
structures onto the file stream.
The library that supports XDR routines must be linked in. The name of this library is not
standard.
#include <rw/xdrstrea.h>
#include <rw/rstream.h>
#include <stdio.h>
main(){
XDR xdr;
FILE* fp = fopen("test","r+");
xdrstdio_create(&xdr, fp, XDR_DECODE);
RWXDRistream rw_xdr(&xdr);
int data;
for(int i=0; i<10; ++i) {
rw_xdr >> data; // decode integer data
if(data == i)
cout << data << endl;
else
cout << "Bad input value" << endl;
}
fclose(fp);
}