mn::buffer< TVALUE, TALLOCATOR > Class Template Reference

A buffer class that allocates a buffer of a given type and size. More...

#include <mn_buffer.hpp>

+ Inheritance diagram for mn::buffer< TVALUE, TALLOCATOR >:
+ Collaboration diagram for mn::buffer< TVALUE, TALLOCATOR >:

Public Types

using self_type = buffer< TVALUE, TALLOCATOR >
 
using value_type = TVALUE
 
using allocator = TALLOCATOR
 
using pointer = value_type *
 
using reference = value_type &
 
using size_type = mn::size_t
 
using const_reference = const value_type &
 
using const_pointer = const value_type *
 
using iterator_category = random_access_iterator_tag
 
using difference_type = ptrdiff_t
 
using iterator = pointer
 
using const_iterator = const value_type *
 

Public Member Functions

 buffer (const size_type &size)
 Consructs and allocates the Buffer. More...
 
 buffer (pointer buffer, size_type size)
 Consructs the buffer from a given memory pointer. More...
 
 buffer (const_pointer buffer, size_type size)
 Consructs and allocates the Buffer. copies the contents of the supplied memory into the buffer. More...
 
 buffer (const self_type &other)
 Move constructor. More...
 
 ~buffer ()
 Deconstrut the buffer. Is allocated the memory by buffer, then deallocated it. More...
 
iterator begin ()
 Get the iterator to the beginning of the buffer. More...
 
const_iterator begin () const
 Get the iterator to the beginning of the buffer. More...
 
iterator end ()
 Get the iterator to end of the buffer. More...
 
const_iterator end () const
 Get the iterator to end of the buffer. More...
 
void append (const_pointer pBuffer, std::size_t sBufferSize)
 Resizes this buffer and appends the given data. More...
 
void append (value_type value)
 Resizes this buffer and appends the given data. More...
 
void append (const self_type &refBuffer)
 Resizes this buffer and appends the given data. More...
 
bool resize (size_type newSize, bool bReserve=true)
 Resizes the buffer capacity and size. More...
 
bool change_size (size_type newSize, bool bReserve=true)
 Change the buffer size. More...
 
void assign (const_pointer pBuffer, size_type size)
 Assigns the argument buffer to this buffer. More...
 
void clear ()
 Clear the used content. More...
 
bool is_equel (const buffer &other) const
 Is the given buffer equel with this? More...
 
constexpr bool is_empty () const noexcept
 is the buffer empty? More...
 
constexpr bool is_full () const noexcept
 is the buffer full? More...
 
constexpr size_type get_size () const noexcept
 Get the allocated memory size in elements. More...
 
constexpr size_type get_size_bytes () const noexcept
 Get the allocated memory size in bytes. More...
 
constexpr size_type get_used () const noexcept
 Get the used size of the buffer in elements. More...
 
constexpr size_type get_used_bytes () const noexcept
 Get the used size of the buffer in bytes. More...
 
bool operator== (const buffer &other) const
 Compare operator. More...
 
bool operator!= (const buffer &other) const
 Not compare operator. More...
 
reference operator[] (size_type index)
 
const_reference operator[] (size_type index) const
 

Private Member Functions

void init_internal_buffer ()
 
void init_internal_buffer (const pointer buffer)
 
void destroy_internal_buffer ()
 

Private Attributes

size_type m_sSize
 
size_type m_sUsed
 
pointer m_pRawBuffer
 
bool m_bOwnMem
 
allocator m_allocator
 

Detailed Description

template<typename TVALUE, class TALLOCATOR = memory::default_allocator>
class mn::buffer< TVALUE, TALLOCATOR >

A buffer class that allocates a buffer of a given type and size.

Note
Useful for temporery buffering data.

Member Typedef Documentation

◆ allocator

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
using mn::buffer< TVALUE, TALLOCATOR >::allocator = TALLOCATOR

◆ const_iterator

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
using mn::buffer< TVALUE, TALLOCATOR >::const_iterator = const value_type*

◆ const_pointer

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
using mn::buffer< TVALUE, TALLOCATOR >::const_pointer = const value_type*

◆ const_reference

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
using mn::buffer< TVALUE, TALLOCATOR >::const_reference = const value_type&

