sswf::Data Class Reference

Buffer object used to save the SWF movie. More...

#include <libsswf.h>

Inheritance diagram for sswf::Data:

sswf::MemoryManager List of all members.

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

Detailed Description

This object is a buffer used to save the SWF movie in a memory buffer.

It grows as required and has functions specific to SWF such as Align() and WriteBits().

See also:
sswf::Data::Align()

sswf::Data::WriteBits()


Constructor & Destructor Documentation

Data::Data ( void   ) 

This function initializes a Data buffer. By default, a Data buffer is empty.

Data::~Data (  ) 

This function does nothing since the memory used by the Data buffer is managed by the memory manager directly.


Member Function Documentation

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.

Parameters:
[in] size The new buffer size in bits
See also:
sswf::Data::Overwrite

sswf::Data::OverwriteByte

sswf::Data::OverwriteShort

sswf::Data::OverwriteLong

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  ) 

This function appends a Data buffer to this Data buffer.

The source Data buffer is not modified.

The destination is first aligned with a call to Align(). The buffer is grown as required, then the source is copied at the end of the destination.

Parameters:
[in] data The source Data buffer

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.

Returns:
The size of the buffer in bytes

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.

Returns:
The size of the buffer in bits

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.

See also:
sswf::Data::OverwriteByte

sswf::Data::OverwriteShort

sswf::Data::OverwriteLong

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.

See also:
sswf::Data::Overwrite

sswf::Data::OverwriteShort

sswf::Data::OverwriteLong

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

See also:
sswf::Data::Overwrite

sswf::Data::OverwriteByte

sswf::Data::OverwriteShort

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

See also:
sswf::Data::Overwrite

sswf::Data::OverwriteByte

sswf::Data::OverwriteLong

void Data::PutByte ( char  c  ) 

This is a convenient function used to save one byte in the Data buffer.

This function implicitly calls Align().

Parameters:
[in] c The byte to save
See also:
sswf::Data::PutShort()

sswf::Data::PutLong()

sswf::Data::PutDLong()

sswf::Data::PutShortFloat()

sswf::Data::PutLongFloat()

sswf::Data::PutDoubleFloat()

sswf::Data::PutString()

void Data::PutDLong ( int64_t  ll  ) 

This is a convenient function used to save one 64 bits long in the Data buffer.

The long least significant byte is saved first.

This function implicitly calls Align().

Parameters:
[in] ll The 64 bits long to save
See also:
sswf::Data::PutByte()

sswf::Data::PutShort()

sswf::Data::PutLong()

sswf::Data::PutShortFloat()

sswf::Data::PutLongFloat()

sswf::Data::PutDoubleFloat()

sswf::Data::PutString()

void Data::PutDoubleFloat ( double  d  ) 

This is a convenient function used to save a 64 bits floating point.

Parameters:
[in] d The floating point to save
See also:
sswf::Data::PutByte()

sswf::Data::PutShort()

sswf::Data::PutLong()

sswf::Data::PutDLong()

sswf::Data::PutShortFloat()

sswf::Data::PutLongFloat()

sswf::Data::PutString()

void Data::PutLong ( long  l  ) 

This is a convenient function used to save one long in the Data buffer.

The long least significant byte is saved first.

This function implicitly calls Align().

Parameters:
[in] l The long to save
See also:
sswf::Data::PutByte()

sswf::Data::PutShort()

sswf::Data::PutDLong()

sswf::Data::PutShortFloat()

sswf::Data::PutLongFloat()

sswf::Data::PutDoubleFloat()

sswf::Data::PutString()

void Data::PutLongFloat ( float  f  ) 

This is a convenient function used to save a 32 bits floating point.

Parameters:
[in] f The floating point to save
See also:
sswf::Data::PutByte()

sswf::Data::PutShort()

sswf::Data::PutLong()

sswf::Data::PutDLong()

sswf::Data::PutShortFloat()

sswf::Data::PutDoubleFloat()

sswf::Data::PutString()

void Data::PutShort ( short  s  ) 

This is a convenient function used to save one short in the Data buffer.

The short least significant byte is saved first.

This function implicitly calls Align().

Parameters:
[in] s The short to save
See also:
sswf::Data::PutByte()

sswf::Data::PutLong()

sswf::Data::PutDLong()

sswf::Data::PutShortFloat()

sswf::Data::PutLongFloat()

sswf::Data::PutDoubleFloat()

sswf::Data::PutString()

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:

Bug:
This function assumes that the input floating point is a valid number, not a NaN. Your SWF will work better that way anyway.
Parameters:
[in] f The floating point to convert and save
See also:
sswf::Data::PutByte()

sswf::Data::PutShort()

sswf::Data::PutLong()

sswf::Data::PutDLong()

sswf::Data::PutLongFloat()

sswf::Data::PutDoubleFloat()

sswf::Data::PutString()

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

Parameters:
[in] string The string to save
See also:
sswf::Data::PutByte()

sswf::Data::PutShort()

sswf::Data::PutLong()

sswf::Data::PutDLong()

sswf::Data::PutShortFloat()

sswf::Data::PutLongFloat()

sswf::Data::PutDoubleFloat()

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

Bug:
Warning: this function returns direct access to the internal buffer pointer and size. If any other function is used, it invalidates these pointers. So use them, and forget about them right away!
Parameters:
[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.

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

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

Parameters:
[in] value The value of which bits are saved
[in] bits The number of bits to be saved


Member Data Documentation

char* sswf::Data::f_data [private]

unsigned long sswf::Data::f_pos [private]

unsigned long sswf::Data::f_size [private]


The documentation for this class was generated from the following files:
Generated on Tue Jun 26 02:36:44 2007 for libsswf by  doxygen 1.4.7