MIRA
|
Stream is an abstraction that represents a device on which input and output operations are performed. A stream can basically be represented as a source or destination of characters.
The STL iostream library provides general streams that are associated to a physical source or destination of characters, like a disk file, the keyboard, or the console. The characters gotten or written from/to the abstraction called stream are physically input/output to the physical device. (see http://www.cplusplus.com/reference/iostream/)
Beside the STL streams, MIRA provides additional streams that are useful for different occasions.
The BufferStream can be used as a replacement to the STL std::stringstream. It provides better flexibility when accessing the underlying data buffer and has a better performance compared to std::stringstream.
The BufferStream can be used as any other STL stream via its implemented << and >> operators.
Example:
Usually, streams like all the STL streams operate with text or ASCII data. Numbers for example are always stored using their textual representation. In contrast to those text streams, MIRA Streams provide a BinaryIstream and a BinaryOstream class. Both are able to take binary data. Instead of the text streams, these binary streams store the data directly using the binary representation. A float number e.g. is stored using its 4 bytes also representing the number in memory.
The BinaryIstream / BinaryOstream classes come in two different flavors:
Example for using a Binary Stream wrapped around an STL stream:
Example for using a Binary Stream that operates directly on a Buffer for best performance:
Binary data is usually stored in the byte order of the host machine. However, if you want to share the data with other machines, you can change the byte order to network byte order (Big Endian). Switching between host and network byte order is done using the net and host manipulators:
Data in streams can also be compressed using the ogzstream and igzstream classes. They are part of the Gzstream Library (http://www.cs.unc.edu/Research/compgeom/gzstream/) written by Deepak Bandyopadhyay and Lutz Kettner.
Both classes can be used instead of std::ofstream and std::ifstream and will compress/decompress the data that is written to or read from the streams on the fly.
Example:
The igzstream input stream class also handles uncompressed files.