SilentEye 0.4.1
|
EncodedData is a data manager used to read information bit per bit. More...
#include <encodeddata.h>
Public Member Functions | |
EncodedData (Data::DataFormat=Data::F_UNDEF, bool=false) | |
Create an empty object (without any data) | |
EncodedData (const QByteArray, Data::DataFormat=Data::BYTES, bool=false) | |
Create an object from existing bytes. | |
EncodedData (const quint32, bool=false) | |
Create an object from an integer. | |
EncodedData (const QString &, Data::DataFormat=Data::UTF8, bool=true) | |
Create an object from an String. | |
EncodedData (QFile &, bool=true) | |
Create an object from an existing file. | |
~EncodedData () | |
Destructor: object cleaning. | |
void | initialize (unsigned short int=2) |
Initialize data for read (or append) | |
bool | hasNext () |
Indicate if there is some next bit to read. | |
int | read () |
Read next available bits. | |
void | append (int) |
Append value into current data. | |
Data::DataFormat | format () |
Returns format of current data. | |
quint32 | size () const |
Returns current encoded data size. | |
QByteArray | bytes () |
Returns ByteArray representation of encoded data. | |
void | clear () |
Remove data and cancel all current operation. | |
bool | isCompressed () const |
Returns current compression mode. | |
void | setCompressed (const bool, const bool=false) |
Change compression mode. | |
QString | toString (Data::DataFormat=Data::F_UNDEF) |
Convert data into string if possible. | |
quint32 | toUInt32 () |
Convert data into unsigned int (32bits) | |
QPointer< Data > | toData () |
Retreive the current Data. | |
Static Public Member Functions | |
static unsigned short int | andOperator (unsigned short int) |
Compute value to use for "and" operator. | |
Private Member Functions | |
void | checkPartialData () |
Use buffer to compute data if needed. | |
Private Attributes | |
QPointer< Data > | _data |
Readable representation of data. | |
QByteArray | _buffer |
Compiled representation of data. | |
unsigned short int | _andOperator |
And operator used for bit read. | |
unsigned short int | _swap |
Number of bit read at once. | |
unsigned int | _arrayCount |
Index of last char read on _buffer. | |
char | _car |
Current readed char. | |
unsigned short int | _bitCount |
Number of bit reads from current char. | |
bool | _compressed |
Indicate that data must be compressed or not. | |
bool | _partialData |
Indicate if current buffer contains partial data (ex: use of append) |
EncodedData is a data manager used to read information bit per bit.
Example:
EncodedData data("some text");
data.initialize(2);
data.read(); // returns the 2 first bits of the string
Definition at line 34 of file encodeddata.h.
SilentEyeFramework::EncodedData::EncodedData | ( | Data::DataFormat | format = Data::F_UNDEF , |
bool | compress = false |
||
) |
Create an empty object (without any data)
This constructor is used with append function and constitute a partial data.
format | Specify data format |
compress | Specify whether the data should be compressed |
Definition at line 29 of file encodeddata.cpp.
References _andOperator, _arrayCount, _bitCount, _buffer, _car, _data, _partialData, _swap, and andOperator().
SilentEyeFramework::EncodedData::EncodedData | ( | const QByteArray | bytes, |
Data::DataFormat | format = Data::BYTES , |
||
bool | compress = false |
||
) |
Create an object from existing bytes.
bytes | Uncompressed data |
format | When format is set to F_UNDEF, constructor try to determine it from bytes |
compress | Specify whether the data should be compressed |
Definition at line 48 of file encodeddata.cpp.
References _andOperator, _arrayCount, _bitCount, _buffer, _car, _data, _partialData, _swap, andOperator(), and SilentEyeFramework::Data::F_UNDEF.
SilentEyeFramework::EncodedData::EncodedData | ( | const quint32 | value, |
bool | compress = false |
||
) |
Create an object from an integer.
value | Interger to encode |
compress | Specify whether the data should be compressed |
Definition at line 74 of file encodeddata.cpp.
References _andOperator, _arrayCount, _bitCount, _buffer, _car, _data, _partialData, _swap, andOperator(), and SilentEyeFramework::Data::UINT32.
SilentEyeFramework::EncodedData::EncodedData | ( | const QString & | str, |
Data::DataFormat | format = Data::UTF8 , |
||
bool | compress = true |
||
) |
Create an object from an String.
str | String to encode |
format | String format(UTF9, LATIN1, ASCII) |
compress | Specify whether the data should be compressed |
Definition at line 104 of file encodeddata.cpp.
References _andOperator, _arrayCount, _bitCount, _buffer, _car, _data, _partialData, _swap, andOperator(), SilentEyeFramework::Data::LATIN1, SilentEyeFramework::Data::toByteArray(), and SilentEyeFramework::Data::UTF8.
SilentEyeFramework::EncodedData::EncodedData | ( | QFile & | file, |
bool | compress = true |
||
) |
Create an object from an existing file.
file | Existing file which will be open, read and close. |
compress | Specify whether the data should be compressed |
Definition at line 134 of file encodeddata.cpp.
References _andOperator, _arrayCount, _bitCount, _buffer, _car, _data, _partialData, _swap, andOperator(), and SilentEyeFramework::Data::FILE.
SilentEyeFramework::EncodedData::~EncodedData | ( | ) |
unsigned short int SilentEyeFramework::EncodedData::andOperator | ( | unsigned short int | nbBits | ) | [static] |
Compute value to use for "and" operator.
nbBits | number of bits to use |
Definition at line 409 of file encodeddata.cpp.
Referenced by append(), EncodedData(), initialize(), and read().
void SilentEyeFramework::EncodedData::append | ( | int | val | ) |
Append value into current data.
val | integer representation of bits to add (little indian) |
Definition at line 317 of file encodeddata.cpp.
References _arrayCount, _bitCount, _buffer, _car, _partialData, _swap, and andOperator().
Referenced by SEFormatWAV::AudioWav::loadData(), and SEFormatBMP::ImageBMP::loadData().
QByteArray SilentEyeFramework::EncodedData::bytes | ( | ) |
Returns ByteArray representation of encoded data.
Definition at line 216 of file encodeddata.cpp.
References _buffer.
Referenced by toString(), and toUInt32().
void SilentEyeFramework::EncodedData::checkPartialData | ( | ) | [private] |
Use buffer to compute data if needed.
Definition at line 164 of file encodeddata.cpp.
References _buffer, _compressed, _data, _partialData, and SilentEyeFramework::Data::format().
Referenced by format(), toData(), toString(), and toUInt32().
void SilentEyeFramework::EncodedData::clear | ( | ) |
Remove data and cancel all current operation.
Definition at line 229 of file encodeddata.cpp.
References _arrayCount, _bitCount, _buffer, _car, _data, SilentEyeFramework::Data::F_UNDEF, and format().
Data::DataFormat SilentEyeFramework::EncodedData::format | ( | ) |
Returns format of current data.
Definition at line 179 of file encodeddata.cpp.
References _data, and checkPartialData().
Referenced by clear(), and toString().
bool SilentEyeFramework::EncodedData::hasNext | ( | ) |
Indicate if there is some next bit to read.
Definition at line 258 of file encodeddata.cpp.
References _arrayCount, and _buffer.
Referenced by read().
void SilentEyeFramework::EncodedData::initialize | ( | unsigned short int | nbBits = 2 | ) |
Initialize data for read (or append)
nbBits | number of bits to use at once |
Definition at line 246 of file encodeddata.cpp.
References _andOperator, _arrayCount, _bitCount, _buffer, _car, _swap, and andOperator().
Referenced by SEFormatWAV::AudioWav::loadData(), and SEFormatBMP::ImageBMP::loadData().
bool SilentEyeFramework::EncodedData::isCompressed | ( | ) | const |
Returns current compression mode.
Definition at line 187 of file encodeddata.cpp.
References _compressed.
int SilentEyeFramework::EncodedData::read | ( | ) |
Read next available bits.
Definition at line 271 of file encodeddata.cpp.
References _andOperator, _arrayCount, _bitCount, _buffer, _car, _swap, andOperator(), and hasNext().
void SilentEyeFramework::EncodedData::setCompressed | ( | const bool | compress, |
const bool | force = false |
||
) |
Change compression mode.
compress | new compression mode |
force | Indicate that we have to change current data |
Definition at line 197 of file encodeddata.cpp.
References _buffer, and _compressed.
quint32 SilentEyeFramework::EncodedData::size | ( | ) | const |
Returns current encoded data size.
Definition at line 223 of file encodeddata.cpp.
References _buffer.
Referenced by SilentEye::OptionDialog::dataSizeRemaining(), and toString().
QPointer< Data > SilentEyeFramework::EncodedData::toData | ( | ) |
Retreive the current Data.
Definition at line 398 of file encodeddata.cpp.
References _data, and checkPartialData().
QString SilentEyeFramework::EncodedData::toString | ( | Data::DataFormat | format = Data::F_UNDEF | ) |
Convert data into string if possible.
format | force format output |
Definition at line 370 of file encodeddata.cpp.
References _data, SilentEyeFramework::Data::ASCII, bytes(), checkPartialData(), SilentEyeFramework::Data::F_UNDEF, SilentEyeFramework::Data::FILE, format(), SilentEyeFramework::Data::LATIN1, size(), and SilentEyeFramework::Data::UTF8.
quint32 SilentEyeFramework::EncodedData::toUInt32 | ( | ) |
Convert data into unsigned int (32bits)
Definition at line 353 of file encodeddata.cpp.
References _data, bytes(), and checkPartialData().
Referenced by SEFormatWAV::AudioWav::loadData(), and SEFormatBMP::ImageBMP::loadData().
unsigned short int SilentEyeFramework::EncodedData::_andOperator [private] |
And operator used for bit read.
Definition at line 42 of file encodeddata.h.
Referenced by EncodedData(), initialize(), and read().
unsigned int SilentEyeFramework::EncodedData::_arrayCount [private] |
Index of last char read on _buffer.
Definition at line 46 of file encodeddata.h.
Referenced by append(), clear(), EncodedData(), hasNext(), initialize(), and read().
unsigned short int SilentEyeFramework::EncodedData::_bitCount [private] |
Number of bit reads from current char.
Definition at line 50 of file encodeddata.h.
Referenced by append(), clear(), EncodedData(), initialize(), and read().
QByteArray SilentEyeFramework::EncodedData::_buffer [private] |
Compiled representation of data.
Definition at line 40 of file encodeddata.h.
Referenced by append(), bytes(), checkPartialData(), clear(), EncodedData(), hasNext(), initialize(), read(), setCompressed(), and size().
char SilentEyeFramework::EncodedData::_car [private] |
Current readed char.
Definition at line 48 of file encodeddata.h.
Referenced by append(), clear(), EncodedData(), initialize(), and read().
Indicate that data must be compressed or not.
Definition at line 52 of file encodeddata.h.
Referenced by checkPartialData(), isCompressed(), and setCompressed().
QPointer<Data> SilentEyeFramework::EncodedData::_data [private] |
Readable representation of data.
Definition at line 38 of file encodeddata.h.
Referenced by checkPartialData(), clear(), EncodedData(), format(), toData(), toString(), toUInt32(), and ~EncodedData().
Indicate if current buffer contains partial data (ex: use of append)
Definition at line 54 of file encodeddata.h.
Referenced by append(), checkPartialData(), and EncodedData().
unsigned short int SilentEyeFramework::EncodedData::_swap [private] |
Number of bit read at once.
Definition at line 44 of file encodeddata.h.
Referenced by append(), EncodedData(), initialize(), and read().