DataChunk Class Reference

#include <datachunk.h>

Inheritance diagram for DataChunk:

RefCount IRefCount List of all members.

Public Member Functions

 DataChunk ()
 Construct an empty data chunk.
 DataChunk (size_t BufferSize)
 Construct a data chunk with a pre-allocated buffer.
 DataChunk (size_t MemSize, const UInt8 *Buffer)
 Construct a data chunk with contents.
template<int SIZE>
 DataChunk (const Identifier< SIZE > *ID)
 Construct a data chunk from an identifier.
 DataChunk (const DataChunk &Chunk)
 Data chunk copy constructor.
 DataChunk (const DataChunkPtr &Chunk)
 Data chunk construct from smart pointer.
 ~DataChunk ()
void Resize (size_t NewSize, bool PreserveContents=true)
 Resize the data chunk, preserving contents if requested.
void ResizeBuffer (size_t NewSize, bool PreserveContents=true)
 Resize the data buffer, preserving contents if requested.
UInt8StealBuffer (bool MakeEmpty=false)
 Steal the buffer belonging to this data chunk.
void Set (const DataChunk &Buffer, size_t Start=0)
 Set some data into a data chunk (expanding it if required).
void Set (const DataChunkPtr &Buffer, size_t Start=0)
 Set some data into a data chunk (expanding it if required).
void Set (size_t MemSize, const UInt8 *Buffer, size_t Start=0)
 Set some data into a data chunk (expanding it if required).
void Append (const DataChunk &Buffer)
 Append some data to a data chunk.
void Append (const DataChunkPtr &Buffer)
 Append some data to a data chunk.
void Append (size_t MemSize, const UInt8 *Buffer)
 Append some data to a data chunk.
DataChunkoperator= (const DataChunk &Right)
bool operator== (const DataChunk &Right) const
bool operator!= (const DataChunk &Right) const
std::string GetString (void)
 Get a (hex) string representation of the data in the buffer.
void SetGranularity (size_t Gran)
 Allocation granularity access functions.
size_t GetGranularity (void)
void SetBuffer (UInt8 *Buffer, size_t BuffSize, size_t AllocatedSize=0)
 Set an external buffer as the data buffer.
bool TakeBuffer (DataChunk &OldOwner, bool MakeEmpty=false)
 Transfer ownership of a data buffer from another DataChunk.
bool TakeBuffer (DataChunkPtr &OldOwner, bool MakeEmpty=false)
 Transfer ownership of a data buffer from another DataChunk (via a smart pointer).

Public Attributes

size_t Size
 True if the buffer is not owned by us.
UInt8Data
 Size of the active data in the buffer.

Private Attributes

size_t DataSize
size_t AllocationGranularity
 Size of the data buffer.
bool ExternalBuffer
 Granulatiry of new memory allocations.

Constructor & Destructor Documentation

DataChunk (  )  [inline]

Construct an empty data chunk.

DataChunk ( size_t  BufferSize  )  [inline]

Construct a data chunk with a pre-allocated buffer.

DataChunk ( size_t  MemSize,
const UInt8 Buffer 
) [inline]

Construct a data chunk with contents.

DataChunk ( const Identifier< SIZE > *  ID  )  [inline]

Construct a data chunk from an identifier.

DataChunk ( const DataChunk Chunk  )  [inline]

Data chunk copy constructor.

DataChunk ( const DataChunkPtr Chunk  )  [inline]

Data chunk construct from smart pointer.

~DataChunk (  )  [inline]


Member Function Documentation

void Resize ( size_t  NewSize,
bool  PreserveContents = true 
)

Resize the data chunk, preserving contents if requested.

void ResizeBuffer ( size_t  NewSize,
bool  PreserveContents = true 
)

Resize the data buffer, preserving contents if requested.

The buffer is resized to at least NewSize, but Size remains unchanged

UInt8 * StealBuffer ( bool  MakeEmpty = false  ) 

Steal the buffer belonging to this data chunk.

The buffer is detached and ownership moves to the caller. It is the caller's responsibility to free the buffer with delete[] at a later point. If MakeEmpty is false the data chunk will not be empty after the call, but the ownership will still be transferred

Returns:
pointer to the buffer or NULL if no buffer or not owned by this object

void Set ( const DataChunk Buffer,
size_t  Start = 0 
) [inline]

Set some data into a data chunk (expanding it if required).

void Set ( const DataChunkPtr Buffer,
size_t  Start = 0 
) [inline]

Set some data into a data chunk (expanding it if required).

void Set ( size_t  MemSize,
const UInt8 Buffer,
size_t  Start = 0 
) [inline]

Set some data into a data chunk (expanding it if required).

void Append ( const DataChunk Buffer  )  [inline]

Append some data to a data chunk.

void Append ( const DataChunkPtr Buffer  )  [inline]

Append some data to a data chunk.

void Append ( size_t  MemSize,
const UInt8 Buffer 
) [inline]

Append some data to a data chunk.

DataChunk& operator= ( const DataChunk Right  )  [inline]

bool operator== ( const DataChunk Right  )  const [inline]

bool operator!= ( const DataChunk Right  )  const [inline]

std::string GetString ( void   ) 

Get a (hex) string representation of the data in the buffer.

void SetGranularity ( size_t  Gran  )  [inline]

Allocation granularity access functions.

size_t GetGranularity ( void   )  [inline]

void SetBuffer ( UInt8 Buffer,
size_t  BuffSize,
size_t  AllocatedSize = 0 
)

Set an external buffer as the data buffer.

Note:
If an external buffer has been set for a DataChunk it may not stay as the buffer in use. This is because there may not be enough room in the buffer to hold new data. Therefore it is important that the value of property Data is checked before assuming the external buffer is still in use.

bool TakeBuffer ( DataChunk OldOwner,
bool  MakeEmpty = false 
)

Transfer ownership of a data buffer from another DataChunk.

This is a very efficient way to set one DataChunk to the value of another. However it partially destroys the source DataChunk by stealing its buffer.

Returns:
true on success, false on failure

bool TakeBuffer ( DataChunkPtr OldOwner,
bool  MakeEmpty = false 
)

Transfer ownership of a data buffer from another DataChunk (via a smart pointer).

This is a very efficient way to set one DataChunk to the value of another. However it partially destroys the source DataChunk by stealing its buffer.

Returns:
true on success, false on failure


Member Data Documentation

size_t DataSize [private]

size_t AllocationGranularity [private]

Size of the data buffer.

bool ExternalBuffer [private]

Granulatiry of new memory allocations.

size_t Size

True if the buffer is not owned by us.

UInt8* Data

Size of the active data in the buffer.


The documentation for this class was generated from the following files:
Generated on Mon Apr 2 15:20:57 2007 for MXFLib by  doxygen 1.5.1-p1