SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
RWpostream Class Reference

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

Public Member Functions

 RWpostream (std::ostream &str)
 
 RWpostream (std::streambuf *sb)
 
virtual ~RWpostream ()
 
virtual int bad ()
 
virtual void clear (int v=0)
 
virtual int eof ()
 
virtual int fail ()
 
virtual RWvostreamflush ()
 
virtual int good ()
 
int precision () const
 
int precision (int p)
 
virtual RWvostreamput (bool b)
 
virtual RWvostreamput (char c)
 
virtual RWvostreamput (const bool *v, size_t n)
 
virtual RWvostreamput (const char *v, size_t n)
 
virtual RWvostreamput (const double *v, size_t n)
 
virtual RWvostreamput (const float *v, size_t n)
 
virtual RWvostreamput (const int *v, size_t n)
 
virtual RWvostreamput (const long *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 short *v, size_t n)
 
virtual RWvostreamput (const signed char *v, size_t n)
 
virtual RWvostreamput (const unsigned char *v, size_t n)
 
virtual RWvostreamput (const unsigned int *v, size_t n)
 
virtual RWvostreamput (const unsigned long *v, size_t n)
 
virtual RWvostreamput (const unsigned long long *v, size_t n)
 
virtual RWvostreamput (const unsigned short *v, size_t n)
 
virtual RWvostreamput (const wchar_t *v, size_t n)
 
virtual RWvostreamput (double d)
 
virtual RWvostreamput (float f)
 
virtual RWvostreamput (int i)
 
virtual RWvostreamput (long double d)
 
virtual RWvostreamput (long i)
 
virtual RWvostreamput (long long i)
 
virtual RWvostreamput (short i)
 
virtual RWvostreamput (signed char c)
 
virtual RWvostreamput (unsigned char c)
 
virtual RWvostreamput (unsigned int i)
 
virtual RWvostreamput (unsigned long i)
 
virtual RWvostreamput (unsigned long long i)
 
virtual RWvostreamput (unsigned short i)
 
virtual RWvostreamput (wchar_t wc)
 
virtual RWvostreamputChar (char c)
 
virtual RWvostreamputChar (signed char c)
 
virtual RWvostreamputChar (unsigned char c)
 
virtual RWvostreamputChar (wchar_t wc)
 
virtual RWvostreamputChars (const char *s, size_t n)
 
virtual RWvostreamputSizeT (size_t sz)
 
virtual RWvostreamputString (const char *s, size_t n)
 
virtual int rdstate ()
 
std::ostream & std ()
 
const std::ostream & std () const
 
- Public Member Functions inherited from RWvostream
virtual ~RWvostream ()
 
unsigned version () const
 
void version (unsigned v)
 
- Public Member Functions inherited from RWvios
 operator void * ()
 

Related Symbols

(Note that these are not member symbols.)

#define 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.
Specializes the abstract base class RWvostream to store variables in a portable (printable) US-ASCII ...
Definition pstream.h:398

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>
// Construct an RWpostream using cout's streambuf
RWpostream pstr(cout);
Persistence
None
Example
#include <fstream>
#include <iostream>
#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() [1/2]

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

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

◆ RWpostream() [2/2]

RWpostream::RWpostream ( std::streambuf * sb)

Initializes an RWpostream from the std::streambuf sb.

◆ ~RWpostream()

virtual RWpostream::~RWpostream ( )
virtual

Empty Destructor.

Member Function Documentation

◆ bad()

virtual int RWpostream::bad ( )
inlinevirtual

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.

◆ clear()

virtual void RWpostream::clear ( int v = 0)
inlinevirtual

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

Implements RWvostream.

◆ eof()

virtual int RWpostream::eof ( )
inlinevirtual

Returns a nonzero integer if an EOF is encountered.

Implements RWvostream.

◆ fail()

virtual int RWpostream::fail ( )
inlinevirtual

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.

◆ flush()

virtual RWvostream & RWpostream::flush ( )
virtual

Sends the contents of the stream buffer to output immediately.

Implements RWvostream.

◆ good()

virtual int RWpostream::good ( )
inlinevirtual

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

Implements RWvostream.

◆ precision() [1/2]

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.

◆ precision() [2/2]

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.

◆ put() [1/32]

virtual RWvostream & RWpostream::put ( bool b)
virtual

Stores the bool b to the output stream.

Implements RWvostream.

◆ put() [2/32]

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.

◆ put() [3/32]

virtual RWvostream & RWpostream::put ( const bool * v,
size_t n )
virtual

Stores the vector of n bool starting at v to the output stream.

Implements RWvostream.

◆ put() [4/32]

virtual RWvostream & RWpostream::put ( const char * v,
size_t n )
virtual

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

Implements RWvostream.

◆ put() [5/32]

virtual RWvostream & RWpostream::put ( const double * v,
size_t n )
virtual

Stores the vector of n double starting at v to the output stream.

Implements RWvostream.

◆ put() [6/32]

virtual RWvostream & RWpostream::put ( const float * v,
size_t n )
virtual

Stores the vector of n float starting at v to the output stream.

Implements RWvostream.

