An array of integral values used for serializing and deserializing data on bit-level. While writing and reading bits is performed with associated classes BitWriter and and BitReader, this class is responsible for storing the data and transferring it to an integral-arrays, which may for example be written and read to and from std::[i/o]stream
objects. With this, platform independence is guaranteed (in respect to little/big-endian storage and similar matters).
This class is abstract (pure virtual), and does not perform the allocation. With BitBuffer, BitBufferMA and BitBufferLocal, three descendants with different allocation strategies are provided. A customized version may be easily created by implementing pure virtual methods Capacity and EnsureCapacity.
Own Implementations have to set field data when reallocating the internal buffer.
Definition at line 42 of file bitbuffer.hpp.
#include <bitbuffer.hpp>
Inner Type Index: | |
class | Index |
Public Type Index: | |
using | TStorage = unsigned int |
Public Method Index: | |
BitBufferBase () noexcept | |
Default Constructor (the only one). | |
virtual | ~BitBufferBase () |
Virtual destructor (does nothing, needed for abstract virtual class). | |
virtual ALIB_API uinteger | Capacity () const =0 |
char * | CharStream (Index idx=Index(0, 0)) |
TStorage * | Data () const |
virtual ALIB_API bool | EnsureCapacity (uinteger bitsRequired, BitBufferBase::Index index)=0 |
ALIB_API void | FromLittleEndianEncoding (const Index &startIndex, const Index &endIndex) |
TStorage | GetWord (const Index &index) const |
uinteger | RemainingSize (const Index &idx) const |
void | SetWord (const Index &index, TStorage value) |
ALIB_API Index | Terminate (Index writerIndex) |
ALIB_API void | ToLittleEndianEncoding (const Index &startIndex, const Index &endIndex) |
ALIB_API Index | Unterminate (Index terminationIndex) |
Protected Field Index: | |
TStorage * | data |
using TStorage = unsigned int |
The storage type of bit buffers. This is chosen as being unsigned int
, which should be the "fasted" integral type for any compiler/platform combination.
Definition at line 47 of file bitbuffer.hpp.
|
protected |
A pointer to the storage. Implementations of this abstract type have to set this field when reallocating the internal buffer.
Definition at line 267 of file bitbuffer.hpp.
|
inlinenoexcept |
Default Constructor (the only one).
Definition at line 273 of file bitbuffer.hpp.
|
inlinevirtual |
Virtual destructor (does nothing, needed for abstract virtual class).
Definition at line 278 of file bitbuffer.hpp.
Virtual function to determine the (currently allocated) capacity.
Implemented in BitBuffer, BitBufferLocal< TCapacity >, and BitBufferMA.
Returns the memory address of the internal storage word denoted by idx
reinterpreted to C++ type char*
.
idx | The index of the word to point to. The bit position within this index is ignored. |
char
pointer to the internal storage word the given index refers to. Definition at line 352 of file bitbuffer.hpp.
|
inline |
Returns the start of the internal storage.
Definition at line 340 of file bitbuffer.hpp.
|
pure virtual |
Virtual function to reserve buffer space by optionally increasing the buffer to enable the writing of the given bits.
bitsRequired | The number of bits required. |
index | The index to which the capacity is currently used. |
true
if the space is available or could be made available, false
otherwise. Implemented in BitBuffer, BitBufferLocal< TCapacity >, and BitBufferMA.
The counter-method to ToLittleEndianEncoding.
startIndex | The first storage word to convert. (The bit position of the index is ignored). |
endIndex | The first bit behind the storage to be converted. Hence, if the bit position within this argument is not 0 , then the whole word that this index points to, will be converted. Otherwise it won't. |
Definition at line 158 of file bitbuffer.cpp.
Returns the storage word at the given position
index | The index to read the word from. Note that the bit number in this value is ignored. |
Definition at line 306 of file bitbuffer.hpp.
Returns the number of remaining bits in this buffer in relation to a given index.
idx | An actual writing/reading position. |
Definition at line 331 of file bitbuffer.hpp.
Stores the given value
at the given index
.
index | The index to read the word at. Note that the bit number in this value is ignored. |
value | The value to store |
Definition at line 319 of file bitbuffer.hpp.
BitBufferBase::Index Terminate | ( | Index | writerIndex | ) |
Writes a termination bit of value 1
and lets this buffer's index point to the next buffer word.
Termination can be undone using the result index of this method with Unterminate. This method should be invoked before serializing a buffer and method Unterminate may be used after deserialization to continue writing to the buffer without creating a gap.
writerIndex | The index to the last bit before termination. |
Definition at line 23 of file bitbuffer.cpp.
Converts the internal storage words into the platform-independent "Little Endian Encoding", which means it may change the byte order within the storage words of the buffer.
This method is recommended to be used before writing buffer contents to a file to make files system independent.
endIndex
.startIndex | The first storage word to convert. (The bit position of the index is ignored). |
endIndex | The first bit behind the storage to be converted. Hence, if the bit position within this argument is not 0 , then the whole word that this index points to, will be converted. Otherwise it won't. |
Definition at line 123 of file bitbuffer.cpp.
BitBufferBase::Index Unterminate | ( | Index | terminationIndex | ) |
Removes the termination bit found in the word before given terminationIndex
.
terminationIndex | The index returned by previous invocation of method Terminate. |
Definition at line 41 of file bitbuffer.cpp.