rwlogo
SourcePro C++ 12.0

SourcePro® C++ API Reference Guide



   SourcePro C++
Documentation Home

RWpostream Class Reference
[Virtual Streams]

Specializes the abstract base class RWvostream to store variables in a portable (printable) US-ASCII format. More...

#include <rw/pstream.h>

Inheritance diagram for RWpostream:
RWvostream RWvios

List of all members.

Public Member Functions

 RWpostream (std::ostream &str)
 RWpostream (std::streambuf *s)
virtual ~RWpostream ()
virtual int eof ()
virtual int fail ()
virtual int bad ()
virtual int good ()
virtual int rdstate ()
virtual void clear (int v=0)
std::ostream & std ()
const std::ostream & std () const
int precision (int p)
int precision () const
virtual RWvostreamputString (const char *s, size_t N)
virtual RWvostreamoperator<< (const char *s)
virtual RWvostreamoperator<< (char c)
virtual RWvostreamoperator<< (wchar_t wc)
virtual RWvostreamoperator<< (unsigned char c)
virtual RWvostreamoperator<< (double d)
virtual RWvostreamoperator<< (float f)
virtual RWvostreamoperator<< (int i)
virtual RWvostreamoperator<< (unsigned int i)
virtual RWvostreamoperator<< (long i)
virtual RWvostreamoperator<< (unsigned long i)
virtual RWvostreamoperator<< (short i)
virtual RWvostreamoperator<< (unsigned short i)
virtual RWvostreamoperator<< (long double d)
virtual RWvostreamoperator<< (long long i)
virtual RWvostreamoperator<< (unsigned long long i)
virtual RWvostreamflush ()
virtual RWvostreamput (char c)
virtual RWvostreamput (const char *v, size_t N)
virtual RWvostreamput (wchar_t wc)
virtual RWvostreamput (const wchar_t *v, size_t N)
virtual RWvostreamput (unsigned char c)
virtual RWvostreamput (const unsigned char *v, size_t N)
virtual RWvostreamput (const short *v, size_t N)
virtual RWvostreamput (const unsigned short *v, size_t N)
virtual RWvostreamput (const int *v, size_t N)
virtual RWvostreamput (const unsigned int *v, size_t N)
virtual RWvostreamput (const long *v, size_t N)
virtual RWvostreamput (const unsigned long *v, size_t N)
virtual RWvostreamput (const float *v, size_t N)
virtual RWvostreamput (const double *v, size_t N)
virtual RWvostreamput (const long double *v, size_t N)
virtual RWvostreamput (const long long *v, size_t N)
virtual RWvostreamput (const unsigned long long *v, size_t N)
virtual RWvostreamputSizeT (size_t sz)

Related Functions

(Note that these are not member functions.)



 RW_DEFAULT_PRECISION

Detailed Description

Class RWpostream specializes the abstract base class RWvostream to store variables in a portable (printable) US-ASCII format. The results can be restored by using its counterpart RWpistream.

You can think of RWpistream and RWpostream as a US-ASCII veneer over an associated std::streambuf. They 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).

The goal of class RWpostream and RWpistream is to store variables using nothing but printable US-ASCII characters. Hence, nonprintable characters must be converted into an external representation where they can be recognized. Furthermore, other characters may be merely bit values (a bit image, for example), having nothing to do with characters as symbols. For example,

 RWpostream pstrm(cout);
 char c = '\n';

 pstr << c;     // Stores "newline"
 pstr.put(c);     // Stores the number 10.

The expression pstr << c treats c as a symbol for a newline, an unprintable character. The expression pstr.put(c) treats c as the literal number "10".

Note:
Variables should not be separated with white space. Such white space is interpreted literally and would be read back in as a character string.

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

Synopsis

 #include <rw/pstream.h>
 RWpostream pstr(cout);   // Construct an RWpostream using cout's streambuf

Persistence

None

