Click on the banner to return to the Class Reference home page.

©Copyright 1996 Rogue Wave Software

RWXDRistream (Unix only)


             RWvistreamRWvios
RWXDRistream
             RWios

Synopsis

#include <rw/xdrstrea.h>
XDR xdr;
xdrstdio_create(&xdr, stdin, XDR_DECODE);
RWXDRistream rw_xdr(&xdr);

Description

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().

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);
}

Public Constructor

RWXDRistream(XDR* xp);
RWXDristream(streambuf*);
RWXDRistream(istream&);

Public Destructor

~virtual RWXDRistream();




Public Member Functions

virtual int
get();
virtual RWvistream&
get(char& c);
virtual RWvistream&
get(wchar_t& wc);
virtual RWvistream&
get(unsigned char& c);
virtual RWvistream&
get(char* v, size_t N);
virtual RWvistream&
get(unsigned char* v, size_t N);
virtual RWvistream&
get(double* v, size_t N);
virtual RWvistream&
get(float* v, size_t N);
virtual RWvistream&
get(int* v, size_t N);
virtual RWvistream&
get(unsigned int* v, size_t N);
virtual RWvistream&
get(long* v, size_t N);
virtual RWvistream&
get(unsigned long* v, size_t N);
virtual RWvistream&
get(short* v, size_t N);
virtual RWvistream&
get(unsigned short* v, size_t N);
virtual RWvistream&
get(wchar_t* v, size_t N);
virtual RWvistream&
getString(char* s, size_t maxlen);
virtual RWvistream&
operator>>(char& c );
virtual RWvistream&
operator>>(double& d);
virtual RWvistream&
operator>>(float& f);
virtual RWvistream&
operator>>(int&  i);
virtual RWvistream&
operator>>(long& l);
virtual RWvistream&
operator>>(short& s);
virtual RWvistream&
operator>>(wchar_t& wc);
virtual RWvistream&
operator>>(unsigned char& c);
virtual RWvistream&
operator>>(unsigned int& i);
virtual RWvistream&
operator>>(unsigned long& l);
virtual RWvistream&
operator>>(unsigned short& s);