Ocean
|
This class implements an input bitstream. More...
Public Member Functions | |
InputBitstream (std::istream &stream) | |
Creates a new bitstream object. More... | |
template<typename T > | |
bool | read (T &value) |
Reads a value from the bitstream and moves the internal position inside the bitstream accordingly. More... | |
template<typename T > | |
T | readDefault (const T &defaultValue) |
Reads a value from the bitstream and moves the internal position inside the bitstream accordingly. More... | |
bool | read (void *data, const size_t size) |
Reads a defined memory block from the stream into a given buffer and moves the internal position inside the bitstream accordingly. More... | |
template<typename T > | |
bool | look (T &value) |
Reads a value from the bitstream but does not move the internal position inside the bitstream. More... | |
unsigned long long | position () const |
Returns the current position inside the bitstream, in bytes counting from the beginning of the stream. More... | |
unsigned long long | size () const |
Returns the current size of the bitstream, in bytes. More... | |
bool | setPosition (const unsigned long long position) |
Sets the current position inside the bitstream explicitly. More... | |
operator bool () const | |
Returns whether this bitstream object is valid and can be used. More... | |
Protected Attributes | |
std::istream & | inputStream |
The internal input stream object that this object encapsulates. More... | |
This class implements an input bitstream.
The implementation of the input bitstream is not thread-safe, thus ensure that the internal input stream object is not used within several threads concurrently.
The following data types are supported:
Data type: Number of bytes: Description: bool 1 char 1 wchar_t 4 Depending on the platform wchar_t has 1, 2 or 4 bytes thus this stream object stores 4 bytes per wchar_t object (see also std::wstring) unsigned char 1 short 2 unsigned short 2 int 4 unsigned int 4 float 4 double 8 long long 8 unsigned long long 8 std::string 4 + 1 * size Four bytes for the size of the string and 1 byte for each character std::wstring 4 + 4 * size Four bytes for the size of the string and 4 bytes for each character
The following data types are not supported as they have individual size on individual platforms and thus must not be used:
Data type: Description: size_t size_t has 4 bytes on 32 bit platforms and 8 bytes on 64 bit platforms
Ocean::IO::InputBitstream::InputBitstream | ( | std::istream & | stream | ) |
Creates a new bitstream object.
stream | The input stream object that is encapsulated by this object |
bool Ocean::IO::InputBitstream::look | ( | T & | value | ) |
Reads a value from the bitstream but does not move the internal position inside the bitstream.
Beware: It's recommended to provide the template argument explicitly to avoid type ambiguities.
value | The resulting value that is looked-up |
T | The data type that is read, ensure that only supported data types are applied |
|
inlineexplicit |
Returns whether this bitstream object is valid and can be used.
unsigned long long Ocean::IO::InputBitstream::position | ( | ) | const |
Returns the current position inside the bitstream, in bytes counting from the beginning of the stream.
bool Ocean::IO::InputBitstream::read | ( | T & | value | ) |
Reads a value from the bitstream and moves the internal position inside the bitstream accordingly.
If the read process fails, the new position of the bitstream may be arbitrary.
Beware: It's recommended to provide the template argument explicitly to avoid type ambiguities.
value | The resulting value that is read |
T | The data type that is read, ensure that only supported data types are applied |
bool Ocean::IO::InputBitstream::read | ( | void * | data, |
const size_t | size | ||
) |
Reads a defined memory block from the stream into a given buffer and moves the internal position inside the bitstream accordingly.
If the read process fails, the new position of the bitstream may be arbitrary.
data | The buffer that will receive the memory block, ensure that this buffer is large enough, may be nullptr if size is 0 |
size | The number of bytes that will be read into the memory block, with range [0, infinity) |
T Ocean::IO::InputBitstream::readDefault | ( | const T & | defaultValue | ) |
Reads a value from the bitstream and moves the internal position inside the bitstream accordingly.
If the read process fails, the new position of the bitstream may be arbitrary.
This function does not provide a success value but returns a given default value if the read process fails.
Beware: It's recommended to provide the template argument explicitly to avoid type ambiguities.
defaultValue | The default value that is returned if the read process fails |
T | The data type that is read, ensure that only supported data types are applied |
bool Ocean::IO::InputBitstream::setPosition | ( | const unsigned long long | position | ) |
Sets the current position inside the bitstream explicitly.
position | The new position inside the bitstream, in bytes counting from the beginning of the stream; with range [0, size()) |
unsigned long long Ocean::IO::InputBitstream::size | ( | ) | const |
Returns the current size of the bitstream, in bytes.
|
protected |
The internal input stream object that this object encapsulates.