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

Output stream adapter that can be assigned to any output stream and allows binary output using the << stream operators. More...

#include <stream/BinaryStream.h>

Inheritance diagram for BinaryOstream< 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

 BinaryOstream (streambuffer_pointer buffer)
 Constructor. More...
 
 BinaryOstream (Base &s)
 Constructor. More...
 
 BinaryOstream (Base &s, pos_type pos)
 Constructor specifying the stream and the current write position. More...
 
BinaryOstreamoperator<< (const char *v)
 stream operator for the built-in C++ datatypes More...
 
BinaryOstreamoperator<< (const std::string &v)
 
BinaryOstreamoperator<< (const bool &v)
 
BinaryOstreamoperator<< (const char &v)
 
BinaryOstreamoperator<< (const uint8 &v)
 
BinaryOstreamoperator<< (const uint16 &v)
 
BinaryOstreamoperator<< (const uint32 &v)
 
BinaryOstreamoperator<< (const uint64 &v)
 
BinaryOstreamoperator<< (const int8 &v)
 
BinaryOstreamoperator<< (const int16 &v)
 
BinaryOstreamoperator<< (const int32 &v)
 
BinaryOstreamoperator<< (const int64 &v)
 
BinaryOstreamoperator<< (const float &v)
 
BinaryOstreamoperator<< (const double &v)
 
template<typename T >
BinaryOstreamoperator<< (const Buffer< T > &v)
 
BinaryOstreamoperator<< (BinaryIosBase &(*manipFn)(BinaryIosBase &))
 This stream operator is for internal use only. More...
 
template<typename T >
void write (const T *data, std::size_t count)
 
BinaryOstreamwriteString (const char *value)
 Method for explicitly writing a C-string to the stream. More...
 
BinaryOstreamwriteString (const std::string &value)
 Method for explicitly writing a STL string to the stream. More...
 
BinaryOstreamwriteString (const char *value, uint32 length)
 Method for explicitly writing the first 'length' characters of the C-string 'value'. More...
 
BinaryOstreamwriteString (const std::string &value, uint32 length)
 Method for explicitly writing the first 'length' characters of the STL-string 'value'. More...
 
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 >
BinaryOstreamtoBinary (const T &value)
 Writes every type T to this binary stream. More...
 

Protected Attributes

fmtflags mFmtFlags
 

Detailed Description

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

Output stream adapter that can be assigned to any output stream and allows binary output 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:

BinaryStlOstream 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 put data into 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, while 'host' sets it into host byte order mode (the default).

Example:

ofstream ofs("myfile.bin");
BinaryStlOstream os(ofs); // create binary stream and attach to file stream
int a = 4;
os << a;
char c = 'A';
os << 1.234f << c;
os << "This is a string";
uint32 x = 0x12345F;
os << net << x; // write x in network byte order (Big Endian)
os << host; // set stream back to host byte order

BinaryBufferOstream is similar to BinaryStlOstream but stores the data in a Buffer.

Example:

Buffer<uint8> buf;
os << "This is a string";
See also
BinaryIstream

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

◆ BinaryOstream() [1/3]

BinaryOstream ( streambuffer_pointer  buffer)
inline

Constructor.

Constructs an BinaryOstream based on the specified stream buffer object. The stream buffer object must be specified as pointer. If you use BinaryOstream 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 BinaryOstream based on BinaryBufferStreamBase, the stream buffer object must be of the type std::vector<uint8>.

◆ BinaryOstream() [2/3]

BinaryOstream ( Base &  s)
inline

Constructor.

The underlying output stream must be specified as parameter.

◆ BinaryOstream() [3/3]

BinaryOstream ( Base &  s,
pos_type  pos 
)
inline

Constructor specifying the stream and the current write position.

Member Function Documentation

◆ operator<<() [1/16]

BinaryOstream& operator<< ( const char *  v)
inline

stream operator for the built-in C++ datatypes

◆ operator<<() [2/16]

BinaryOstream& operator<< ( const std::string &  v)
inline

◆ operator<<() [3/16]

BinaryOstream& operator<< ( const bool &  v)
inline

◆ operator<<() [4/16]

BinaryOstream& operator<< ( const char &  v)
inline

◆ operator<<() [5/16]

BinaryOstream& operator<< ( const uint8 &  v)
inline

◆ operator<<() [6/16]

BinaryOstream& operator<< ( const uint16 &  v)
inline

◆ operator<<() [7/16]

BinaryOstream& operator<< ( const uint32 &  v)
inline

◆ operator<<() [8/16]

BinaryOstream& operator<< ( const uint64 &  v)
inline

◆ operator<<() [9/16]

BinaryOstream& operator<< ( const int8 &  v)
inline

◆ operator<<() [10/16]

BinaryOstream& operator<< ( const int16 &  v)
inline

◆ operator<<() [11/16]

BinaryOstream& operator<< ( const int32 &  v)
inline

◆ operator<<() [12/16]

BinaryOstream& operator<< ( const int64 &  v)
inline

◆ operator<<() [13/16]

BinaryOstream& operator<< ( const float &  v)
inline

◆ operator<<() [14/16]

BinaryOstream& operator<< ( const double &  v)
inline

◆ operator<<() [15/16]

BinaryOstream& operator<< ( const Buffer< T > &  v)
inline

◆ operator<<() [16/16]

BinaryOstream& 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).

◆ write()

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

◆ writeString() [1/4]

BinaryOstream& writeString ( const char *  value)
inline

Method for explicitly writing a C-string to the stream.

    stream.writeString(string)
has the same effect as
    stream << string;

◆ writeString() [2/4]

BinaryOstream& writeString ( const std::string &  value)
inline

Method for explicitly writing a STL string to the stream.

    stream.writeString(string)
has the same effect as
    stream << string;

◆ writeString() [3/4]

BinaryOstream& writeString ( const char *  value,
uint32  length 
)
inline

Method for explicitly writing the first 'length' characters of the C-string 'value'.

◆ writeString() [4/4]

BinaryOstream& writeString ( const std::string &  value,
uint32  length 
)
inline

Method for explicitly writing the first 'length' characters of the STL-string 'value'.

◆ toBinary()

BinaryOstream& toBinary ( const T &  value)
inlineprotected

Writes every type T to this binary stream.

Can be used for native C++ types or POD.

◆ 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: