Open Lighting Architecture  Latest Git
Public Member Functions | List of all members
ola::io::MemoryBlock Class Reference

Detailed Description

A MemoryBlock encapsulates a chunk of memory. It's used by the IOQueue and IOStack classes.

Public Member Functions

 MemoryBlock (uint8_t *data, unsigned int size)
 Construct a new MemoryBlock. More...
 
 ~MemoryBlock ()
 Destructor, this frees the memory for the block.
 
void SeekBack ()
 Move the insertation point to the end of the block. This is useful if you want to use the block in pre-pend mode.
 
unsigned int Capacity () const
 The size of the memory region for this block. More...
 
unsigned int Remaining () const
 The free space at the end of the block. More...
 
unsigned int Size () const
 The size of data in this block. More...
 
bool Empty () const
 Check if the block contains data. More...
 
uint8_t * Data () const
 Provides a pointer to the first byte of valid data in this block. More...
 
unsigned int Append (const uint8_t *data, unsigned int length)
 Append data to this block. More...
 
unsigned int Prepend (const uint8_t *data, unsigned int length)
 Prepend data to this block. More...
 
unsigned int Copy (uint8_t *data, unsigned int length) const
 
unsigned int PopFront (unsigned int length)
 Remove data from the front of the block. More...
 

Constructor & Destructor Documentation

◆ MemoryBlock()

ola::io::MemoryBlock::MemoryBlock ( uint8_t *  data,
unsigned int  size 
)
inline

Construct a new MemoryBlock.

Parameters
dataa pointer to the memory region to use, ownership is transferred.
sizethe size of the memory region to use

Member Function Documentation

◆ Append()

unsigned int ola::io::MemoryBlock::Append ( const uint8_t *  data,
unsigned int  length 
)
inline

Append data to this block.

Parameters
datathe data to append.
lengththe length of the data to append.
Returns
the number of bytes written, which will be less than length if the block is now full.

◆ Capacity()

unsigned int ola::io::MemoryBlock::Capacity ( ) const
inline

The size of the memory region for this block.

Returns
the size of the memory region for this block.

◆ Copy()

unsigned int ola::io::MemoryBlock::Copy ( uint8_t *  data,
unsigned int  length 
) const
inline

Copy data from the MemoryBlock into the location provided.

Parameters
[out]dataa pointer to the memory to copy the block data to.
lengththe maximum size of data to copy.
Returns
the amount of data copied

◆ Data()

uint8_t* ola::io::MemoryBlock::Data ( ) const
inline

Provides a pointer to the first byte of valid data in this block.

Returns
a pointer to the first byte of valid data in this block.

◆ Empty()

bool ola::io::MemoryBlock::Empty ( ) const
inline

Check if the block contains data.

Returns
true if the block contains no data, false otherwise.

◆ PopFront()

unsigned int ola::io::MemoryBlock::PopFront ( unsigned int  length)
inline

Remove data from the front of the block.

Parameters
lengththe amount of data to remove
Returns
the amount of data removed.

◆ Prepend()

unsigned int ola::io::MemoryBlock::Prepend ( const uint8_t *  data,
unsigned int  length 
)
inline

Prepend data to this block.

Parameters
datathe data to prepend.
lengththe length of the data to prepend.
Returns
the amount of data prepended, (from the end of data), which will be less than length if the block is now full.

◆ Remaining()

unsigned int ola::io::MemoryBlock::Remaining ( ) const
inline

The free space at the end of the block.

Returns
the free space at the end of the block.

◆ Size()

unsigned int ola::io::MemoryBlock::Size ( ) const
inline

The size of data in this block.

Returns
the size of the data in this block.

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