◆ put() [7/32]

virtual RWvostream & RWpostream::put ( const int * v,
size_t n )
virtual

Stores the vector of n int starting at v to the output stream.

Implements RWvostream.

◆ put() [8/32]

virtual RWvostream & RWpostream::put ( const long * v,
size_t n )
virtual

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

Implements RWvostream.

◆ put() [9/32]

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.

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

Implements RWvostream.

◆ put() [10/32]

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.

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

Implements RWvostream.

◆ put() [11/32]

virtual RWvostream & RWpostream::put ( const short * v,
size_t n )
virtual

Stores the vector of n short starting at v to the output stream.

Implements RWvostream.

◆ put() [12/32]

virtual RWvostream & RWpostream::put ( const signed char * v,
size_t n )
virtual

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

Implements RWvostream.

◆ put() [13/32]

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. The characters should be treated as literal numbers (i.e., not as a character string).

Implements RWvostream.

◆ put() [14/32]

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.

Implements RWvostream.

◆ put() [15/32]

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.

◆ put() [16/32]

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.

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

Implements RWvostream.

◆ put() [17/32]

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.

Implements RWvostream.

◆ put() [18/32]

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.

◆ put() [19/32]

virtual RWvostream & RWpostream::put ( double d)
virtual

Stores the double d to the output stream.

Implements RWvostream.

◆ put() [20/32]

virtual RWvostream & RWpostream::put ( float f)
virtual

Stores the float f to the output stream.

Implements RWvostream.

◆ put() [21/32]

virtual RWvostream & RWpostream::put ( int i)
virtual

Stores the int i to the output stream.

Implements RWvostream.

◆ put() [22/32]

virtual RWvostream & RWpostream::put ( long double d)
virtual

Stores the long double d to the output stream.

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

Implements RWvostream.

◆ put() [23/32]

virtual RWvostream & RWpostream::put ( long i)
virtual

Stores the long i to the output stream.

Implements RWvostream.

◆ put() [24/32]

virtual RWvostream & RWpostream::put ( long long i)
virtual

Stores the long long i to the output stream.

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

Implements RWvostream.

◆ put() [25/32]

virtual RWvostream & RWpostream::put ( short i)
virtual

Stores the short i to the output stream.

Implements RWvostream.

◆ put() [26/32]

virtual RWvostream & RWpostream::put ( signed char c)
virtual

Stores the signed char c to the output stream, preserving its value.

Implements RWvostream.

◆ put() [27/32]

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

Stores the unsigned char c to the output stream, preserving its value.

Implements RWvostream.

◆ put() [28/32]

virtual RWvostream & RWpostream::put ( unsigned int i)
virtual

Stores the unsigned int i to the output stream.

Implements RWvostream.

◆ put() [29/32]

virtual RWvostream & RWpostream::put ( unsigned long i)
virtual

Stores the unsigned long i to the output stream.

Implements RWvostream.

◆ put() [30/32]

virtual RWvostream & RWpostream::put ( unsigned long long i)
virtual

Stores the unsigned long long i to the output stream.

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

Implements RWvostream.

◆ put() [31/32]

virtual RWvostream & RWpostream::put ( unsigned short i)
virtual

Stores the unsigned short i to the output stream.

Implements RWvostream.

◆ put() [32/32]

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

Stores the wchar_t wc to the output stream, preserving its value.

Implements RWvostream.

◆ putChar() [1/4]

virtual RWvostream & RWpostream::putChar ( char c)
virtual

Stores the char c to the output stream, preserving its meaning. c is treated as a character.

Implements RWvostream.

◆ putChar() [2/4]

virtual RWvostream & RWpostream::putChar ( signed char c)
virtual

Stores the signed char c to the output stream, preserving its meaning. c is treated as a character.

Implements RWvostream.

◆ putChar() [3/4]

virtual RWvostream & RWpostream::putChar ( unsigned char c)
virtual

Stores the unsigned char c to the output stream, preserving its meaning. c is treated as a character.

Implements RWvostream.

◆ putChar() [4/4]

virtual RWvostream & RWpostream::putChar ( wchar_t wc)
virtual

Stores the wchar_t wc to the output stream, preserving its value. wc is treated as a character.

Implements RWvostream.

◆ putChars()

virtual RWvostream & RWpostream::putChars ( const char * s,
size_t n )
virtual

Stores n char starting at s to the output stream.

Reimplemented from RWvostream.

◆ putSizeT()

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

Stores the size_t sz to the output stream.

Implements RWvostream.

◆ putString()

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.

◆ rdstate()

virtual int RWpostream::rdstate ( )
inlinevirtual

Returns the current error state.

Implements RWvostream.

◆ std() [1/2]

std::ostream & RWpostream::std ( )

Returns a reference to the underlying C++ Standard Library output stream.

◆ std() [2/2]

const std::ostream & RWpostream::std ( ) const
inline

Returns a reference to the underlying C++ Standard Library output stream.

Friends And Related Symbol Documentation

◆ RW_DEFAULT_PRECISION

#define RW_DEFAULT_PRECISION
related

Default decimal digits of precision.

Copyright © 2024 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.