SilentEye 0.4.1
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes

SilentEyeFramework::EncodedData Class Reference

EncodedData is a data manager used to read information bit per bit. More...

#include <encodeddata.h>

List of all members.

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< DatatoData ()
 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)

Detailed Description

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.


Constructor & Destructor Documentation

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.

Parameters:
formatSpecify data format
compressSpecify 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.

Parameters:
bytesUncompressed data
formatWhen format is set to F_UNDEF, constructor try to determine it from bytes
compressSpecify 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.

Parameters:
valueInterger to encode
compressSpecify 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.

Parameters:
strString to encode
formatString format(UTF9, LATIN1, ASCII)
compressSpecify 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.

Parameters:
fileExisting file which will be open, read and close.
compressSpecify 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 ( )

Destructor: object cleaning.

Definition at line 157 of file encodeddata.cpp.

References _data.


Member Function Documentation

unsigned short int SilentEyeFramework::EncodedData::andOperator ( unsigned short int  nbBits) [static]

Compute value to use for "and" operator.

Parameters:
nbBitsnumber of bits to use
Returns:
"and" operator value

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.

Parameters:
valinteger 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.

Returns:
current data array

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.

Returns:
data format (UTF8, FILE, ...)

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.

Returns:
true when more data are available

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)

Parameters:
nbBitsnumber 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.

Returns:
current compression mode

Definition at line 187 of file encodeddata.cpp.

References _compressed.

int SilentEyeFramework::EncodedData::read ( )

Read next available bits.

Returns:
integer representation of bits read (little indian). 0 if none available

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.

Parameters:
compressnew compression mode
forceIndicate 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.

Returns:
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.

Returns:
pointer on 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.

Parameters:
formatforce format output
Returns:
String representation

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)

Returns:
uint32 representation

Definition at line 353 of file encodeddata.cpp.

References _data, bytes(), and checkPartialData().

Referenced by SEFormatWAV::AudioWav::loadData(), and SEFormatBMP::ImageBMP::loadData().


Member Data Documentation

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().

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().

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().

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().

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().


The documentation for this class was generated from the following files: