MIRA
Public Types | Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
BinaryIstream< StreamUnderlay > Class Template Reference

Input stream adapter that can be assigned to any input stream and allows binary input using the >> stream operators. More...

#include <stream/BinaryStream.h>

Inheritance diagram for BinaryIstream< StreamUnderlay >:
Inheritance graph
[legend]

Public Types

typedef Base::char_type char_type
 
typedef StreamUnderlay::pos_type pos_type
 
enum  fmtflags { none = 0, net = 1L << 0 }
 

Public Member Functions

 BinaryIstream (streambuffer_pointer buffer)
 Constructor. More...
 
 BinaryIstream (Base &s)
 Constructor. More...
 
 BinaryIstream (Base &s, pos_type pos)
 Constructor specifying the stream and the current read position. More...
 
BinaryIstreamoperator>> (char *v)
 stream operator for the built-in C++ datatypes More...
 
BinaryIstreamoperator>> (std::string &v)
 
BinaryIstreamoperator>> (bool &v)
 
BinaryIstreamoperator>> (char &v)
 
BinaryIstreamoperator>> (uint8 &v)
 
BinaryIstreamoperator>> (uint16 &v)
 
BinaryIstreamoperator>> (uint32 &v)
 
BinaryIstreamoperator>> (uint64 &v)
 
BinaryIstreamoperator>> (int8 &v)
 
BinaryIstreamoperator>> (int16 &v)
 
BinaryIstreamoperator>> (int32 &v)
 
BinaryIstreamoperator>> (int64 &v)
 
BinaryIstreamoperator>> (float &v)
 
BinaryIstreamoperator>> (double &v)
 
template<typename T >
BinaryIstreamoperator>> (Buffer< T > &v)
 
BinaryIstreamoperator>> (BinaryIosBase &(*manipFn)(BinaryIosBase &))
 This stream operator is for internal use only. More...
 
template<typename T >
void read (T *data, std::size_t count)
 
fmtflags setf (fmtflags flags)
 Setting new format flags. More...
 
void unsetf (fmtflags mask)
 Clearing format flags. More...
 

Public Attributes

decltype(std::declval< Base >().rdbuf()) typedef streambuffer_pointer
 

Protected Member Functions

template<typename T >
BinaryIstreamfromBinary (T &value)
 Reads every type T from this binary stream. More...
 
