Base Framework
Public Member Functions | Static Public Attributes | Protected Attributes | List of all members
Buffer Class Reference

Buffer. More...

#include <base/mem/Buffer.h>

Inherits Object.

Public Member Functions

 Buffer (MemorySize size=0, MemorySize granularity=DEFAULT_GRANULARITY)
 
 Buffer (const Buffer &copy)
 
uint8 * getBytes () noexcept
 
const uint8 * getBytes () const noexcept
 
MemorySize getSize () const noexcept
 
void setSize (MemorySize size)
 
uint8 operator[] (MemorySize i) const
 
uint8 & operator[] (MemorySize i)
 
uint8 * begin () noexcept
 
uint8 * end () noexcept
 
const uint8 * begin () const noexcept
 
const uint8 * end () const noexcept
 
 operator bool () const noexcept
 
 ~Buffer () noexcept
 

Static Public Attributes

static const MemorySize DEFAULT_GRANULARITY = 1024
 

Protected Attributes

HeapBlockOwned< uint8 > heap
 
MemorySize size = 0
 
MemorySize granularity = DEFAULT_GRANULARITY
 

Detailed Description

Buffer.

This class implements a resizeable buffer and provides some low-level operations. The implementation is not MT-safe.

Version
1.0

Constructor & Destructor Documentation

◆ Buffer() [1/2]

Buffer::Buffer ( MemorySize  size = 0,
MemorySize  granularity = DEFAULT_GRANULARITY 
)
explicit

Initializes the buffer of given size and does not clear the memory. Raises MemoryException if unable to allocate the required memory.

Parameters
sizeSpecifies the initial size of the buffer. Default is 0.
granularitySpecifies the granularity of the size. Default is given by DEFAULT_GRANULARITY.

◆ Buffer() [2/2]

Buffer::Buffer ( const Buffer copy)

Copy constructor. Raises MemoryException if unable to allocate the required memory.

◆ ~Buffer()

Buffer::~Buffer ( )
noexcept

Destroys the buffer.

Member Function Documentation

◆ getBytes() [1/2]

const uint8* Buffer::getBytes ( ) const
inlinenoexcept

Returns the bytes of the buffer.

◆ getBytes() [2/2]

uint8* Buffer::getBytes ( )
inlinenoexcept

Returns the bytes of the buffer.

◆ getSize()

MemorySize Buffer::getSize ( ) const
inlinenoexcept

Returns the size of the buffer.

◆ operator[]() [1/2]

uint8& Buffer::operator[] ( MemorySize  i)
inline

Returns the byte at the given index.

◆ operator[]() [2/2]

uint8 Buffer::operator[] ( MemorySize  i) const
inline

Returns the byte at the given index.

◆ setSize()

void Buffer::setSize ( MemorySize  size)

Sets the size of the buffer. The original bytes of the buffer are not changed. If the buffer is expanded the bytes are not initialized. Raises MemoryException if unable to adjust the size of the buffer or the buffer is externally managed.

Parameters
sizeThe desired size.

Member Data Documentation

◆ DEFAULT_GRANULARITY

const MemorySize Buffer::DEFAULT_GRANULARITY = 1024
static

Specifies the granularity of the buffer size. Guaranteed to be greater than 16 bytes.

◆ granularity

MemorySize Buffer::granularity = DEFAULT_GRANULARITY
protected

The granularity of the size.

◆ heap

HeapBlockOwned<uint8> Buffer::heap
protected

The bytes of the buffer.

◆ size

MemorySize Buffer::size = 0
protected

The size of the buffer.