RWpostream(3C++) RWpostream(3C++)
NameRWpostream - Rogue Wave library class
Synopsis
#include <rw/pstream.h>
// Construct an RWpostream, using cout's streambuf:
RWpostreampstr(cout) ;
Description
Class RWpostream specializes the abstract base class RWvostream to store
variables in a portable (printable) ASCII format. The results can be
restored by using its counterpart RWpistream. You can think of
RWpistream and RWpostream as an ASCII veneer over an associated 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 streambufs,
their use can be freely exchanged with other users of the streambuf (such
as istream or ifstream). The goal of class RWpostream and RWpistream is
to store variables using nothing but printable 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,
RWpostreampstrm(cout);
char c = '0;
pstr << c; // Stores "newline"
pstr.put_; // Stores the number 10.
The expression "pstr << c" treats c as a symbol for a newline, an
unprintable character. The expression "pstr.put_" treats c as the
literal number "10". Note that variables should not be separated with
white space. Such white space would be interpreted literally and would
have to be read back in as a character string. RWpostream can be
interrogated as to the stream state using member functions good(), bad(),
eof(),precision(), etc.
Page 1
RWpostream(3C++) RWpostream(3C++)
Persistence
None
Example
See RWpistream for an example of how to read back in the results of this
program. The symbol "o" is intended to represent a control-G, or bell.
.cpp
#include <rw/pstream.h>
main(){
// Construct an RWpostream to use standard output:
RWpostreampstr(cout);
int i = 5;
float f = 22.1;
double d = -0.05;
char string[]
= "A string withtabs,0ewlines and a o bell.";
pstr << i; // Store an int in binary
pstr << f << d; // Store a float & double
pstr << string; // Store a string
}
Program output:
5
22.1
-0.05
"A string withtabs,0ewlines and a bell."
Public Constructors
RWpostream(streambuf* s);
Initialize an RWpostream from the streambuf s.
RWpostream(ostream& str);
Page 2
RWpostream(3C++) RWpostream(3C++)
Initialize an RWpostream from the streambuf associated with the output
stream str.
Public Destructor
virtual ~RWvostream();
This virtual destructor allows specializing classes to deallocate any
resources that they may have allocated.
Public Operators
virtual RWvostream&
operator<<(const char* s);
Redefined from class RWvostream. Store the character string starting at
s to the output stream using a portable format. The character string is
expected to be null terminated.
virtual RWvostream&
operator<<(const wchar_t* ws);
Redefined from class RWvostream. Store the wide character string
starting at ws to the output stream using a portable format. The
character string is expected to be null terminated.
virtual RWvostream&
operator<<(char c);
Redefined from class RWvostream. Store the char c to the output stream
using a portable format. Note that c is treated as a character, not a
number. This member attempts to preserve the symbolic characters values
transmitted over the stream
virtual RWvostream&
operator<<(wchar_t wc);
Redefined from class RWvostream. Store the wide char wc to the output
stream using a portable format. Note that wc is treated as a character,
not a number.
virtual RWvostream&
operator<<(unsigned char c);
Page 3
RWpostream(3C++) RWpostream(3C++)
Redefined from class RWvostream. Store the unsigned char c to the output
stream using a portable format. Note that c is treated as a character,
not a number.
virtual RWvostream&
operator<<(double d);
Redefined from class RWvostream. Store the double d to the output stream
using a portable format.
virtual RWvostream&
operator<<(float f);
Redefined from class RWvostream. Store the float f to the output stream
using a portable format.
virtual RWvostream&
operator<<(int i);
Redefined from class RWvostream. Store the int i to the output stream
using a portable format.
virtual RWvostream&
operator<<(unsigned int i);
Redefined from class RWvostream. Store the unsigned int i to the output
stream using a portable format.
virtual RWvostream&
operator<<(long l);
Redefined from class RWvostream. Store the long l to the output stream
using a portable format.
virtual RWvostream&
operator<<(unsigned long l);
Redefined from class RWvostream. Store the unsigned long l to the output
stream using a portable format.
virtual RWvostream&
operator<<(short s);
Redefined from class RWvostream. Store the short s to the output stream
using a portable format.
Page 4
RWpostream(3C++) RWpostream(3C++)
virtual RWvostream&
operator<<(unsigned short s);
Redefined from class RWvostream. Store the unsigned short s to the
output stream using a portable format.
operator void*();
Inherited via RWvostream from RWvios.
Public Member Functions
int
precision() const;
Returns the currently set precision used for writing float and double
data. At construction, the precision is set to RW_DEFAULT_PRECISION
(defined in compiler.h.)
int
precision(int p);
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 (defined in compiler.h.)
virtual RWvostream&
flush();
Send the contents of the stream buffer to output immediately.
virtual RWvostream&
put(char c);
Redefined from class RWvostream. Store the char c to the output stream,
preserving its value using a portable format. This member only preserves
ASCII numerical codes, not the coresponding character symbol.
virtual RWvostream&
put(wchar_t wc);
Redefined from class RWvostream. Store the wide character wc to the
output stream, preserving its value using a portable format.
Page 5
RWpostream(3C++) RWpostream(3C++)
virtual RWvostream&
put(unsigned char c);
Redefined from class RWvostream. Store the unsigned char c to the output
stream, preserving its value using a portable format.
virtual RWvostream&
put(const char* p, size_t N);
Redefined from class RWvostream. Store the vector of chars starting at p
to the output stream, preserving their values using a portable format.
Note that the characters will be treated as literal numbers (i.e., not as
a character string).
virtual RWvostream&
put(const wchar_t* p, size_t N);
Redefined from class RWvostream. Store the vector of wide chars starting
at p to the output stream, preserving their values using a portable
format. Note that the characters will be treated as literal numbers
(i.e., not as a character string).
virtual RWvostream&
put(const unsigned char* p, size_t N);
Redefined from class RWvostream. Store the vector of unsigned chars
starting at p to the output stream using a portable format. The
characters should be treated as literal numbers (i.e., not as a character
string).
virtual RWvostream&
put(const short* p, size_t N);
Redefined from class RWvostream. Store the vector of shorts starting at
p to the output stream using a portable format.
virtual RWvostream&
put(const unsigned short* p, size_t N);
Redefined from class RWvostream. Store the vector of unsigned shorts
starting at p to the output stream using a portable format.
virtual RWvostream&
put(const int* p, size_t N);
Page 6
RWpostream(3C++) RWpostream(3C++)
Redefined from class RWvostream. Store the vector of ints starting at p
to the output stream using a portable format.
virtual RWvostream&
put(const unsigned int* p, size_t N);
Redefined from class RWvostream. Store the vector of unsigned ints
starting at p to the output stream using a portable format.
virtual RWvostream&
put(const long* p, size_t N);
Redefined from class RWvostream. Store the vector of longs starting at p
to the output stream using a portable format.
virtual RWvostream&
put(const unsigned long* p, size_t N);
Redefined from class RWvostream. Store the vector of unsigned longs
starting at p to the output stream using a portable format.
virtual RWvostream&
put(const float* p, size_t N);
Redefined from class RWvostream. Store the vector of floats starting at
p to the output stream using a portable format.
virtual RWvostream&
put(const double* p, size_t N);
Redefined from class RWvostream. Store the vector of doubles starting at
p to the output stream using a portable format.
virtual RWvostream&
putString(const char*s, size_t N);
Store the character string, including embedded nulls, starting at s to
the output string.
Page 7