CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::Buffer Class Reference

Represents a secure buffer i.e. More...

#include <CeresEngine/Foundation/Buffer.hpp>

Inheritance diagram for CeresEngine::Buffer:
CeresEngine::CopyableBuffer

Public Types

using Iterator = Byte *
 The buffer iterator.
 
using ConstIterator = const Byte *
 The buffer const iterator.
 

Public Member Functions

 Buffer () noexcept
 Creates a new empty buffer.
 
 Buffer (std::nullptr_t) noexcept
 Creates a new null buffer.
 
 Buffer (size_t size) noexcept
 Creates a new buffer with "size" bytes preallocated.
 
 Buffer (Byte *buffer, size_t size, bool copy=false) noexcept
 Creates a new buffer by referecning another raw buffer.
 
 Buffer (const Byte *buffer, size_t size) noexcept
 Creates a new buffer by copying another raw buffer.
 
 Buffer (std::initializer_list< unsigned char > bytes) noexcept
 Creates a new buffer using a initializer list.
 
 Buffer (const Buffer &other) noexcept=delete
 Creates a new buffer by creating a copy of another.
 
Bufferoperator= (const Buffer &other) noexcept=delete
 Assigns this buffer a copy of another.
 
 Buffer (Buffer &&other) noexcept
 Creates a new buffer by moving another.
 
Bufferoperator= (Buffer &&other) noexcept
 Assigns this buffer another buffer's content by moving it.
 
 ~Buffer () noexcept
 Destroys and releases the buffer content.
 
Buffer copy () const noexcept
 Creates a explicit buffer copy.
 
Bytedata () noexcept
 Gets a pointer to the raws buffer data.
 
const Bytedata () const noexcept
 Gets a pointer to the raws buffer data.
 
Bytebuffer () noexcept
 Gets a pointer to the raws buffer data.
 
const Bytebuffer () const noexcept
 Gets a pointer to the raws buffer data.
 
size_t size () const noexcept
 Gets the number of bytes currently allocated in the buffer.
 
size_t capacity () const noexcept
 Gets the buffer capacity.
 