◆ difference_type

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
using mn::buffer< TVALUE, TALLOCATOR >::difference_type = ptrdiff_t

◆ iterator

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
using mn::buffer< TVALUE, TALLOCATOR >::iterator = pointer

◆ iterator_category

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
using mn::buffer< TVALUE, TALLOCATOR >::iterator_category = random_access_iterator_tag

◆ pointer

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
using mn::buffer< TVALUE, TALLOCATOR >::pointer = value_type*

◆ reference

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
using mn::buffer< TVALUE, TALLOCATOR >::reference = value_type&

◆ self_type

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
using mn::buffer< TVALUE, TALLOCATOR >::self_type = buffer<TVALUE, TALLOCATOR>

◆ size_type

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
using mn::buffer< TVALUE, TALLOCATOR >::size_type = mn::size_t

◆ value_type

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
using mn::buffer< TVALUE, TALLOCATOR >::value_type = TVALUE

Constructor & Destructor Documentation

◆ buffer() [1/4]

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
mn::buffer< TVALUE, TALLOCATOR >::buffer ( const size_type size)
inline

Consructs and allocates the Buffer.

Parameters
sizeThe size of the buffer

◆ buffer() [2/4]

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
mn::buffer< TVALUE, TALLOCATOR >::buffer ( pointer  buffer,
size_type  size 
)
inline

Consructs the buffer from a given memory pointer.

Parameters
sizeThe size of the buffer
bufferThe using pointer for this buffer
Note
This pointer not deallocated, from buffer on deconstruction

◆ buffer() [3/4]

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
mn::buffer< TVALUE, TALLOCATOR >::buffer ( const_pointer  buffer,
size_type  size 
)
inline

Consructs and allocates the Buffer. copies the contents of the supplied memory into the buffer.

Parameters
sizeThe size of the buffer
bufferThe using pointer for this buffer

◆ buffer() [4/4]

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
mn::buffer< TVALUE, TALLOCATOR >::buffer ( const self_type other)
inline

Move constructor.

◆ ~buffer()

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
mn::buffer< TVALUE, TALLOCATOR >::~buffer ( )
inline

Deconstrut the buffer. Is allocated the memory by buffer, then deallocated it.

Member Function Documentation

◆ append() [1/3]

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
void mn::buffer< TVALUE, TALLOCATOR >::append ( const self_type refBuffer)
inline

Resizes this buffer and appends the given data.

Parameters
refBufferThe other buffer to append.

◆ append() [2/3]

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
void mn::buffer< TVALUE, TALLOCATOR >::append ( const_pointer  pBuffer,
std::size_t  sBufferSize 
)
inline

Resizes this buffer and appends the given data.

Parameters
pBufferThe array of data to append.
sBufferSizeThe number elements in the array.

◆ append() [3/3]

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
void mn::buffer< TVALUE, TALLOCATOR >::append ( value_type  value)
inline

Resizes this buffer and appends the given data.

Parameters
valueThe value to append.

◆ assign()

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
void mn::buffer< TVALUE, TALLOCATOR >::assign ( const_pointer  pBuffer,
size_type  size 
)
inline

Assigns the argument buffer to this buffer.

Note
If necessary, resizes the buffer.

◆ begin() [1/2]

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
iterator mn::buffer< TVALUE, TALLOCATOR >::begin ( )
inline

Get the iterator to the beginning of the buffer.

Returns
The iterator to the beginning of the buffer.

◆ begin() [2/2]

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
const_iterator mn::buffer< TVALUE, TALLOCATOR >::begin ( ) const
inline

Get the iterator to the beginning of the buffer.

Returns
The iterator to the beginning of the buffer.

◆ change_size()

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
bool mn::buffer< TVALUE, TALLOCATOR >::change_size ( size_type  newSize,
bool  bReserve = true 
)
inline

Change the buffer size.

Note
Externally memory can not change.
Parameters
newSizeThe new size for this buffer.
bReserveIf true then the content of the old buffer is copied over to the new buffer.

◆ clear()

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
void mn::buffer< TVALUE, TALLOCATOR >::clear ( )
inline

Clear the used content.

◆ destroy_internal_buffer()

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
void mn::buffer< TVALUE, TALLOCATOR >::destroy_internal_buffer ( )
inlineprivate

