Module: Essential Tools Module Group: Virtual Stream Classes
... std::ios RWeistreamRWbistream ... ...RWvistreamRWvios
get() getString() operator>>() |
RWeistream() streamEndian() streamSizeofInt() |
streamSizeofLong() streamSizeofShort() streamSizeofSizeT() |
streamSizeofWchar() |
#include <rw/estream.h> RWeistream estr(cin); // Construct an RWeistream, // using cin's streambuf
Class RWeistream specializes the base class RWbistream to restore values previously stored by RWeostream. Please note, RWeostream must be opened before RWeistream, or the application will not function properly.
The endian streams, RWeistream and RWeostream, offer an efficient compromise between the portable streams (RWpistream, RWpostream) and the binary streams (RWbistream, RWbostream). By compensating for differences in big-endian vs. little-endian formats, as well as sizes of the various integral types, the endian streams offer portability without incurring the stream-size overhead of translating values into a series of printable characters. For example, data stored in little-endian format by an RWeostream object in a DOS program can be retrieved by an RWeistream object on any of several machines, regardless of its native endian format or the sizes of its integral types. Endian streams will work properly when shared among a group of platforms that:
Share a common size and representation (apart from endian format) for types float and double;
Use two's complement format for negative integral values.
As with the portable streams, care must be taken when storing or retrieving variables of type char. Endian stream methods treat chars as numbers except where the method description explicitly states that the char is being treated, instead, as a character. See the entry for RWpostream for an example of this distinction. Data stored in an integral type on one platform may be too large to fit into that type on a receiving platform. If so, the RWeistream's failbit will be set.
Endian streams can be interrogated as to the stream state using member functions good(), bad(), eof(), etc.
None.
See RWeostream for an example of how the file "data.dat" might be created.
#include <iostream> #include <fstream> #include <rw/estream.h> int main() { // Open an input file std::ifstream fstr ("data.dat"); // Construct RWeistream from it RWeistream estr (fstr); int i; float f; double d; // Restore an int that was stored in binary if(!(estr >> i)) { std::cout << "Run eostream.exe first!" << std::endl; } else { // Restore a float & double estr >> 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; }
Program output:
The integer: 5 The float: 22.1 The double: -0.05
RWeistream(streambuf* s);
Construct an RWeistream from the std::streambuf s. For DOS, this streambuf must have been created in binary mode. Throw exception RWStreamErr if not a valid endian stream.
RWeistream(istream& str);
Construct an RWeistream using the std::streambuf associated with the std::istream str. For DOS, the str must have been opened in binary mode. Throw exception RWStreamErr if not a valid endian stream.
virtual int get(); virtual RWvistream& get(char& c); virtual RWvistream& get(unsigned char& c); virtual RWvistream& get(char* v, size_t N); virtual RWvistream& get(unsigned char* v, size_t N);
Inherited from class RWbistream.
virtual RWvistream& get(wchar_t& wc);
Redefined from class RWbistream. Get the next wchar_t from the input stream and store it in wc, compensating for any differences in size or endian format between the stream and the current environment. Set the failbit if the value in the stream is too large to be stored in wc.
virtual RWvistream& get(wchar_t* v, size_t N);
Redefined from class RWbistream. Get a vector of wchar_ts and store it in the array beginning at v, compensating for any differences in size or endian format between the stream and the current environment. If the restore stops prematurely, store whatever possible in v, and set the failbit. Also set the failbit if any values in the stream are too large to be stored in an element of v.
virtual RWvistream& get(double* v, size_t N);
Redefined from class RWbistream. Get a vector of doubles and store them in the array beginning at v, compensating for any difference in endian format between the stream and the current environment. If the restore stops prematurely, store whatever possible in v, and set the failbit.
virtual RWvistream& get(long double* v, size_t N);
Redefined from class RWbistream. Get a vector of long doubles and store them in the array beginning at v, compensating for any difference in endian format between the stream and the current environment. If the restore stops prematurely, store whatever possible in v, and set the failbit. Note: This operator function is available only if your compiler supports the long double type.
virtual RWvistream& get(float* v, size_t N);
Redefined from class RWbistream. Get a vector of floats and store them in the array beginning at v, compensating for any difference in endian format between the stream and the current environment. If the restore stops prematurely, store whatever possible in v, and set the failbit.
virtual RWvistream& get(int* v, size_t N);
Redefined from class RWbistream. Get a vector of ints and store them in the array beginning at v, compensating for any differences in size or endian format between the stream and the current environment. If the restore stops prematurely, store whatever possible in v, and set the failbit. Also set the failbit if any values in the stream are too large to be stored in an element of v.
virtual RWvistream& get(long* v, size_t N);
Redefined from class RWbistream. Get a vector of longs and store them in the array beginning at v, compensating for any differences in size or endian format between the stream and the current environment. If the restore stops prematurely, store whatever possible in v, and set the failbit. Also set the failbit if any values in the stream are too large to be stored in an element of v.
virtual RWvistream& get(long long* v, size_t N);
Redefined from class RWbistream. Get a vector of long longs and store them in the array beginning at v, compensating for any difference in endian format between the stream and the current environment. If the restore stops prematurely, store whatever possible in v, and set the failbit. Note: This operator function is available only if your compiler supports the long long type.
virtual RWvistream& get(short* v, size_t N);
Redefined from class RWbistream. Get a vector of shorts and store them in the array beginning at v, compensating for any differences in size or endian format between the stream and the current environment. If the restore stops prematurely, store whatever possible in v, and set the failbit. Also set the failbit if any values in the stream are too large to be stored in an element of v.
virtual RWvistream& get(unsigned short* v, size_t N);
Redefined from class RWbistream. Get a vector of unsigned shorts and store them in the array beginning at v. If the restore stops prematurely, store whatever possible in v, and set the failbit. Also set the failbit if any values in the stream are too large to be stored in an element of v.
virtual RWvistream& get(unsigned int* v, size_t N);
Redefined from class RWbistream. Get a vector of unsigned ints and store them in the array beginning at v, compensating for any differences in size or endian format between the stream and the current environment. If the restore stops prematurely, store whatever possible in v, and set the failbit. Also set the failbit if any values in the stream are too large to be stored in an element of v.
virtual RWvistream& get(unsigned long* v, size_t N);
Redefined from class RWbistream. Get a vector of unsigned longs and store them in the array beginning at v, compensating for any differences in size or endian format between the stream and the current environment If the restore stops prematurely, store whatever possible in v, and set the failbit. Also set the failbit if any values in the stream are too large to be stored in an element of v.
virtual RWvistream& get(unsigned long long* v, size_t N);
Redefined from class RWbistream. Get a vector of unsigned long longs and store them in the array beginning at v, compensating for any difference in endian format between the stream and the current environment. If the restore stops prematurely, store whatever possible in v, and set the failbit. Note: This operator function is available only if your compiler supports the unsigned long long type.
virtual RWvistream& getString(char* s, size_t N);
Redefined from class RWbistream. Restores a character string from the input stream 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 the latter, then the failbit of the stream will be set, and the remaining characters of the string will be extracted from the stream and thrown away. In either case, the string will be terminated with a null byte. If the size of the string is too large to be represented by a variable of type size_t in the current environment, the badbit of the stream will be set, and no characters will be extracted. Note that the elements of the string are treated as characters, not numbers.
virtual RWvistream& operator>>(char& c);
Redefined from class RWbistream. Get the next char from the input stream and store it in c. Note that c is treated as a character, not a number.
virtual RWvistream& operator>>(wchar_t& wc);
Redefined from class RWbistream. Get the next wchar_t from the input stream and store it in wc, compensating for any differences in size or endian format between the stream and the current environment. Set the failbit if the value in the stream is too large to be stored in wc.
virtual RWvistream& operator>>(double& d);
Redefined from class RWbistream. Get the next double from the input stream and store it in d, compensating for any difference in endian format between the stream and the current environment.
virtual RWvistream& operator>>(float& f);
Redefined from class RWbistream. Get the next float from the input stream and store it in f, compensating for any difference in endian format between the stream and the current environment.
virtual RWvistream& operator>>(int& i);
Redefined from class RWbistream. Get the next int from the input stream and store it in i, compensating for any differences in size or endian format between the stream and the current environment. Set the failbit if the value in the stream is too large to be stored in i.
virtual RWvistream& operator>>(long& l);
Redefined from class RWbistream. Get the next long from the input stream and store it in l, compensating for any differences in size or endian format between the stream and the current environment. Set the failbit if the value in the stream is too large to be stored in l.
virtual RWvistream& operator>>(long long& l);
Redefined from class RWbistream. Get the next long long from the input stream and store it in l, compensating for any difference in endian format between the stream and the current environment. Note: This operator function is available only if your compiler supports the long long type.
virtual RWvistream& operator>>(short& s);
Redefined from class RWbistream. Get the next short from the input stream and store it in s, compensating for any differences in size or endian format between the stream and the current environment. Set the failbit if the value in the stream is too large to be stored in s.
virtual RWvistream& operator>>(unsigned char& c);
Redefined from class RWbistream. Get the next unsigned char from the input stream and store it in c. Note that c is treated as a character, not a number.
virtual RWvistream& operator>>(unsigned short& s);
Redefined from class RWbistream. Get the next unsigned short from the input stream and store it in s, compensating for any differences in size or endian format between the stream and the current environment. Set the failbit if the value in the stream is too large to be stored in s.
virtual RWvistream& operator>>(unsigned int& i);
Redefined from class RWbistream. Get the next unsigned int from the input stream and store it in i, compensating for any differences in size or endian format between the stream and the current environment. Set the failbit if the value in the stream is too large to be stored in i.
virtual RWvistream& operator>>(unsigned long& l);
Redefined from class RWbistream. Get the next unsigned long from the input stream and store it in l, compensating for any differences in size or endian format between the stream and the current environment. Set the failbit if the value in the stream is too large to be stored in l.
virtual RWvistream& operator>>(unsigned long long& l);
Redefined from class RWbistream. Get the next unsigned long long from the input stream and store it in l, compensating for any difference in endian format between the stream and the current environment. Note: This operator function is available only if your compiler supports the unsigned long long type.
RWeostream::Endian streamEndian();
Return the endian format (RWeostream::BigEndian or RWeostream::LittleEndian) of numeric values, as represented in the stream.
size_t streamSizeofInt();
Return the size of ints, as represented in the stream.
size_t streamSizeofLong();
Return the size of longs, as represented in the stream.
size_t streamSizeofShort();
Return the size of shorts, as represented in the stream.
size_t streamSizeofSizeT();
Return the size of size_ts, as represented in the stream.
size_t streamSizeofWchar();
Returns the size of wchar_ts, as represented in the stream.
© 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.