RWvistreamRWvios RWXDRistream RWios
Member Functions |
get() getString() operator>>() |
#include <rw/xdrstrea.h> XDR xdr; xdrstdio_create(&xdr, stdin, XDR_DECODE); RWXDRistream rw_xdr(&xdr);
Class RWXDRistream is a portable input stream based on XDR routines. Class RWXDRistream 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 RWXDRistream enables one to decode an XDR structure to a machine representation. Class RWXDRistream provides the capability to decode all 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 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().
None
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); }
RWXDRistream(XDR* xp);
Initialize an RWXDRistream from the XDR structure xp.
RWXDristream(streambuf*);
Initialize RWXDRistream with a pointer to streambuf. Streambuf must be already allocated.
RWXDRistream(istream&);
Initialize RWXDRistream with an input stream.
~virtual RWXDRistream();
Deallocate previously allocated resources.
virtual int get();
Redefined from class RWvistream. Gets and returns the next character from the XDR input stream. If the operation fails, it sets the failbit and returns EOF.
virtual RWvistream& get(char& c);
Redefined from class RWvistream. Gets the next character from the XDR input stream and stores it in c. If the operation fails, it sets the failbit. This member only preserves ASCII numerical codes, not the coresponding character symbol.
virtual RWvistream& get(wchar_t& wc);
Redefined from class RWvistream. Gets the next wide character from the XDR input stream and stores it in wc. If the operation fails, it sets the failbit.
virtual RWvistream& get(unsigned char& c);
Redefined from class RWvistream. Gets the next unsigned character from the XDR input stream and stores it in c. If the operation fails, it sets the failbit.
virtual RWvistream& get(char* v, size_t N);
Redefined from class RWvistream. Gets a vector of N characters from the XDR input stream and stores them in v. If the operation fails, it sets the failbit.
virtual RWvistream& get(unsigned char* v, size_t N);
Redefined from class RWvistream. Gets a vector of N unsigned characters from the XDR input stream and stores them in v. If the operation fails, it sets the failbit.
virtual RWvistream& get(double* v, size_t N);
Redefined from class RWvistream. Gets a vector of N doubles from the XDR input stream and stores them in v. If the operation fails, it sets the failbit.
virtual RWvistream& get(float* v, size_t N);
Redefined from class RWvistream. Gets a vector of N floats from the XDR input stream and stores them in v. If the operation fails, it sets the failbit.
virtual RWvistream& get(int* v, size_t N);
Redefined from class RWvistream. Gets a vector of N ints from the XDR input stream and stores them in v. If the operation fails, it sets the failbit.
virtual RWvistream& get(unsigned int* v, size_t N);
Redefined from class RWvistream. Gets a vector of N unsigned ints from the XDR input stream and stores them in v. If the operation fails, it sets the failbit.
virtual RWvistream& get(long* v, size_t N);
Redefined from class RWvistream. Gets a vector of N longs from the XDR input stream and stores them in v. If the operation fails, it sets the failbit.
virtual RWvistream& get(unsigned long* v, size_t N);
Redefined from class RWvistream. Gets a vector of N unsigned longs from the XDR input stream and stores them in v. If the operation fails, it sets the failbit.
virtual RWvistream& get(short* v, size_t N);
Redefined from class RWvistream. Gets a vector of N shorts from the XDR input stream and stores them in v. If the operation fails, it sets the failbit.
virtual RWvistream& get(unsigned short* v, size_t N);
Redefined from class RWvistream. Gets a vector of N unsigned shorts from the XDR input stream and stores them in v. If the operation fails, it sets the failbit.
virtual RWvistream& get(wchar_t* v, size_t N);
Redefined from class RWvistream. Gets a vector of N wide characters from the XDR input stream and stores them in v. If the operation fails, it sets the failbit.
virtual RWvistream& getString(char* s, size_t maxlen);
Redefined from class RWvistream. Restores a character string from the XDR input stream that was stored to the XDR output stream with RWXDRistream::putstring and stores the characters in the array starting at s. The function stops reading at the end of the string or after maxlen-1 characters, whichever comes first. If maxlen-1 characters have been read and the maxlenth character is not the string terminator, then the failbit of the stream will be set. In either case, the string will be terminated with a null byte.
virtual RWvistream& operator>>(char& c );
Redefined from class RWvistream. Gets the next character from the XDR input stream and stores it in c. If the operation fails, it sets the failbit. This member attempts to preserve the symbolic characters' values transmitted over the stream.
virtual RWvistream& operator>>(double& d);
Redefined from class RWvistream. Gets the next double from the XDR input stream and stores it in d. If the operation fails, it sets the failbit.
virtual RWvistream& operator>>(float& f);
Redefined from class RWvistream. Gets the next float from the XDR input stream and stores it in f. If the operation fails, it sets the failbit.
virtual RWvistream& operator>>(int& i);
Redefined from class RWvistream. Gets the next integer from the XDR input stream and stores it in i. If the operation fails, it sets the failbit.
virtual RWvistream& operator>>(long& l);
Redefined from class RWvistream. Gets the next long from the XDR input stream and stores it in l. If the operation fails, it sets the failbit.
virtual RWvistream& operator>>(short& s);
Redefined from class RWvistream. Gets the next short from the XDR input stream and stores it in s. If the operation fails, it sets the failbit.
virtual RWvistream& operator>>(wchar_t& wc);
Redefined from class RWvistream. Gets the next wide character from the XDR input stream and stores it in wc. If the operation fails, it sets the failbit.
virtual RWvistream& operator>>(unsigned char& c);
Redefined from class RWvistream. Gets the next unsigned character from the XDR input stream and stores it in c. If the operation fails, it sets the failbit.
virtual RWvistream& operator>>(unsigned int& i);
Redefined from class RWvistream. Gets the next unsigned integer from the XDR input stream and stores it in i. If the operation fails, it sets the failbit.
virtual RWvistream& operator>>(unsigned long& l);
Redefined from class RWvistream. Gets the next unsigned long from the XDR input stream and stores it in l. If the operation fails, it sets the failbit.
virtual RWvistream& operator>>(unsigned short& s);
Redefined from class RWvistream. Gets the next unsigned short from the XDR input stream and stores it in s. If the operation fails, it sets the failbit.