Nugget
Loading...
Searching...
No Matches
Public Member Functions | List of all members
Utilities::Buffer< T, Allocator > Class Template Reference

A class that manages a buffer of data. More...

#include <common/util/buffer.hh>

Public Member Functions

 Buffer ()
 
 Buffer (size_t size)
 
 Buffer (T *data, size_t size)
 
 Buffer (const Buffer &other)
 
 Buffer (Buffer &&other) noexcept
 
 ~Buffer ()
 
Bufferoperator= (const Buffer &other)
 
Bufferoperator= (Buffer &&other) noexcept
 
void clear ()
 
void resize (size_t size)
 
T * data ()
 
const T * data () const
 
size_t size () const
 
T & operator[] (size_t index)
 
const T & operator[] (size_t index) const
 
T * begin ()
 
T * end ()
 
const T * begin () const
 
const T * end () const
 
bool empty () const
 

Detailed Description

template<typename T, class Allocator>
class Utilities::Buffer< T, Allocator >

A class that manages a buffer of data.

The Buffer class is a template class that manages a buffer of data of type T. It behaves similarly to a std::vector, providing the same kind of accessors, with some key differences: when resizing the buffer, it will use C's realloc() function to resize the buffer, with the guarantee that the data is not moved if the size is the same or less, as POSIX realloc does. Also, the buffer can be created from an external pointer, in which case the buffer will consider the data to be external and will not try to free or reallocate it. This is useful for when the data is for instance a static array or a pointer allocated by a different allocator.

Template Parameters
TThe type of the data in the buffer.
AllocatorThe allocator to use for allocating, deallocating, reallocating and copying the data. The allocator must provide the following functions:
  • allocate(size_t size): Allocates a buffer of size bytes and returns a pointer to the buffer.
  • deallocate(void* data): Deallocates the buffer pointed to by data.
  • reallocate(void* data, size_t size): Reallocates the buffer pointed to by data to size bytes and returns a pointer to the buffer. The behavior needs to be the same as realloc() in C, meaning that if the size is the same or less, the data is not moved. If the size is greater, the data may be moved to a new location. If the size is 0, the data is deallocated and a null pointer is returned.
  • copy(void* dest, const void* src, size_t size): Copies size bytes from src to dest. The behavior needs to be the same as memcpy() in C.

Constructor & Destructor Documentation

◆ Buffer() [1/5]

template<typename T , class Allocator >
Utilities::Buffer< T, Allocator >::Buffer ( )
inline

◆ Buffer() [2/5]

template<typename T , class Allocator >
Utilities::Buffer< T, Allocator >::Buffer ( size_t  size)
inline

◆ Buffer() [3/5]

template<typename T , class Allocator >
Utilities::Buffer< T, Allocator >::Buffer ( T *  data,
size_t  size 
)
inline

◆ Buffer() [4/5]

template<typename T , class Allocator >
Utilities::Buffer< T, Allocator >::Buffer ( const Buffer< T, Allocator > &  other)
inline

◆ Buffer() [5/5]

template<typename T , class Allocator >
Utilities::Buffer< T, Allocator >::Buffer ( Buffer< T, Allocator > &&  other)
inlinenoexcept

◆ ~Buffer()

template<typename T , class Allocator >
Utilities::Buffer< T, Allocator >::~Buffer ( )
inline

Member Function Documentation

◆ begin() [1/2]

template<typename T , class Allocator >
T * Utilities::Buffer< T, Allocator >::begin ( )
inline

◆ begin() [2/2]

template<typename T , class Allocator >
const T * Utilities::Buffer< T, Allocator >::begin ( ) const
inline

◆ clear()

template<typename T , class Allocator >
void Utilities::Buffer< T, Allocator >::clear ( )
inline

◆ data() [1/2]

template<typename T , class Allocator >
T * Utilities::Buffer< T, Allocator >::data ( )
inline

◆ data() [2/2]

template<typename T , class Allocator >
const T * Utilities::Buffer< T, Allocator >::data ( ) const
inline

◆ empty()

template<typename T , class Allocator >
bool Utilities::Buffer< T, Allocator >::empty ( ) const
inline

◆ end() [1/2]

template<typename T , class Allocator >
T * Utilities::Buffer< T, Allocator >::end ( )
inline

◆ end() [2/2]

template<typename T , class Allocator >
const T * Utilities::Buffer< T, Allocator >::end ( ) const
inline

◆ operator=() [1/2]

template<typename T , class Allocator >
Buffer & Utilities::Buffer< T, Allocator >::operator= ( Buffer< T, Allocator > &&  other)
inlinenoexcept

◆ operator=() [2/2]

template<typename T , class Allocator >
Buffer & Utilities::Buffer< T, Allocator >::operator= ( const Buffer< T, Allocator > &  other)
inline

◆ operator[]() [1/2]

template<typename T , class Allocator >
T & Utilities::Buffer< T, Allocator >::operator[] ( size_t  index)
inline

◆ operator[]() [2/2]

template<typename T , class Allocator >
const T & Utilities::Buffer< T, Allocator >::operator[] ( size_t  index) const
inline

◆ resize()

template<typename T , class Allocator >
void Utilities::Buffer< T, Allocator >::resize ( size_t  size)
inline

◆ size()

template<typename T , class Allocator >
size_t Utilities::Buffer< T, Allocator >::size ( ) const
inline

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