25 #ifndef COMMON_BITSTREAMWRITER_H 26 #define COMMON_BITSTREAMWRITER_H 30 #include <boost/noncopyable.hpp> 46 virtual void putBit(
bool bit) = 0;
52 virtual void flush() = 0;
69 template<
int valueBits,
bool isLE,
bool isMSB2LSB>
105 _value >>= 64 - valueBits;
118 if ((valueBits != 8) && (valueBits != 16) && (valueBits != 32) && (valueBits != 64))
119 throw Exception(
"BitStreamWriter: Invalid memory layout %d, %d, %d", valueBits, isLE, isMSB2LSB);
126 if ((valueBits != 8) && (valueBits != 16) && (valueBits != 32) && (valueBits != 64))
127 throw Exception(
"BitStreamWriter: Invalid memory layout %d, %d, %d", valueBits, isLE, isMSB2LSB);
139 _value = (
_value >> 1) | (static_cast<uint64>(bit ? 1 : 0) << 63);
155 throw Exception(
"Too many bits requested to be written");
162 putBit(bits & 0x80000000);
177 const size_t padding = valueBits -
_inValue;
227 #endif // COMMON_BITSTREAMWRITER_H void writeValue()
Write the full data value.
A template implementing a bit stream writer for different data memory layouts.
void writeData(uint64 data)
Write a data value.
BitStreamWriterImpl< 16, true, false > BitStreamWriter16LELSB
16-bit little-endian data, LSB to MSB.
void putBit(bool bit)
Write a bit to the bit stream.
BitStreamWriterImpl< 64, false, false > BitStreamWriter64BELSB
64-bit big-endian data, LSB to MSB.
BitStreamWriterImpl< 16, true, true > BitStreamWriter16LEMSB
16-bit little-endian data, MSB to LSB.
BitStreamWriterImpl< 32, true, true > BitStreamWriter32LEMSB
32-bit little-endian data, MSB to LSB.
BitStreamWriterImpl< 64, true, false > BitStreamWriter64LELSB
64-bit little-endian data, LSB to MSB.
BitStreamWriterImpl< 16, false, true > BitStreamWriter16BEMSB
16-bit big-endian data, MSB to LSB.
uint8 _inValue
Position within the current value.
BitStreamWriterImpl< 64, false, true > BitStreamWriter64BEMSB
64-bit big-endian data, MSB to LSB.
BitStreamWriterImpl(WriteStream &stream)
Create a bit stream using this input data stream.
Basic exceptions to throw.
BitStreamWriterImpl< 8, false, true > BitStreamWriter8MSB
8-bit data, MSB to LSB.
Basic writing stream interfaces.
Low-level type definitions to handle fixed width types portably.
Generic interface for a writable data stream.
void flush()
Flush the stream, forcing all cached bits to the written.
A disposable plain pointer, allowing pointer-y access and normal deletion.
virtual void putBits(uint32 bits, size_t n)=0
Write a multi-bit value to the bit stream.
A smart pointer with a deletion flag.
virtual ~BitStreamWriter()
virtual void putBit(bool bit)=0
Write a bit to the bit stream.
BitStreamWriterImpl< 32, true, false > BitStreamWriter32LELSB
32-bit little-endian data, LSB to MSB.
BitStreamWriterImpl< 64, true, true > BitStreamWriter64LEMSB
64-bit little-endian data, MSB to LSB.
BitStreamWriterImpl< 8, false, false > BitStreamWriter8LSB
8-bit data, LSB to MSB.
BitStreamWriterImpl< 32, false, false > BitStreamWriter32BELSB
32-bit big-endian data, LSB to MSB.
virtual void flush()=0
Flush the stream, forcing all cached bits to the written.
uint64 _value
Current value.
DisposablePtr< WriteStream > _stream
The output stream.
BitStreamWriterImpl(WriteStream *stream, bool disposeAfterUse=false)
Create a bit stream using this input data stream and optionally delete it on destruction.
void putBits(uint32 bits, size_t n)
Write a multi-bit value to the bit stream.
BitStreamWriterImpl< 16, false, false > BitStreamWriter16BELSB
16-bit big-endian data, LSB to MSB.
BitStreamWriterImpl< 32, false, true > BitStreamWriter32BEMSB
32-bit big-endian data, MSB to LSB.