rwlogo
SourcePro C++ 12.0

SourcePro® C++ API Reference Guide



   SourcePro C++
Documentation Home

RWpistream Class Reference
[Virtual Streams]

Specializes the abstract base class RWvistream to restore variables stored in a portable US-ASCII format by RWpostream. More...

#include <rw/pstream.h>

Inheritance diagram for RWpistream:
RWvistream RWvios

List of all members.

Public Member Functions

 RWpistream (std::istream &str)
 RWpistream (std::streambuf *s)
virtual ~RWpistream ()
virtual int eof ()
virtual int fail ()
virtual int bad ()
virtual int good ()
virtual int rdstate ()
virtual void clear (int v=0)
std::istream & std ()
const std::istream & std () const
virtual int get ()
virtual RWvistreamget (char &c)
virtual RWvistreamget (wchar_t &wc)
virtual RWvistreamget (unsigned char &c)
virtual RWvistreamget (char *v, size_t N)
virtual RWvistreamget (long double *v, size_t N)
virtual RWvistreamget (long long *v, size_t N)
virtual RWvistreamget (unsigned long long *v, size_t N)
virtual RWvistreamget (double *v, size_t N)
virtual RWvistreamget (float *v, size_t N)
virtual RWvistreamget (int *v, size_t N)
virtual RWvistreamget (long *v, size_t N)
virtual RWvistreamget (short *v, size_t N)
virtual RWvistreamget (wchar_t *v, size_t N)
virtual RWvistreamget (unsigned char *v, size_t N)
virtual RWvistreamget (unsigned short *v, size_t N)
virtual RWvistreamget (unsigned int *v, size_t N)
virtual RWvistreamget (unsigned long *v, size_t N)
virtual RWvistreamgetString (char *s, size_t N)
virtual RWvistreamgetSizeT (size_t &sz)
virtual RWvistreamoperator>> (char &c)
virtual RWvistreamoperator>> (double &d)
virtual RWvistreamoperator>> (float &f)
virtual RWvistreamoperator>> (int &i)
virtual RWvistreamoperator>> (long &i)
virtual RWvistreamoperator>> (short &i)
virtual RWvistreamoperator>> (long double &d)
virtual RWvistreamoperator>> (long long &i)
virtual RWvistreamoperator>> (unsigned long long &i)
virtual RWvistreamoperator>> (wchar_t &wc)
virtual RWvistreamoperator>> (unsigned char &c)
virtual RWvistreamoperator>> (unsigned int &i)
virtual RWvistreamoperator>> (unsigned long &i)
virtual RWvistreamoperator>> (unsigned short &i)

Detailed Description

Class RWpistream specializes the abstract base class RWvistream to restore variables stored in a portable US-ASCII format by RWpostream.

You can think of RWpistream and RWpostream as an US-ASCII veneer over an associated std::streambuf which are responsible for formatting variables and escaping characters such that the results can be interchanged between any machines. As such, they are slower than their binary counterparts RWbistream and RWbostream which are more machine dependent. Because RWpistream and RWpostream retain no information about the state of their associated std::streambuf, their use can be freely exchanged with other users of the std::streambuf (such as std::istream or std::ifstream).

RWpistream can be interrogated as to the stream state using member functions good(), bad(), eof(), and so forth.

Synopsis

 #include <rw/pstream.h>
 RWpistream pstr(cin);   // Construct a RWpistream using cin's streambuf

Persistence

None

Examples

 #include <iostream>
 #include <fstream>

 #include <rw/pstream.h>

 int main()
 {
     // Open an input file
     std::ifstream fstr ("data.dat");

     // Construct RWpistream from it
     RWpistream pstr (fstr);

     int i;
     float f;
     double d;

     // Restore an int that was stored in binary
     if(!(pstr >> i))
     {
         std::cout << "Run postream.exe first!\n";
     }
     else
     {
         // Restore a float & double
         pstr >> f >> d;

         std::cout << "The integer: " << i << std::endl;
         std::cout << "The float: " << f << std::endl;
         std::cout << "The double: " << d << std::endl;
     }

     return 0;
 }

Constructor & Destructor Documentation

RWpistream::RWpistream ( std::istream &  str  ) 

Initializes an RWpistream using the std::streambuf associated with the std::istream str.

RWpistream::RWpistream ( std::streambuf *  s  ) 

Initializes an RWpistream from the std::streambuf s.

virtual RWpistream::~RWpistream (  )  [virtual]

Empty destructor.


Member Function Documentation

virtual int RWpistream::bad (  )  [inline, virtual]

Returns a nonzero integer if the bad bit has been set. Normally this indicates that a severe error has occurred from which recovery is probably impossible.

Implements RWvistream.

virtual void RWpistream::clear ( int  v = 0  )  [inline, virtual]

Sets the current error state to v. If v is zero, then this clears the error state.

Implements RWvistream.

virtual int RWpistream::eof (  )  [inline, virtual]

Returns a nonzero integer if an EOF is encountered.

Implements RWvistream.

virtual int RWpistream::fail (  )  [inline, virtual]

Returns a nonzero integer if the failed or bad bit has been set. Normally, this indicates that some storage or retrieval has failed, but that the stream is still in a usable state.

Implements RWvistream.

virtual RWvistream& RWpistream::get ( unsigned long *  v,
size_t  N 
) [virtual]

Gets a vector of N unsigned long and stores it in the array beginning at v. If the restore operation stops prematurely because there is no more data available on the stream, because an exception is thrown, or for some other reason, get() stores what has already been retrieved from the stream into v, and sets the failbit.

Implements RWvistream.

virtual RWvistream& RWpistream::get ( unsigned int *  v,
size_t  N 
) [virtual]

Gets a vector of N unsigned int and stores it in the array beginning at v. If the restore operation stops prematurely because there is no more data available on the stream, because an exception is thrown, or for some other reason, get() stores what has already been retrieved from the stream into v, and sets the failbit.

Implements RWvistream.

virtual RWvistream& RWpistream::get ( unsigned short *  v,
size_t  N 
) [virtual]

Gets a vector of N unsigned short and stores it in the array beginning at v. If the restore operation stops prematurely because there is no more data available on the stream, because an exception is thrown, or for some other reason, get() stores what has already been retrieved from the stream into v, and sets the failbit.

Implements RWvistream.

virtual RWvistream& RWpistream::get ( unsigned char *  v,
size_t  N 
) [virtual]

Gets a vector of N unsigned char and stores it in the array beginning at v. If the restore operation stops prematurely because there is no more data available on the stream, because an exception is thrown, or for some other reason, get() stores what has already been retrieved from the stream into v, and sets the failbit.

Implements RWvistream.

virtual RWvistream& RWpistream::get ( wchar_t *  v,
size_t  N 
) [virtual]

Gets a vector of wchar_t and stores it in the array beginning at v. If the restore operation stops prematurely because there is no more data available on the stream, because an exception is thrown, or for some other reason, get() stores what has already been retrieved from the stream into v, and sets the failbit.

Implements RWvistream.

virtual RWvistream& RWpistream::get ( short *  v,
size_t  N 
) [virtual]

Gets a vector of N short and stores it in the array beginning at v. If the restore operation stops prematurely because there is no more data available on the stream, because an exception is thrown, or for some other reason, get() stores what has already been retrieved from the stream into v, and sets the failbit.

Implements RWvistream.

virtual RWvistream& RWpistream::get ( long *  v,
size_t  N 
) [virtual]

Gets a vector of N long and stores it in the array beginning at v. If the restore operation stops prematurely because there is no more data available on the stream, because an exception is thrown, or for some other reason, get() stores what has already been retrieved from the stream into v, and sets the failbit.

Implements RWvistream.

virtual RWvistream& RWpistream::get ( int *  v,
size_t  N 
) [virtual]

Gets a vector of N int and stores it in the array beginning at v. If the restore operation stops prematurely because there is no more data available on the stream, because an exception is thrown, or for some other reason, get() stores what has already been retrieved from the stream into v, and sets the failbit.

Implements RWvistream.

virtual RWvistream& RWpistream::get ( float *  v,
size_t  N 
) [virtual]

Gets a vector of N float and stores it in the array beginning at v. If the restore operation stops prematurely because there is no more data available on the stream, because an exception is thrown, or for some other reason, get() stores what has already been retrieved from the stream into v, and sets the failbit.

Implements RWvistream.

virtual RWvistream& RWpistream::get ( double *  v,
size_t  N 
) [virtual]

Gets a vector of N double and stores it in the array beginning at v. If the restore operation stops prematurely because there is no more data available on the stream, because an exception is thrown, or for some other reason, get() stores what has already been retrieved from the stream into v, and sets the failbit.

Implements RWvistream.

virtual RWvistream& RWpistream::get ( unsigned long long *  v,
size_t  N 
) [virtual]

Get a vector of N unsigned long long and store them in the array beginning at v. If the restore operation stops prematurely because there is no more data available on the stream, because an exception is thrown, or for some other reason, get() stores what has already been retrieved from the stream into v, and sets the failbit.

Note:
This operator function is only available if your compiler supports the unsigned long long type.

Implements RWvistream.

virtual RWvistream& RWpistream::get ( long long *  v,
size_t  N 
) [virtual]

Gets a vector of N long long and stores it in the array beginning at v. If the restore operation stops prematurely because there is no more data available on the stream, because an exception is thrown, or for some other reason, get() stores what has already been retrieved from the stream into v, and sets the failbit.

Note:
This operator function is only available if your compiler supports the long long type.

Implements RWvistream.

virtual RWvistream& RWpistream::get ( long double *  v,
size_t  N 
) [virtual]

Gets a vector of N long double and stores it in the array beginning at v. If the restore operation stops prematurely because there is no more data available on the stream, because an exception is thrown, or for some other reason, get() stores what has already been retrieved from the stream into v, and sets the failbit.

Note:
This operator function is only available if your compiler supports the long double type.

Implements RWvistream.

virtual RWvistream& RWpistream::get ( char *  v,
size_t  N 
) [virtual]

Gets a vector of char and stores it in the array beginning at v. If the restore operation stops prematurely because there is no more data available on the stream, because an exception is thrown, or for some other reason, get() stores what has already been retrieved from the stream into v, and sets the failbit.

Note:
This method preserves US-ASCII numerical codes, not their corresponding character values. If you wish to restore a character string, use the function getString().

Implements RWvistream.

virtual RWvistream& RWpistream::get ( unsigned char &  c  )  [virtual]

Gets the next unsigned char from the input stream, returning its value in c.

Implements RWvistream.

virtual RWvistream& RWpistream::get ( wchar_t &  wc  )  [virtual]

Gets the next wchar_t from the input stream, returning its value in wc.

Implements RWvistream.

virtual RWvistream& RWpistream::get ( char &  c  )  [virtual]

Gets the next char from the input stream, returning its value in c. This member only preserves US-ASCII numerical codes, not the corresponding character symbol.

Implements RWvistream.

virtual int RWpistream::get (  )  [virtual]

Gets and returns the next byte from the input stream, returning its value. Returns EOF if end of file is encountered.

Implements RWvistream.

virtual RWvistream& RWpistream::getSizeT ( size_t &  sz  )  [virtual]

Gets the next size_t value from the input stream, returning its value in sz.

Implements RWvistream.

virtual RWvistream& RWpistream::getString ( char *  s,
size_t  N 
) [virtual]

Restores a character string from the input stream that was stored to the output stream with RWvostream::putstring and stores it in the array beginning at s. The function stops reading at the end of the string or after N - 1 characters, whichever comes first. If N - 1 characters have been read and the N th character is not the string terminator, then the failbit of the stream is set. In either case, the string is terminated with a null byte.

Implements RWvistream.

virtual int RWpistream::good (  )  [inline, virtual]

Returns a nonzero integer if no error bits have been set.

Implements RWvistream.

virtual RWvistream& RWpistream::operator>> ( unsigned short &  i  )  [virtual]

Gets the next unsigned short from the input stream and stores it in i.

Implements RWvistream.

virtual RWvistream& RWpistream::operator>> ( unsigned long &  i  )  [virtual]

Gets the next unsigned long from the input stream and stores it in i.

Implements RWvistream.

virtual RWvistream& RWpistream::operator>> ( unsigned int &  i  )  [virtual]

Gets the next unsigned int from the input stream and stores it in i.

Implements RWvistream.

virtual RWvistream& RWpistream::operator>> ( unsigned char &  c  )  [virtual]

Gets the next unsigned char from the input stream and stores it in c.

Implements RWvistream.

virtual RWvistream& RWpistream::operator>> ( wchar_t &  wc  )  [virtual]

Gets the next wchar_t from the input stream and stores it in wc.

Implements RWvistream.

virtual RWvistream& RWpistream::operator>> ( unsigned long long &  i  )  [virtual]

Gets the next unsigned long long from the input stream and stores it in i.

Note:
This operator function is only available if your compiler supports the unsigned long long type.

Implements RWvistream.

virtual RWvistream& RWpistream::operator>> ( long long &  i  )  [virtual]

Gets the next long long from the input stream and stores it in i.

Note:
This operator function is only available if your compiler supports the long long type.

Implements RWvistream.

virtual RWvistream& RWpistream::operator>> ( long double &  d  )  [virtual]

Gets the next long double from the input stream and stores it in d.

Note:
This operator function is only available if your compiler supports the long double type.

Implements RWvistream.

virtual RWvistream& RWpistream::operator>> ( short &  i  )  [virtual]

Gets the next short from the input stream and stores it in i.

Implements RWvistream.

virtual RWvistream& RWpistream::operator>> ( long &  i  )  [virtual]

Gets the next long from the input stream and stores it in i.

Implements RWvistream.

virtual RWvistream& RWpistream::operator>> ( int &  i  )  [virtual]

Gets the next int from the input stream and stores it in i.

Implements RWvistream.

virtual RWvistream& RWpistream::operator>> ( float &  f  )  [virtual]

Gets the next float from the input stream and stores it in f.

Implements RWvistream.

virtual RWvistream& RWpistream::operator>> ( double &  d  )  [virtual]

Gets the next double from the input stream and stores it in d.

Implements RWvistream.

virtual RWvistream& RWpistream::operator>> ( char &  c  )  [virtual]

Gets the next char from the input stream and stores it in c. This member attempts to preserve the symbolic characters values transmitted over the stream.

Implements RWvistream.

virtual int RWpistream::rdstate (  )  [inline, virtual]

Returns the current error state.

Implements RWvistream.

const std::istream& RWpistream::std (  )  const [inline]

Returns a reference to the underlying C++ Standard Library data type. The reference can be used to access the functionality exposed via std::istream interface.

std::istream& RWpistream::std (  ) 

Returns a reference to the underlying C++ Standard Library data type. The reference can be used to access the functionality exposed via std::istream interface.

 All Classes Functions Variables Typedefs Enumerations Enumerator Friends

© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.