#include <libsswf.h>
Inheritance diagram for sswf::Data:
Public Member Functions | |
void | Align (void) |
Align the buffer position to the next byte. | |
void | Append (const Data &append) |
Append another Data buffer. | |
unsigned long | ByteSize (void) const |
Returns the size of the buffer in bytes. | |
Data (void) | |
Initialize a Data buffer. | |
void | Empty (void) |
Reset the size. | |
unsigned long | GetSize (void) const |
Returns the current size of the buffer. | |
void | Overwrite (size_t offset, const void *ptr, size_t size) |
Overwrite data at the specified offset. | |
void | OverwriteByte (size_t offset, char c) |
Overwrite data at the specified offset. | |
void | OverwriteLong (size_t offset, long l) |
Overwrite data at the specified offset. | |
void | OverwriteShort (size_t offset, short s) |
Overwrite data at the specified offset. | |
void | PutByte (char c) |
Save one byte. | |
void | PutDLong (int64_t ll) |
Save one 64 bits long. | |
void | PutDoubleFloat (double f) |
Save one 64 bits floating point in IEEE format. | |
void | PutLong (long l) |
Save one 32 bits long. | |
void | PutLongFloat (float f) |
Save one 32 bits floating point in IEEE format. | |
void | PutShort (short s) |
Save one short. | |
void | PutShortFloat (float f) |
Save one 16 bits floating point in IEEE format. | |
void | PutString (const char *string) |
Save one string. | |
void | Read (void *&ptr, size_t &size) |
Read the data buffer information. | |
void | SetSize (unsigned long size) |
Set the size in bits. | |
void | Write (const void *ptr, size_t size) |
Write data at the end of the buffer. | |
void | WriteBits (long value, size_t bits) |
Write bits at the end of the buffer. | |
~Data () | |
Cleanup a Data buffer. | |
Private Member Functions | |
void | AdjustSize (size_t size) |
Make sure that the buffer is at least of that size. | |
Private Attributes | |
char * | f_data |
unsigned long | f_pos |
unsigned long | f_size |
It grows as required and has functions specific to SWF such as Align() and WriteBits().
Data::~Data | ( | ) |
This function does nothing since the memory used by the Data buffer is managed by the memory manager directly.
void Data::AdjustSize | ( | size_t | size | ) | [private] |
This function ensures that the output buffer is at least of the specified number of bits (notice: BITS, bot BYTES.)
This is used to create a buffer for a tag that can later be modified with the Overwrite functions.
[in] | size | The new buffer size in bits |
void Data::Align | ( | void | ) |
Whenever writing an SWF movie, it is most often compressed on bytes and quite often on bits. Whenever bits are used to save one structure (such as a rectangle), the following data which are aligned on a byte need to appear on a byte.
This function ensures that this is indeed the case.
This function can safely be called multiple times in a raw. The position will be adjusted only the first time and only if necessary.
void Data::Append | ( | const Data & | data | ) |
sswf::Data::ByteSize | ( | void | ) | const [inline] |
Returns the size of the buffer in bytes. The exact size of the buffer is in bits. The byte size is the bit size rounded up.
sswf::Data::Empty | ( | void | ) | [inline] |
This function marks the Data buffer as empty.
All the data previously saved in this buffer is lost.
sswf::Data::GetSize | ( | void | ) | const [inline] |
Returns the size of the buffer in bits. This is the exact position in the buffer.
In general, one needs to call ByteSize() instead.
void Data::Overwrite | ( | size_t | offset, | |
const void * | ptr, | |||
size_t | size | |||
) |
This function is used to overwrite data at offset on size bytes with the data pointed by ptr. This function will not enlarge the Data buffer and thus is must be used to overwrite only.
void Data::OverwriteByte | ( | size_t | offset, | |
char | c | |||
) |
This function is used to overwrite one byte at the specified offset. This function will not enlarge the Data buffer and thus is must be used to overwrite only.
void Data::OverwriteLong | ( | size_t | offset, | |
long | l | |||
) |
This function is used to overwrite one long at the specified offset (i.e. 4 bytes). This function will not enlarge the Data buffer and thus is must be used to overwrite only.
The long value is saved in little endian (least significant byte first.)
void Data::OverwriteShort | ( | size_t | offset, | |
short | s | |||
) |
This function is used to overwrite one short at the specified offset. This function will not enlarge the Data buffer and thus is must be used to overwrite only.
The short value is saved in little endian (least significant byte first.)
void Data::PutByte | ( | char | c | ) |
void Data::PutDLong | ( | int64_t | ll | ) |
void Data::PutDoubleFloat | ( | double | d | ) |
This is a convenient function used to save a 64 bits floating point.
[in] | d | The floating point to save |
void Data::PutLong | ( | long | l | ) |
void Data::PutLongFloat | ( | float | f | ) |
This is a convenient function used to save a 32 bits floating point.
[in] | f | The floating point to save |
void Data::PutShort | ( | short | s | ) |
void Data::PutShortFloat | ( | float | f | ) |
This is a convenient function used to save a floating point on 16 bits. This is not a fixed point value, it really is a floating point defined as:
[in] | f | The floating point to convert and save |
void Data::PutString | ( | const char * | string | ) |
This is a convenient function used to save a string in the Data buffer.
It is valid to call the function with a NULL pointer. It is considered to be an empty string and just one zero byte is written.
Otherwise, strlen(string) + 1 bytes are saved (i.e. the string characters and the nul terminator.)
This function implicitly calls Align().
[in] | string | The string to save |
void Data::Read | ( | void *& | ptr, | |
size_t & | size | |||
) |
This function can be used to get access to the internal buffer pointer and size.
In general, this function is used at the end to save the Data buffer in a file.
This function implicitly calls Align().
[out] | ptr | Receives the Data buffer pointer |
[out] | size | Receives the size in bytes of the buffer pointer |
void Data::SetSize | ( | unsigned long | size | ) |
This function can be used to shrink the buffer.
This is used after an AdjustSize() with a size which was too large.
In general, because the resulting size is determined after compression.
[in] | size | The new bit size of the buffer |
void Data::Write | ( | const void * | ptr, | |
size_t | size | |||
) |
This function writes size bytes from ptr at the end of the buffer. It automatically calls Align() to make sure that the alignment is correct.
[in] | ptr | The pointer to the data to append |
[in] | size | The number of bytes to append |
void Data::WriteBits | ( | long | value, | |
size_t | bits | |||
) |
This function writes the specified number of bits from the specified value.
The least significant bits of value are used. Thus, a 1 bit value is defined as 0 or 1. A 2 bits value is defined as 0, 1, 2 or 3. And so on...
It is valid to save up to 31 bits with this function. In debug mode, the function asserts if it looks like the parameters are invalid.
[in] | value | The value of which bits are saved |
[in] | bits | The number of bits to be saved |
char* sswf::Data::f_data [private] |
unsigned long sswf::Data::f_pos [private] |
unsigned long sswf::Data::f_size [private] |