RWvostreamRWvios RWXDRostream RWios
Member Functions |
flush() operator<<() put() putString() |
#include <rw/xdrstrea.h> XDR xdr; xdrstdio_create(&xdr, stdout, XDR_ENCODE) ; RWXDRostream rw_xdr(&xdr);
Class RWXDRostream is a portable output stream based on XDR routines. Class RWXDRostream encapsulates a portion of the XDR library routines that are used for external data representation. XDR routines allow programmers to describe arbitrary data structures in a machine-independent fashion. Data for remote procedure calls (RPC) are transmitted using XDR routines.
Class RWXDRostream enables one to output from a stream and encode an XDR structure from a machine representation. Class RWXDRostream provides the capability to encode the standard data types and vectors of those data types.
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 an argument to the constructor for a RWXDRostream object.
RWXDRostream can be interrogated as to the status of the stream using member functions bad(), clear(), eof(), fail(), good(), and rdstate().
None
The example that follows is a "writer" program that encodes an XDR structure onto a file stream. The example for class RWXDRistream is the "reader" program that decodes the XDR structures into a machine representation for a data type. 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","w+"); xdrstdio_create(&xdr, fp, XDR_ENCODE); RWXDRostream rw_xdr(&xdr); for(int i=0; i<10; ++i) rw_xdr << i; // encode integer data fclose(fp); }
RWXDRostream(XDR* xp);
Initialize a RWXDRostream from the XDR structure xp.
RWXDRostream(streambuf*);
Initialize RWXDRostream with a pointer to streambuf. streambuf must already be allocated.
RWXDRostream(ostream&);
Initialize RWXDRostream with an output stream.
virtual ~RWXDRostream();
Deallocate previously allocated resources.
virtual RWvostream& operator<<(const char* s);
Redefined from class RWvostream. Store the character string starting at s to the output stream using the XDR format. The character string is expected to be null terminated.
virtual RWvostream& operator<<(char c);
Redefined from class RWvostream. Store the character c to the output stream using the XDR format. Note that c is treated as a character, not a number. This member attempts to preserve the symbolic characters values transmitted over the stream.
virtual RWvostream& operator<<(wchar_t wc);
Redefined from class RWvostream. Store the wide character wc to the output stream using the XDR format. Note that wc is treated as a character, not a number.
virtual RWvostream& operator<<(unsigned char c);
Redefined from class RWvostream. Store the unsigned character c to the output stream using the XDR format. Note that c is treated as a character, not a number.
virtual RWvostream& operator<<(double d);
Redefined from class RWvostream. Store the double d to the output stream using the XDR format.
virtual RWvostream& operator<<(float f);
Redefined from class RWvostream. Store the float f to the output stream using the XDR format.
virtual RWvostream& operator<<(int i);
Redefined from class RWvostream. Store the integer i to the output stream using the XDR format.
virtual RWvostream& operator<<(unsigned int i);
Redefined from class RWvostream. Store the unsigned integer i to the output stream using the XDR format.
virtual RWvostream& operator<<(long l);
Redefined from class RWvostream. Store the long l to the output stream using the XDR format.
virtual RWvostream& operator<<(unsigned long l);
Redefined from class RWvostream. Store the unsigned long l to the output stream using the XDR format.
virtual RWvostream& operator<<(short s);
Redefined from class RWvostream. Store the short s to the output stream using the XDR format.
virtual RWvostream& operator<<(unsigned short );
Redefined from class RWvostream. Store the unsigned short s to the output stream using the XDR format.
virtual RWvostream& put(char c);
Redefined from class RWvostream. Store the character c to the output stream using the XDR format. If the operation fails, it sets the failbit. This member only preserves ASCII numerical codes, not the coresponding character symbol.
virtual RWvostream& put(unsigned char c);
Redefined from class RWvostream. Store the unsigned character c to the output stream using the XDR format. If the operation fails, it sets the failbit.
virtual RWvostream& put(wchar_t wc);
Redefined from class RWvostream. Store the wide character wc to the output stream using the XDR format. If the operation fails, it sets the failbit.
virtual RWvostream& put(const char* p, size_t N);
Redefined from class RWvostream. Store the vector of N characters starting at p to the output stream using the XDR format. If the operation fails, it sets the failbit.
virtual RWvostream& put(const wchar_t* p, size_t N);
Redefined from class RWvostream. Store the vector of N wide characters starting at p to the output stream using the XDR format. If the operation fails, it sets the failbit.
virtual RWvostream& put(const short* p, size_t N);
Redefined from class RWvostream. Store the vector of N shorts starting at p to the output stream using the XDR format. If the operation fails, it sets the failbit.
virtual RWvostream& put(const unsigned short* p, size_t N);
Redefined from class RWvostream. Store the vector of N unsigned shorts starting at p to the output stream using the XDR format. If the operation fails, it sets the failbit.
virtual RWvostream& put(const int* p, size_t N);
Redefined from class RWvostream. Store the vector of N integers starting at p to the output stream using the XDR format. If the operation fails, it sets the failbit.
virtual RWvostream& put(const unsigned int* p, size_t N);
Redefined from class RWvostream. Store the vector of N unsigned integers starting at p to the output stream using the XDR format. If the operation fails, it sets the failbit.
virtual RWvostream& put(const long* p, size_t N);
Redefined from class RWvostream. Store the vector of N longs starting at p to the output stream using the XDR format. If the operation fails, it sets the failbit.
virtual RWvostream& put(const unsigned long* p, size_t N);
Redefined from class RWvostream. Store the vector of N unsigned longs starting at p to the output stream using the XDR format. If the operation fails, it sets the failbit.
virtual RWvostream& put(const float* p, size_t N);
Redefined from class RWvostream. Store the vector of N floats starting at p to the output stream using the XDR format. If the operation fails, it sets the failbit.
virtual RWvostream& put(const double* p, size_t N);
Redefined from class RWvostream. Store the vector of N doubles starting at p to the output stream using the XDR format. If the operation fails, it sets the failbit.
Virtual RWXDRostream& flush();
Send the contents of the stream buffer to output immediately.
Virtual RWXDRostream& putString(const char*s, size_t N);
Store the character string for retrieval by RWXDRistream::getString.