55 #ifndef _MIRA_BINARY_STREAM_H_ 56 #define _MIRA_BINARY_STREAM_H_ 153 mBuffer(buffer), mGetPos(0), mPutPos(0), mFailBit(false)
155 if(mBuffer->
size()==0)
170 void write(
const char* data, std::size_t size)
172 std::size_t npos = mPutPos+size;
175 if(npos>mBuffer->
size())
178 memcpy(mBuffer->
data()+mPutPos, data, size);
183 void read(
char* data, std::size_t size)
185 std::size_t npos = mGetPos+size;
189 if(npos>mBuffer->
size()) {
190 size = mBuffer->
size() - mGetPos;
191 npos = mBuffer->
size();
195 memcpy(data, mBuffer->
data()+mGetPos, size);
223 return mPutPos == mBuffer->
size();
292 template <
typename StreamUnderlay = BinaryBufferStreamBase>
296 typedef StreamUnderlay Base;
347 uint64 size = v.size();
349 write(v.data(), v.size());
369 template <
typename T>
370 void write(
const T* data, std::size_t count)
372 static_assert(
sizeof(
char_type)==1,
"binaryostream must have char_type of size 1");
373 Base::write(reinterpret_cast<const char*>(data), count*
sizeof(T));
411 write(value, length);
422 write(value.c_str(), length);
522 template <
typename StreamUnderlay = BinaryBufferStreamBase>
526 typedef StreamUnderlay Base;
578 if(size!=0 && this->eof())
579 MIRA_THROW(XIO,
"Failed to read buffer from binary stream, premature end of stream");
580 v.
resize((std::size_t)size);
601 template <
typename T>
602 void read(T* data, std::size_t count)
604 static_assert(
sizeof(
char_type)==1,
"binaryistream must have char_type of size 1");
605 Base::read(reinterpret_cast<char*>(data), count*
sizeof(T));
621 value = networkToHost<T>(v);
636 MIRA_THROW(XIO,
"Failed to read string from binary stream, premature end of stream");
651 MIRA_THROW(XIO,
"Failed to read string from binary stream, premature end of stream");
654 read((
char*)value.c_str(), l);
655 ((
char*)value.c_str())[l]=
'\0';
buffer_type * rdbuf()
Definition: BinaryStream.h:162
BinaryOstream< std::basic_ostream< char, std::char_traits< char > > > BinaryStlOstream
Typedef for binary output streams based on STL streams.
Definition: BinaryStream.h:450
BinaryIstream< BinaryBufferStreamBase > BinaryBufferIstream
Typedef for binary input streams based on a Buffer.
Definition: BinaryStream.h:673
BinaryIstream & operator>>(uint64 &v)
Definition: BinaryStream.h:567
BinaryBufferStreamBase & seekp(std::size_t pos)
Definition: BinaryStream.h:214
decltype(std::declval< Base >().rdbuf()) typedef streambuffer_pointer
Definition: BinaryStream.h:531
void write(const char *data, std::size_t size)
Definition: BinaryStream.h:170
BinaryOstream & writeString(const std::string &value)
Method for explicitly writing a STL string to the stream.
Definition: BinaryStream.h:398
Base::char_type char_type
Definition: BinaryStream.h:301
BinaryOstream & operator<<(const std::string &v)
Definition: BinaryStream.h:332
BinaryIstream< std::basic_istream< char, std::char_traits< char > > > BinaryStlIstream
Typedef for binary input streams based on STL streams.
Definition: BinaryStream.h:665
BinaryIstream(Base &s)
Constructor.
Definition: BinaryStream.h:552
BinaryOstream & writeString(const std::string &value, uint32 length)
Method for explicitly writing the first 'length' characters of the STL-string 'value'.
Definition: BinaryStream.h:419
BinaryIstream & operator>>(uint16 &v)
Definition: BinaryStream.h:565
Macros for generating logical operators for using enum values as flags.
T Type
Definition: Endian.h:236
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
fmtflags setf(fmtflags flags)
Setting new format flags.
Definition: BinaryStream.h:109
BinaryIosBase & net(BinaryIosBase &stream)
Manipulators:
Definition: BinaryStream.h:692
bool fail() const
Definition: BinaryStream.h:226
BinaryOstream & writeString(const char *value, uint32 length)
Method for explicitly writing the first 'length' characters of the C-string 'value'.
Definition: BinaryStream.h:408
BinaryOstream & operator<<(const uint32 &v)
Definition: BinaryStream.h:337
Utilities for byte order conversion between little and big endian.
BinaryOstream & operator<<(const uint8 &v)
Definition: BinaryStream.h:335
BinaryIosBase & host(BinaryIosBase &stream)
Manipulator that sets a binary input/output stream into host byte order mode and can be used to reset...
Definition: BinaryStream.h:712
BinaryOstream & operator<<(const uint64 &v)
Definition: BinaryStream.h:338
std::size_t tellp() const
Definition: BinaryStream.h:210
BinaryIstream & operator>>(int64 &v)
Definition: BinaryStream.h:571
void read(T *data, std::size_t count)
Definition: BinaryStream.h:602
uint8 value_type
Definition: Buffer.h:90
BinaryIstream & operator>>(char *v)
stream operator for the built-in C++ datatypes
Definition: BinaryStream.h:560
Although this class is not a template we must keep its methods inline for performance reasons! write(...
Definition: BinaryStream.h:142
BinaryOstream< BinaryBufferStreamBase > BinaryBufferOstream
Typedef for binary output streams based on a Buffer.
Definition: BinaryStream.h:458
StreamUnderlay::pos_type pos_type
Definition: BinaryStream.h:532
#define MIRA_ENUM_TO_FLAGS_INCLASS(EnumType)
Macro that can be used with enums that contain flags.
Definition: EnumToFlags.h:143
#define MIRA_THROW(ex, msg)
Macro for throwing an exception.
Definition: Exception.h:82
BinaryOstream & operator<<(BinaryIosBase &(*manipFn)(BinaryIosBase &))
This stream operator is for internal use only.
Definition: BinaryStream.h:361
BinaryOstream & operator<<(const int16 &v)
Definition: BinaryStream.h:340
BinaryOstream & operator<<(const int64 &v)
Definition: BinaryStream.h:342
buffer_type::value_type char_type
Definition: BinaryStream.h:148
BinaryOstream & toBinary(const T &value)
Writes every type T to this binary stream.
Definition: BinaryStream.h:433
Output stream adapter that can be assigned to any output stream and allows binary output using the <<...
Definition: BinaryStream.h:293
MIRA_BASE_EXPORT void write(const Value &value, std::ostream &ioStream, bool formatted=false, int precision=-1)
Writes a json::Value into a given stream using the JSON format.
Commonly used exception classes.
std::size_t tellg() const
Definition: BinaryStream.h:201
BinaryIstream & operator>>(int32 &v)
Definition: BinaryStream.h:570
size_type size() const
Returns the used size of the buffer set by resize()
Definition: Buffer.h:293
BinaryBufferStreamBase & seekg(std::size_t pos)
Definition: BinaryStream.h:205
decltype(std::declval< Base >().rdbuf()) typedef streambuffer_pointer
Definition: BinaryStream.h:302
BinaryOstream & operator<<(const int32 &v)
Definition: BinaryStream.h:341
pointer data()
Returns a pointer to the underlying data.
Definition: Buffer.h:514
Base::char_type char_type
Definition: BinaryStream.h:530
BinaryIstream & operator>>(std::string &v)
Definition: BinaryStream.h:561
MIRA_BASE_EXPORT void read(const std::string &s, Value &oValue)
Read a json::Value from a string that contains JSON format.
BinaryIstream & fromBinary(T &value)
Reads every type T from this binary stream.
Definition: BinaryStream.h:616
BinaryOstream & operator<<(const bool &v)
Definition: BinaryStream.h:333
BinaryIstream & stringFromBinary(char *value)
Special method for reading C-strings (pointer value must point to memory address with enough memory f...
Definition: BinaryStream.h:631
BinaryOstream & operator<<(const double &v)
Definition: BinaryStream.h:344
BinaryIstream & operator>>(BinaryIosBase &(*manipFn)(BinaryIosBase &))
This stream operator is for internal use only.
Definition: BinaryStream.h:593
BinaryOstream & operator<<(const char &v)
Definition: BinaryStream.h:334
BinaryIstream & operator>>(int16 &v)
Definition: BinaryStream.h:569
fmtflags
Definition: BinaryStream.h:88
BinaryIstream & operator>>(bool &v)
Definition: BinaryStream.h:562
BinaryOstream & operator<<(const int8 &v)
Definition: BinaryStream.h:339
void unsetf(fmtflags mask)
Clearing format flags.
Definition: BinaryStream.h:122
bool eof() const
Definition: BinaryStream.h:222
Input stream adapter that can be assigned to any input stream and allows binary input using the >> st...
Definition: BinaryStream.h:523
BinaryOstream & operator<<(const float &v)
Definition: BinaryStream.h:343
BinaryIstream & operator>>(uint32 &v)
Definition: BinaryStream.h:566
Definition: BinaryStream.h:90
BinaryOstream & writeString(const char *value)
Method for explicitly writing a C-string to the stream.
Definition: BinaryStream.h:384
void resize(size_type size)
Resizes the buffer.
Definition: Buffer.h:350
BinaryIstream & operator>>(double &v)
Definition: BinaryStream.h:573
Buffer< uint8 > buffer_type
Definition: BinaryStream.h:147
BinaryIstream & operator>>(Buffer< T > &v)
Definition: BinaryStream.h:575
void write(const T *data, std::size_t count)
Definition: BinaryStream.h:370
BinaryIstream & stringFromBinary(std::string &value)
Special method for reading STL-strings.
Definition: BinaryStream.h:645
BinaryOstream(Base &s)
Constructor.
Definition: BinaryStream.h:323
BinaryIstream & operator>>(char &v)
Definition: BinaryStream.h:563
Definition: BinaryStream.h:91
BinaryIstream & operator>>(int8 &v)
Definition: BinaryStream.h:568
BinaryOstream & operator<<(const char *v)
stream operator for the built-in C++ datatypes
Definition: BinaryStream.h:331
Generic buffer class that can be used as a replacement for std::vector.
BinaryOstream(Base &s, pos_type pos)
Constructor specifying the stream and the current write position.
Definition: BinaryStream.h:328
BinaryIstream & operator>>(float &v)
Definition: BinaryStream.h:572
std::size_t pos_type
Definition: BinaryStream.h:149
Helper class that is a base for binaryostream and binaryistream in the same way as ios_base is a base...
Definition: BinaryStream.h:84
BinaryBufferStreamBase(buffer_type *buffer)
Definition: BinaryStream.h:152
BinaryIstream(Base &s, pos_type pos)
Constructor specifying the stream and the current read position.
Definition: BinaryStream.h:557
void read(char *data, std::size_t size)
Definition: BinaryStream.h:183
fmtflags mFmtFlags
Definition: BinaryStream.h:131
BinaryOstream & operator<<(const uint16 &v)
Definition: BinaryStream.h:336
BinaryIstream & operator>>(uint8 &v)
Definition: BinaryStream.h:564