Examples

 #include <iostream>
 #include <fstream>

 #include <rw/pstream.h>

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

     // Construct a RWpostream from it
     RWpostream pstr (fstr);

     int i = 5;
     float f = 22.1f;
     double d = -0.05;

     std::cout << "An integer, a float and a double sent out on a RWpostream!\n";

     // Store a float & double
     pstr << i << f << d;

     return 0;
 }

Constructor & Destructor Documentation

RWpostream::RWpostream ( std::ostream &  str  ) 

Initializes an RWpostream from the std::streambuf associated with the std::ostream str.

RWpostream::RWpostream ( std::streambuf *  s  ) 

Initializes an RWpostream from the std::streambuf s.

virtual RWpostream::~RWpostream (  )  [virtual]

Empty Destructor.


Member Function Documentation

virtual int RWpostream::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 RWvostream.

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

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

Implements RWvostream.

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

Returns a nonzero integer if an EOF is encountered.

Implements RWvostream.

virtual int RWpostream::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 RWvostream.

virtual RWvostream& RWpostream::flush (  )  [virtual]

Sends the contents of the stream buffer to output immediately.

Implements RWvostream.

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

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

Implements RWvostream.

virtual RWvostream& RWpostream::operator<< ( unsigned long long  i  )  [virtual]

Stores the unsigned long long i to the output stream using a portable format.

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

Implements RWvostream.

virtual RWvostream& RWpostream::operator<< ( long long  i  )  [virtual]

Stores the long long i to the output stream using a portable format.

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

Implements RWvostream.

virtual RWvostream& RWpostream::operator<< ( long double  d  )  [virtual]

Stores the long double d to the output stream using a portable format.

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

Implements RWvostream.

virtual RWvostream& RWpostream::operator<< ( unsigned short  i  )  [virtual]

Stores the unsigned short i to the output stream using a portable format.

Implements RWvostream.

virtual RWvostream& RWpostream::operator<< ( short  i  )  [virtual]

Stores the short i to the output stream using a portable format.

Implements RWvostream.

virtual RWvostream& RWpostream::operator<< ( unsigned long  i  )  [virtual]

Stores the unsigned long i to the output stream using a portable format.

Implements RWvostream.

virtual RWvostream& RWpostream::operator<< ( long  i  )  [virtual]

Stores the long i to the output stream using a portable format.

Implements RWvostream.

virtual RWvostream& RWpostream::operator<< ( unsigned int  i  )  [virtual]

Stores the unsigned int i to the output stream using a portable format.

Implements RWvostream.

virtual RWvostream& RWpostream::operator<< ( int  i  )  [virtual]

Stores the int i to the output stream using a portable format.

Implements RWvostream.

virtual RWvostream& RWpostream::operator<< ( float  f  )  [virtual]

Stores the float f to the output stream using a portable format.

Implements RWvostream.

virtual RWvostream& RWpostream::operator<< ( double  d  )  [virtual]

Stores the double d to the output stream using a portable format.

Implements RWvostream.

virtual RWvostream& RWpostream::operator<< ( unsigned char  c  )  [virtual]

Stores the unsigned char c to the output stream using a portable format.

Note:
c is treated as a character, not a number.

Implements RWvostream.

virtual RWvostream& RWpostream::operator<< ( wchar_t  wc  )  [virtual]

Stores the wchar_t wc to the output stream using a portable format.

Note:
wc is treated as a character, not a number.

Implements RWvostream.

virtual RWvostream& RWpostream::operator<< ( char  c  )  [virtual]

Stores the char c to the output stream using a portable format.

Note:
c is treated as a character, not a number.

Implements RWvostream.

virtual RWvostream& RWpostream::operator<< ( const char *  s  )  [virtual]

Stores the null terminated character string starting at s to the output stream.

Implements RWvostream.

int RWpostream::precision (  )  const [inline]

Returns the currently set precision used for writing float and double data. At construction, the precision is set to RW_DEFAULT_PRECISION.

int RWpostream::precision ( int  p  )  [inline]

Changes the precision used for writing float and double data. Returns the previously set precision. At construction, the precision is set to RW_DEFAULT_PRECISION.

virtual RWvostream& RWpostream::put ( const unsigned long long *  v,
size_t  N 
) [virtual]

Stores the vector of N unsigned long long starting at v to the output stream using a portable format.

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

Implements RWvostream.

virtual RWvostream& RWpostream::put ( const long long *  v,
size_t  N 
) [virtual]

Stores the vector of N long long starting at v to the output stream using a portable format.

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

Implements RWvostream.

virtual RWvostream& RWpostream::put ( const long double *  v,
size_t  N 
) [virtual]

Stores the vector of N long double starting at v to the output stream using a portable format.

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

Implements RWvostream.

virtual RWvostream& RWpostream::put ( const double *  v,
size_t  N 
) [virtual]

Stores the vector of N double starting at v to the output stream using a portable format.

Implements RWvostream.

virtual RWvostream& RWpostream::put ( const float *  v,
size_t  N 
) [virtual]

Stores the vector of N float starting at v to the output stream using a portable format.

Implements RWvostream.

virtual RWvostream& RWpostream::put ( const unsigned long *  v,
size_t  N 
) [virtual]

Stores the vector of N unsigned long starting at v to the output stream.

Implements RWvostream.

virtual RWvostream& RWpostream::put ( const long *  v,
size_t  N 
) [virtual]

Stores the vector of N long starting at v to the output stream using a portable format.

Implements RWvostream.

virtual RWvostream& RWpostream::put ( const unsigned int *  v,
size_t  N 
) [virtual]

Stores the vector of N unsigned int starting at v to the output stream using a portable format.

Implements RWvostream.

virtual RWvostream& RWpostream::put ( const int *  v,
size_t  N 
) [virtual]

Stores the vector of N int starting at v to the output stream using a portable format.

Implements RWvostream.

virtual RWvostream& RWpostream::put ( const unsigned short *  v,
size_t  N 
) [virtual]

Stores the vector of N unsigned short starting at v to the output stream using a portable format.

Implements RWvostream.

virtual RWvostream& RWpostream::put ( const short *  v,
size_t  N 
) [virtual]

Stores the vector of N short starting at v to the output stream using a portable format.

Implements RWvostream.

virtual RWvostream& RWpostream::put ( const unsigned char *  v,
size_t  N 
) [virtual]

Stores the vector of N unsigned char starting at v to the output stream using a portable format. The characters should be treated as literal numbers (i.e., not as a character string).

Implements RWvostream.

virtual RWvostream& RWpostream::put ( unsigned char  c  )  [virtual]

Stores the char c to the output stream, preserving its value using a portable format.

Implements RWvostream.

virtual RWvostream& RWpostream::put ( const wchar_t *  v,
size_t  N 
) [virtual]

Stores the vector of N wchar_t starting at v to the output stream. The characters should be treated as literal numbers (i.e., not as a character string).

Implements RWvostream.

virtual RWvostream& RWpostream::put ( wchar_t  wc  )  [virtual]

Stores the wchar_t wc to the output stream, preserving its value using a portable format.

Implements RWvostream.

virtual RWvostream& RWpostream::put ( const char *  v,
size_t  N 
) [virtual]

Stores the vector of N char starting at v to the output stream, preserving their values using a portable format. The characters should be treated as literal numbers (i.e., not as a character string).

Implements RWvostream.

virtual RWvostream& RWpostream::put ( char  c  )  [virtual]

Stores the char c to the output stream, preserving its value using a portable format. This member only preserves US-ASCII numerical codes, not the corresponding character symbol.

Implements RWvostream.

virtual RWvostream& RWpostream::putSizeT ( size_t  sz  )  [virtual]

Stores the size_t sz to the output stream using a portable format.

Implements RWvostream.

virtual RWvostream& RWpostream::putString ( const char *  s,
size_t  N 
) [virtual]

Stores the character string, including embedded nulls, starting at s to the output stream.

Implements RWvostream.

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

Returns the current error state.

Implements RWvostream.

const std::ostream& RWpostream::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::ostream interface.

std::ostream& RWpostream::std (  ) 

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


Friends And Related Function Documentation

RW_DEFAULT_PRECISION [related]

Default decimal digits of precision.

 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.