BinaryIstreamstringFromBinary (char *value)
 Special method for reading C-strings (pointer value must point to memory address with enough memory for storing the read string. More...
 
BinaryIstreamstringFromBinary (std::string &value)
 Special method for reading STL-strings. More...
 

Protected Attributes

fmtflags mFmtFlags
 

Detailed Description

template<typename StreamUnderlay = BinaryBufferStreamBase>
class mira::BinaryIstream< StreamUnderlay >

Input stream adapter that can be assigned to any input stream and allows binary input using the >> stream operators.

This class can be used with different stream "underlays". The underlay provides the actual stream functionality and stores or transmits the data. Currently the binary stream comes in two flavors:

BinaryStlIstream can be used as adapter to any existing STL conform stream This class can be used as adapter to any existing STL conform stream (like file streams, string streams, zip-streams, etc). The resulting binary stream object can be used to read data from the underlying stream in binary format using the >>-operator. Additionally, there exist special manipulators to control the byte-order: 'net' will set the binary stream into network byte order (big endian) mode. Afterwards all read values are interpreted as Big Endian values. 'host' sets it into host byte order mode (the default).

Example:

// reads the file that was written in the binaryostream example:
ifstream ifs("myfile.bin");
BinaryStlIstream is(ifs); // create binary stream and attach to file stream
int a;
is >> a; // a=4
float f;
char c;
is >> f >> c; // f=1.234f, c='A'
string s;
is >> s; // s="This is a string"
uint32 x
is >> net >> x; // x = 0x12345F;
is >> host; // set stream back to host byte order

BinaryBufferIstream is similar to BinaryStlIstream but reads the data from a Buffer.

Example:

Buffer<uint8> buf;
... // fill the buffer with data
std::string s;
os >> s; // s="This is a string"
See also
BinaryOstream

Member Typedef Documentation

◆ char_type

typedef Base::char_type char_type

◆ pos_type

typedef StreamUnderlay::pos_type pos_type

Member Enumeration Documentation

◆ fmtflags

enum fmtflags
inherited
Enumerator
none 
net 

Constructor & Destructor Documentation

◆ BinaryIstream() [1/3]

BinaryIstream ( streambuffer_pointer  buffer)
inline

Constructor.

Constructs a BinaryIstream based on the specified stream buffer object. The stream buffer object must be specified as pointer. If you use BinaryIstream based on STL streams, then the stream buffer object must be of the type std::basic_streambuf<_CharT, _Traits> (see corresponding documentation of STL streams). If you use BinaryIstream based on BinaryBufferStreamBase, the stream buffer object must be of the type std::vector<uint8>.

◆ BinaryIstream() [2/3]

BinaryIstream ( Base &  s)
inline

Constructor.

The underlying input stream must be specified as parameter.

◆ BinaryIstream() [3/3]

BinaryIstream ( Base &  s,
pos_type  pos 
)
inline

Constructor specifying the stream and the current read position.

Member Function Documentation

◆ operator>>() [1/16]

BinaryIstream& operator>> ( char *  v)
inline

stream operator for the built-in C++ datatypes

◆ operator>>() [2/16]

BinaryIstream& operator>> ( std::string &  v)
inline

◆ operator>>() [3/16]

BinaryIstream& operator>> ( bool &  v)
inline

◆ operator>>() [4/16]

BinaryIstream& operator>> ( char &  v)
inline

◆ operator>>() [5/16]

BinaryIstream& operator>> ( uint8 &  v)
inline

◆ operator>>() [6/16]

BinaryIstream& operator>> ( uint16 &  v)
inline

◆ operator>>() [7/16]

BinaryIstream& operator>> ( uint32 &  v)
inline

◆ operator>>() [8/16]

BinaryIstream& operator>> ( uint64 &  v)
inline

◆ operator>>() [9/16]

BinaryIstream& operator>> ( int8 &  v)
inline

◆ operator>>() [10/16]

BinaryIstream& operator>> ( int16 &  v)
inline

◆ operator>>() [11/16]

BinaryIstream& operator>> ( int32 &  v)
inline

◆ operator>>() [12/16]

BinaryIstream& operator>> ( int64 &  v)
inline

◆ operator>>() [13/16]

BinaryIstream& operator>> ( float &  v)
inline

◆ operator>>() [14/16]

BinaryIstream& operator>> ( double &  v)
inline

◆ operator>>() [15/16]

BinaryIstream& operator>> ( Buffer< T > &  v)
inline

◆ operator>>() [16/16]

BinaryIstream& operator>> ( BinaryIosBase &(*)(BinaryIosBase &)  manipFn)
inline

This stream operator is for internal use only.

It provides an interface for stream manipulators like net and host. The manipulators are passed as function pointers. The passed manipulator functions are then called with the binary stream object as parameter (same mechanism as ios_base with manipulators hex, oct, etc).

◆ read()

void read ( T *  data,
std::size_t  count 
)
inline

◆ fromBinary()

BinaryIstream& fromBinary ( T &  value)
inlineprotected

Reads every type T from this binary stream.

Can be used for native C++ types or POD only !

◆ stringFromBinary() [1/2]

BinaryIstream& stringFromBinary ( char *  value)
inlineprotected

Special method for reading C-strings (pointer value must point to memory address with enough memory for storing the read string.

◆ stringFromBinary() [2/2]

BinaryIstream& stringFromBinary ( std::string &  value)
inlineprotected

Special method for reading STL-strings.

◆ setf()

fmtflags setf ( fmtflags  flags)
inlineinherited

Setting new format flags.

Parameters
flagsAdditional flags to set.
Returns
The previous format control flags.

This function sets additional flags in format control. Flags that were previously set remain set.

Note
This method has the same behavior as ios_base::setf() but works for our additional binary format flags only!

◆ unsetf()

void unsetf ( fmtflags  mask)
inlineinherited

Clearing format flags.

Parameters
maskThe flags to unset.

This function clears mask in the format flags.

Member Data Documentation

◆ streambuffer_pointer

decltype(std::declval<Base>().rdbuf()) typedef streambuffer_pointer

◆ mFmtFlags

fmtflags mFmtFlags
protectedinherited

The documentation for this class was generated from the following file: