Stream
The Stream class is a multi uses class that store a binary stream
Public member functions
Stream();
Stream(const Stream &stream);
Stream(const std::vector<unsigned char> &buffer);
Stream(const std::string &str);
Stream(const char str[], size_t size);
~Stream();
void operator += (const Stream &stream);
void operator += (const unsigned char &data);
void operator += (const std::string &str);
Stream operator = (const Stream &stream);
unsigned char operator[](size_t n);
const std::vector<unsigned char> &getBuffer() const;
size_t size() const;
void clear();
Stream subStream(size_t pos) const;
Stream subStream(size_t pos, size_t len) const;
std::string toString() const;
void setDataCharArray(const char *data, size_t size);
void setDataUInt(unsigned int data);
void setDataUShort(unsigned short data);
void setDataUChar(unsigned char data);
void setDataInt(int data);
void setDataShort(short data);
void setDataChar(char data);
unsigned int getDataUInt();
unsigned short getDataUShort();
unsigned char getDataUChar();
int getDataInt();
short getDataShort();
char getDataChar();
Private attributes
std::vector<unsigned char> _buffer;
Member functions documentation
Constructor
Stream();
Stream(const Stream &stream);
Stream(const std::vector<unsigned char> &buffer);
Stream(const std::string &str);
Stream(const char str[], size_t size);
Parameters
stream:
The Stream to copy
buffer:
The buffer to copy
str:
The string to put as buffer
size:
The size of the string if needed
operator+=
This operator concat another binary data to the current object
void operator += (const Stream &stream);
void operator += (const unsigned char &data);
void operator += (const std::string &str);
Parameters
stream:
The stream to concat
data:
The single byte to concat
str:
The string that contain binary data to concat
operator=
This operator change the buffer of the current object
Stream operator = (const Stream &stream);
Parameters
stream:
The source stream
operator[]
This operator return the value at the position n
of the buffer
unsigned char operator[](size_t n);
getBuffer
This method return the buffer that contain the binary data
const std::vector<unsigned char> &getBuffer() const;
size
This method return the size of the binary data in bytes
clear
This method clear the binary data
subStream
This method return newly constructed Stream object with its value initialized to a copy of a substream of this object.
Stream subStream(size_t pos) const;
Stream subStream(size_t pos, size_t len) const;
Parameters
pos:
Position of the first byte to put in the substream
len:
The number of byte to includes in the substream
toString
This method return the stream in form of a std::string.
std::string toString() const;
setData
This bunch of methods concat binary data to the Stream object.
void setDataCharArray(const char *data, size_t size);
void setDataUInt(unsigned int data);
void setDataUShort(unsigned short data);
void setDataUChar(unsigned char data);
void setDataInt(int data);
void setDataShort(short data);
void setDataChar(char data);
Parameters
data:
The varable you want to append in the Stream
size:
The number of byte you want to append if needed
getData
This bunch of methods extract a binary data from the Stream object and return it
unsigned int getDataUInt();
unsigned short getDataUShort();
unsigned char getDataUChar();
int getDataInt();
short getDataShort();
char getDataChar();