bool empty () const noexcept
 Checks if the buffer is currently empty (i.e.
 
bool owns () const noexcept
 Checks if the buffer is currently owned.
 
bool valid () const noexcept
 Checks if the buffer is valid.
 
Iterator begin () noexcept
 Gets a iterator that points to the begining of the buffer.
 
Iterator end () noexcept
 Gets a iterator that points to the end of the buffer.
 
ConstIterator begin () const noexcept
 Gets a iterator that points to the beginning of the buffer.
 
ConstIterator end () const noexcept
 Gets a iterator that points to the end of the buffer.
 
ConstIterator cbegin () const noexcept
 Gets a iterator that points to the beginning of the buffer.
 
ConstIterator cend () const noexcept
 Gets a iterator that points to the end of the buffer.
 
bool operator== (const Buffer &other) const noexcept
 Compares a buffer for equality If either buffer contain the same address and size, retuns true.
 
bool operator!= (const Buffer &other) const noexcept
 Compares a buffer for inequality If either buffer contain the same address and size, retuns false.
 
Byteoperator[] (size_t offset) noexcept
 Accesses a buffer element by its offset.
 
Byte operator[] (size_t offset) const noexcept
 Accesses a buffer element by its offset.
 
 operator bool () const noexcept
 Checks if the buffer is valid (i.e.
 
 operator const unsigned char * () const noexcept
 
 operator const char * () const noexcept
 
 operator unsigned char * () noexcept
 
 operator char * () noexcept
 
void resize (size_t newSize) noexcept
 Resizes the buffer to be able to store up-to "newSize" bytes.
 
void reserve (size_t newCapacity) noexcept
 Reservers at least newCapacity bytes in the buffer.
 
void own () noexcept
 Transforms a unowned buffer into a owned buffer.
 
void append (const Buffer &buffer) noexcept
 Appends a buffer to the end of this buffer.
 
void write (const char *buf, size_t length) noexcept
 Writes buf to the end of the buffer.
 
auto reference (size_t start=0, size_t length=std::numeric_limits< size_t >::max()) const noexcept -> Buffer
 Creates a buffer reference.
 
std::string hexdump () const noexcept
 Creates a hexdump representation.
 
std::string hexstring () const noexcept
 Creates a hexdump representation.
 

Private Attributes

BytemBuffer = nullptr
 The buffer pointer.
 
size_t mSize = 0
 The buffer size.
 
size_t mCapacity = 0
 The buffer capacity.
 
bool mOwns = true
 A flag that indicates whether the buffer is owned or not.
 

Friends

std::ostream & operator<< (std::ostream &os, const Buffer &buffer)
 

Detailed Description

Represents a secure buffer i.e.

a buffer that protects its memory by doing the following:

  • Protects the memory against swapping
  • Protects the memory against writing/reading (using mode)

Member Typedef Documentation

◆ ConstIterator

The buffer const iterator.

◆ Iterator

The buffer iterator.

Constructor & Destructor Documentation

◆ Buffer() [1/8]

CeresEngine::Buffer::Buffer ( )
noexcept

Creates a new empty buffer.

◆ Buffer() [2/8]

CeresEngine::Buffer::Buffer ( std::nullptr_t  )
noexcept

Creates a new null buffer.

◆ Buffer() [3/8]

CeresEngine::Buffer::Buffer ( size_t  size)
explicitnoexcept

Creates a new buffer with "size" bytes preallocated.

Parameters
sizeThe number of bytes to preallocate

◆ Buffer() [4/8]

CeresEngine::Buffer::Buffer ( Byte buffer,
size_t  size,
bool  copy = false 
)
explicitnoexcept

Creates a new buffer by referecning another raw buffer.

Important: the data is not copied!

Parameters
bufferThe buffer
sizeThe buffer size
copyA flag that configures copying

◆ Buffer() [5/8]

CeresEngine::Buffer::Buffer ( const Byte buffer,
size_t  size 
)
explicitnoexcept

Creates a new buffer by copying another raw buffer.

Parameters
bufferThe buffer
sizeThe buffer size

◆ Buffer() [6/8]

CeresEngine::Buffer::Buffer ( std::initializer_list< unsigned char bytes)
noexcept

Creates a new buffer using a initializer list.

Parameters
bytesThe buffer content

◆ Buffer() [7/8]

CeresEngine::Buffer::Buffer ( const Buffer other)
deletenoexcept

Creates a new buffer by creating a copy of another.

Parameters
otherThe instance to copy from

◆ Buffer() [8/8]

CeresEngine::Buffer::Buffer ( Buffer &&  other)
noexcept

Creates a new buffer by moving another.

Parameters
otherThe instance to move from

◆ ~Buffer()

CeresEngine::Buffer::~Buffer ( )
noexcept

Destroys and releases the buffer content.

Member Function Documentation

◆ append()

void CeresEngine::Buffer::append ( const Buffer buffer)
noexcept

Appends a buffer to the end of this buffer.

Parameters
bufferThe buffer to be appended

◆ begin() [1/2]

ConstIterator CeresEngine::Buffer::begin ( ) const
inlinenoexcept

Gets a iterator that points to the beginning of the buffer.

Returns
A iterator pointing to the buffers start

◆ begin() [2/2]

Iterator CeresEngine::Buffer::begin ( )
inlinenoexcept

Gets a iterator that points to the begining of the buffer.

Returns
A iterator pointing to the buffers start.

◆ buffer() [1/2]

const Byte * CeresEngine::Buffer::buffer ( ) const
inlinenoexcept

Gets a pointer to the raws buffer data.

Returns
A raw pointer to the buffer content

◆ buffer() [2/2]

Byte * CeresEngine::Buffer::buffer ( )
inlinenoexcept

Gets a pointer to the raws buffer data.

Returns
A raw pointer to the buffer content

◆ capacity()

size_t CeresEngine::Buffer::capacity ( ) const
inlinenoexcept

Gets the buffer capacity.

Returns
The buffer capacity

◆ cbegin()

ConstIterator CeresEngine::Buffer::cbegin ( ) const
inlinenoexcept

Gets a iterator that points to the beginning of the buffer.

Returns
A iterator pointing to the buffers start

◆ cend()

ConstIterator CeresEngine::Buffer::cend ( ) const
inlinenoexcept

Gets a iterator that points to the end of the buffer.

Returns
A iterator pointing to the buffers end

◆ copy()

Buffer CeresEngine::Buffer::copy ( ) const
noexcept

Creates a explicit buffer copy.

Returns
The new buffer whose contents are a copy of the contents of the source

◆ data() [1/2]

const Byte * CeresEngine::Buffer::data ( ) const
inlinenoexcept

Gets a pointer to the raws buffer data.

Returns
A raw pointer to the buffer content

◆ data() [2/2]

Byte * CeresEngine::Buffer::data ( )
inlinenoexcept

Gets a pointer to the raws buffer data.

Returns
A raw pointer to the buffer content

◆ empty()

bool CeresEngine::Buffer::empty ( ) const
inlinenoexcept

Checks if the buffer is currently empty (i.e.

size is zero)

Returns
True if size is zero

◆ end() [1/2]

ConstIterator CeresEngine::Buffer::end ( ) const
inlinenoexcept

Gets a iterator that points to the end of the buffer.

Returns
A iterator pointing to the buffers end

◆ end() [2/2]

Iterator CeresEngine::Buffer::end ( )
inlinenoexcept

Gets a iterator that points to the end of the buffer.

Returns
A iterator pointing to the buffers end

◆ hexdump()

std::string CeresEngine::Buffer::hexdump ( ) const
noexcept

Creates a hexdump representation.

◆ hexstring()

std::string CeresEngine::Buffer::hexstring ( ) const
noexcept

Creates a hexdump representation.

◆ operator bool()

CeresEngine::Buffer::operator bool ( ) const
inlineexplicitnoexcept

Checks if the buffer is valid (i.e.

not null)

Returns
True if the buffer is valid

◆ operator char *()

CeresEngine::Buffer::operator char * ( )
inlinenoexcept

◆ operator const char *()

CeresEngine::Buffer::operator const char * ( ) const
inlinenoexcept

◆ operator const unsigned char *()

CeresEngine::Buffer::operator const unsigned char * ( ) const
inlinenoexcept

◆ operator unsigned char *()

CeresEngine::Buffer::operator unsigned char * ( )
inlinenoexcept

◆ operator!=()

bool CeresEngine::Buffer::operator!= ( const Buffer other) const
inlinenoexcept

Compares a buffer for inequality If either buffer contain the same address and size, retuns false.

If the addresses differ the content is checked for inequality.

Parameters
otherthe instance to compare to
Returns
True if the buffer contents are not equal

◆ operator=() [1/2]

Buffer & CeresEngine::Buffer::operator= ( Buffer &&  other)
noexcept

Assigns this buffer another buffer's content by moving it.

Parameters
otherThe instance to move from
Returns
This

◆ operator=() [2/2]

Buffer & CeresEngine::Buffer::operator= ( const Buffer other)
deletenoexcept

Assigns this buffer a copy of another.

Parameters
otherThe instance to copy from
Returns
This

◆ operator==()

bool CeresEngine::Buffer::operator== ( const Buffer other) const
inlinenoexcept

Compares a buffer for equality If either buffer contain the same address and size, retuns true.

If the addresses differ the content is checked for equality.

Parameters
otherthe instance to compare to
Returns
True if the buffer contents are equal

◆ operator[]() [1/2]

Byte CeresEngine::Buffer::operator[] ( size_t  offset) const
inlinenoexcept

Accesses a buffer element by its offset.

Parameters
offsetThe memory offset the access the element at
Returns
A reference to the element at offset

◆ operator[]() [2/2]

Byte & CeresEngine::Buffer::operator[] ( size_t  offset)
inlinenoexcept

Accesses a buffer element by its offset.

Parameters
offsetThe memory offset the access the element at
Returns
A reference to the element at offset

◆ own()

void CeresEngine::Buffer::own ( )
noexcept

Transforms a unowned buffer into a owned buffer.

If the buffer is already owned, this call has no effect.

◆ owns()

bool CeresEngine::Buffer::owns ( ) const
inlinenoexcept

Checks if the buffer is currently owned.

Returns
True if the buffer is owned

◆ reference()

auto CeresEngine::Buffer::reference ( size_t  start = 0,
size_t  length = std::numeric_limits< size_t >::max() 
) const -> Buffer
noexcept

Creates a buffer reference.

Parameters
startThe starting byte
lengthThe length of the reference
Returns
A referenced buffer

◆ reserve()

void CeresEngine::Buffer::reserve ( size_t  newCapacity)
noexcept

Reservers at least newCapacity bytes in the buffer.

Parameters
newCapacityThe buffers new capacity

◆ resize()

void CeresEngine::Buffer::resize ( size_t  newSize)
noexcept

Resizes the buffer to be able to store up-to "newSize" bytes.

Parameters
newSizeThe new buffer limit

◆ size()

size_t CeresEngine::Buffer::size ( ) const
inlinenoexcept

Gets the number of bytes currently allocated in the buffer.

Returns
The buffer size

◆ valid()

bool CeresEngine::Buffer::valid ( ) const
inlinenoexcept

Checks if the buffer is valid.

Returns
True if the buffer is valid

◆ write()

void CeresEngine::Buffer::write ( const char buf,
size_t  length 
)
noexcept

Writes buf to the end of the buffer.

Parameters
bufThe buffer to be written
lengthThe buffer length

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const Buffer buffer 
)
friend

Member Data Documentation

◆ mBuffer

Byte* CeresEngine::Buffer::mBuffer = nullptr
private

The buffer pointer.

◆ mCapacity

size_t CeresEngine::Buffer::mCapacity = 0
private

The buffer capacity.

◆ mOwns

bool CeresEngine::Buffer::mOwns = true
private

A flag that indicates whether the buffer is owned or not.

◆ mSize

size_t CeresEngine::Buffer::mSize = 0
private

The buffer size.


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