◆ end() [1/2]

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
iterator mn::buffer< TVALUE, TALLOCATOR >::end ( )
inline

Get the iterator to end of the buffer.

Returns
The iterator to end of the buffer.

◆ end() [2/2]

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
const_iterator mn::buffer< TVALUE, TALLOCATOR >::end ( ) const
inline

Get the iterator to end of the buffer.

Returns
The iterator to end of the buffer.

◆ get_size()

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
constexpr size_type mn::buffer< TVALUE, TALLOCATOR >::get_size ( ) const
inlineconstexprnoexcept

Get the allocated memory size in elements.

Returns
The allocated memory size in elements.

◆ get_size_bytes()

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
constexpr size_type mn::buffer< TVALUE, TALLOCATOR >::get_size_bytes ( ) const
inlineconstexprnoexcept

Get the allocated memory size in bytes.

Returns
The allocated memory size in bytes.

◆ get_used()

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
constexpr size_type mn::buffer< TVALUE, TALLOCATOR >::get_used ( ) const
inlineconstexprnoexcept

Get the used size of the buffer in elements.

Returns
The used size of the buffer in elements.

◆ get_used_bytes()

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
constexpr size_type mn::buffer< TVALUE, TALLOCATOR >::get_used_bytes ( ) const
inlineconstexprnoexcept

Get the used size of the buffer in bytes.

Returns
The used size of the buffer in bytes.

◆ init_internal_buffer() [1/2]

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
void mn::buffer< TVALUE, TALLOCATOR >::init_internal_buffer ( )
inlineprivate

◆ init_internal_buffer() [2/2]

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
void mn::buffer< TVALUE, TALLOCATOR >::init_internal_buffer ( const pointer  buffer)
inlineprivate

◆ is_empty()

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
constexpr bool mn::buffer< TVALUE, TALLOCATOR >::is_empty ( ) const
inlineconstexprnoexcept

is the buffer empty?

Returns
If true then is the buffer empty and if false then not.

◆ is_equel()

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
bool mn::buffer< TVALUE, TALLOCATOR >::is_equel ( const buffer< TVALUE, TALLOCATOR > &  other) const
inline

Is the given buffer equel with this?

Parameters
otherReference to the comparing buffer
Returns
true The given buffer is equel with this, false when not.

◆ is_full()

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
constexpr bool mn::buffer< TVALUE, TALLOCATOR >::is_full ( ) const
inlineconstexprnoexcept

is the buffer full?

Returns
If true then is the buffer full and if false then not.

◆ operator!=()

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
bool mn::buffer< TVALUE, TALLOCATOR >::operator!= ( const buffer< TVALUE, TALLOCATOR > &  other) const
inline

Not compare operator.

◆ operator==()

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
bool mn::buffer< TVALUE, TALLOCATOR >::operator== ( const buffer< TVALUE, TALLOCATOR > &  other) const
inline

Compare operator.

◆ operator[]() [1/2]

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
reference mn::buffer< TVALUE, TALLOCATOR >::operator[] ( size_type  index)
inline

◆ operator[]() [2/2]

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
const_reference mn::buffer< TVALUE, TALLOCATOR >::operator[] ( size_type  index) const
inline

◆ resize()

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
bool mn::buffer< TVALUE, TALLOCATOR >::resize ( size_type  newSize,
bool  bReserve = true 
)
inline

Resizes the buffer capacity and size.

Note
Externally memory can not resize.
Parameters
newSizeThe new size for this buffer.
bReserveIf true then the content of the old buffer is copied over to the new buffer.

Member Data Documentation

◆ m_allocator

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
allocator mn::buffer< TVALUE, TALLOCATOR >::m_allocator
private

◆ m_bOwnMem

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
bool mn::buffer< TVALUE, TALLOCATOR >::m_bOwnMem
private

◆ m_pRawBuffer

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
pointer mn::buffer< TVALUE, TALLOCATOR >::m_pRawBuffer
private

◆ m_sSize

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
size_type mn::buffer< TVALUE, TALLOCATOR >::m_sSize
private

◆ m_sUsed

template<typename TVALUE , class TALLOCATOR = memory::default_allocator>
size_type mn::buffer< TVALUE, TALLOCATOR >::m_sUsed
private

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