Module: Essential Tools Module Group: Virtual Stream Classes
RWvostreamRWvios
#include <rw/vstream.h>
Class RWvostream is an abstract base class. It provides an interface for format-independent storage of fundamental types and arrays of fundamental types. Its counterpart, RWvistream, provides a complementary interface for the retrieval of variables of the fundamental types.
Because the interface of RWvistream and RWvostream is independent of formatting, the user of these classes need not be concerned with how variables will actually be stored or restored. That will be up to the derived class to decide. It might be done using an operating-system independent ASCII format (classes RWpistream and RWpostream), a binary format (classes RWbistream and RWbostream), or the user could define his or her own format (such as an interface to a network). Note that because it is an abstract base class, there is no way to actually enforce these goals -- the description here is merely the model of how a class derived from RWvistream and RWvostream should act.
Note that there is no need to separate variables with whitespace. It is the responsibility of the derived class to delineate variables with whitespace, packet breaks, or whatever might be appropriate for the final output sink. The model is one where variables are inserted into the output stream, either individually or as homogeneous vectors, to be restored in the same order using RWvistream.
Storage and retrieval of characters requires some explanation. Characters can be thought of as either representing some alphanumeric or control character, or as the literal number. Generally, the overloaded insertion (<<) and extraction (>>) operators seek to store and restore characters preserving their symbolic meaning. That is, storage of a newline should be restored as a newline, regardless of its representation on the target machine. By contrast, member functions get() and put() should treat the character as a literal number, whose value is to be preserved. See also class RWpostream.
None
// Based on vostream.cpp in the examples directory. // You can build an run this example, which stores // some data, and then run vistream.cpp to restore // the data. #include <iostream> #include <fstream> #include <rw/vstream.h> #include <rw/bstream.h> #include <rw/pstream.h> void storeStuff( RWvostream& str) { int i = 5; double d = 22.5; char s [] = "A string with \t tabs and a newline\n"; str << i; // Store an int str << d; // Store a double str << s; // Store a string if (str.fail()) { std::cerr << "Storage failed.\n"; } } int main () { std::ofstream vf ("vfile.dat"); RWpostream ps(vf); RWbostream bs(vf); // Uncomment the call to storeStuff that matches your stream type storeStuff((RWvostream &) ps); // storeStuff((RWvostream &) bs); return 0; }
Program output:
Output is written to the file vfile.dat.
virtual ~RWvostream();
Empty destructor.
virtual RWvostream& operator<<(const char* s) = 0;
Store the character string starting at s to the output stream. The character string is expected to be null terminated.
virtual RWvostream& operator<<(const wchar_t* ws) = 0;
Store the wide character string starting at ws to the output stream. The character string is expected to be null terminated.
virtual RWvostream& operator<<(char c) = 0;
Store the char c to the output stream. Note that c is treated as a character, not a number.
virtual RWvostream& operator<<(wchar_t wc) = 0;
Store the wchar_t wc to the output stream. Note that wc is treated as a character, not a number.
virtual RWvostream& operator<<(unsigned char c) = 0;
Store the unsigned char c to the output stream. Note that c is treated as a character, not a number.
virtual RWvostream& operator<<(double d) = 0;
Store the double d to the output stream.
virtual RWvostream& operator<<(long double d) = 0;
Store the double d to the output stream. Note: This operator function is only available if your compiler supports the long double d type.
virtual RWvostream& operator<<(float f) = 0;
Store the float f to the output stream.
virtual RWvostream& operator<<(int i) = 0;
Store the int i to the output stream.
virtual RWvostream& operator<<(unsigned int i) = 0;
Store the unsigned int i to the output stream.
virtual RWvostream& operator<<(long l) = 0;
Store the long l to the output stream.
virtual RWvostream& operator<<(long long l) = 0;
Store the long long l to the output stream. Note: This operator function is only available if your compiler supports the long long l type.
virtual RWvostream& operator<<(unsigned long l) = 0;
Store the unsigned long l to the output stream.
virtual RWvostream& operator<<(unsigned long long l) = 0;
Store the unsigned long long l to the output stream. Note: This operator function is only available if your compiler supports the unsigned long long l type.
virtual RWvostream& operator<<(short s) = 0;
Store the short s to the output stream.
virtual RWvostream& operator<<(unsigned short s) = 0;
Store the unsigned short s to the output stream.
operator void*();
Inherited from RWvios.
virtual RWvostream& flush();
Send the contents of the stream buffer to output immediately.
virtual RWvostream& put(char c) = 0;
Store the char c to the output stream, preserving its value.
virtual RWvostream& put(wchar_t wc) = 0;
Store the wchar_t wc to the output stream, preserving its value.
virtual RWvostream& put(unsigned char c) = 0;
Store the char c to the output stream, preserving its value.
virtual RWvostream& put(const char* p, size_t N) = 0;
Store the vector of N chars starting at p to the output stream. The chars should be treated as literal numbers (i.e., not as a character string).
virtual RWvostream& put(const wchar_t* p, size_t N) = 0;
Store the vector of N wchar_ts starting at p to the output stream. The chars should be treated as literal numbers (i.e., not as a character string).
virtual RWvostream& put(const unsigned char* p, size_t N) = 0;
Store the vector of N unsigned chars starting at p to the output stream. The chars should be treated as literal numbers (i.e., not as a character string).
virtual RWvostream& put(const short* p, size_t N) = 0;
Store the vector of N shorts starting at p to the output stream.
virtual RWvostream& put(const unsigned short* p, size_t N) = 0;
Store the vector of N unsigned shorts starting at p to the output stream.
virtual RWvostream& put(const int* p, size_t N) = 0;
Store the vector of N ints starting at p to the output stream.
virtual RWvostream& put(const unsigned int* p, size_t N) = 0;
Store the vector of N unsigned ints starting at p to the output stream.
virtual RWvostream& put(const long* p, size_t N) = 0;
Store the vector of N longs starting at p to the output stream.
virtual RWvostream& put(const long long* p, size_t N) = 0;
Store the vector of N long longs starting at p to the output stream. Note: This operator function is only available if your compiler supports the long long type.
virtual RWvostream& put(const unsigned long* p, size_t N) = 0;
Store the vector of N unsigned longs starting at p to the output stream.
virtual RWvostream& put(const unsigned long long* p, size_t N) = 0;
Store the vector of N unsigned long longs starting at p to the output stream. Note: This operator function is only available if your compiler supports the unsigned long long type.
virtual RWvostream& put(const float* p, size_t N) = 0;
Store the vector of N floats starting at p to the output stream.
virtual RWvostream& put(const double* p, size_t N) = 0;
Store the vector of N doubles starting at p to the output stream.
virtual RWvostream& put(const long double* p, size_t N) = 0;
Store the vector of N long doubles starting at p to the output stream. Note: This operator function is only available if your compiler supports the long double type.
virtual RWvostream& putString(const char*s, size_t N);
Store the character string, including embedded nulls, starting at s to the output string.
RWvostream& operator<<(RWvostream&, const RWCString& str);
Saves string str to a virtual stream or RWFile, respectively.
RWvostream& operator<<(RWvostream&, const RWInteger& x);
RWvostream& operator<<(RWvostream&, const RWTime& t);
RWvostream& operator<< (RWvostream& strm, const RWTPtrDeque<T,A>& coll); RWvostream& operator<<(RWvostream& strm, const RWTPtrDlist<T,A>& coll); RWvostream& operator<<(RWvostream& strm, const RWTPtrHashMap<K,T,H,EQ,A>& coll); RWvostream& operator<<(RWvostream& strm, const RWTPtrHashMultiMap<K,T,H,EQ,A>& coll); RWvostream& operator<<(RWvostream& strm, const RWTPtrHashMultiSet<T,H,EQ,A>& coll); RWvostream& operator<<(RWvostream& strm, const RWTPtrHashSet<T,H,EQ,A> & coll); RWvostream& operator<<(RWvostream& strm, const RWTPtrMap<K,T,C,A>& coll); RWvostream& operator<<(RWvostream& strm, const RWTPtrMultiMap<K,T,C,A>& coll); RWvostream& operator<<(RWvostream& strm, const RWTPtrMultiSet<T,C,A>& coll); RWvostream& operator<<(RWvostream& strm, const RWTPtrOrderedVector<T,A> RWTPtrOrderedVector<T,A> & coll); RWvostream& operator<<(RWFile& strm, const RWTPtrSet<T,C,A>& coll); RWvostream& operator<<(RWvostream& strm, const RWTPtrSlist<T,A>& coll); RWvostream& operator<<(RWvostream& strm, const RWTPtrSortedDlist<T,C,A>& coll); RWvostream& operator<<(RWvostream& strm, const RWTPtrSortedVector<T,C,A> & coll); RWvostream& operator<<(RWvostream& strm, const RWTValDeque<T,A>& coll); RWvostream& operator<<(RWvostream& strm, const RWTValDlist<T,A>& coll); RWvostream& operator<<(RWvostream& strm, const RWTValHashMap<T,H,EQ>& coll); RWvostream& operator<<(RWvostream& strm, const RWTValHashMultiMap<K,T,H,EQ,A>& coll); RWvostream& operator<<(RWvostream& strm, const RWTValHashMultiSet<T,H,EQ,A>& coll); RWvostream& operator<<(RWvostream& strm, const RWTValHashSet<T,H,EQ,A>& coll); RWvostream& operator<<(RWvostream& strm, const RWTValMap<K,T,C,A>& coll); RWvostream& operator<<(RWvostream& strm, const RWTValMultiMap<K,T,C,A>& coll); RWvostream& operator<<(RWvostream& strm, const RWTValMultiSet<T,C,A>& coll); RWvostream& operator<<(RWvostream& strm, const RWTValOrderedVector<T,A>& coll); RWvostream& operator<<(RWvostream& strm, const RWTValSet<T,C,A>& coll); RWvostream& operator<<(RWvostream& strm, const RWTValSlist<T,A>& coll); RWvostream& operator<<(RWvostream& strm, const RWTValSortedDlist<T,C,A>& coll); RWvostream& operator<<(RWvostream& strm, const RWTValSortedVector<T,C,A>& coll);
Saves the collection coll onto the output stream strm, or a reference to it if it has already been saved.
© 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.