MostlyHarmless 0.0.1
 
Loading...
Searching...
No Matches
marvin::containers::SwapBuffer< T > Class Template Referencefinal

Convenience type to handle the concept of an "active" buffer, and a "back" buffer. More...

#include <marvin_SwapBuffer.h>

Public Member Functions

 SwapBuffer ()=default
 
 SwapBuffer (const SwapBuffer< T > &other)=default
 
 SwapBuffer (SwapBuffer< T > &&other) noexcept=default
 
 SwapBuffer (size_t len)
 
 SwapBuffer (size_t len, T fillV)
 
 ~SwapBuffer () noexcept=default
 
SwapBufferoperator= (const SwapBuffer< T > &other)=default
 
SwapBufferoperator= (SwapBuffer< T > &&other) noexcept=default
 
size_t size () const noexcept
 
void reserve (size_t toReserve)
 
void resize (size_t newSize)
 
std::span< T > getFrontBuffer ()
 
std::span< T > getBackBuffer ()
 
void swap () noexcept
 

Detailed Description

template<typename T>
requires std::is_default_constructible_v<T> && std::is_copy_constructible_v<T> && std::is_move_constructible_v<T>
class marvin::containers::SwapBuffer< T >

Convenience type to handle the concept of an "active" buffer, and a "back" buffer.

Constructor & Destructor Documentation

◆ SwapBuffer() [1/5]

template<typename T>
marvin::containers::SwapBuffer< T >::SwapBuffer ( )
default

Constructs a SwapBuffer without allocating any space for the internal buffers. If using this constructor, make sure you call resize before doing anything else.

◆ SwapBuffer() [2/5]

template<typename T>
marvin::containers::SwapBuffer< T >::SwapBuffer ( const SwapBuffer< T > & other)
default

◆ SwapBuffer() [3/5]

template<typename T>
marvin::containers::SwapBuffer< T >::SwapBuffer ( SwapBuffer< T > && other)
defaultnoexcept

◆ SwapBuffer() [4/5]

template<typename T>
marvin::containers::SwapBuffer< T >::SwapBuffer ( size_t len)
inlineexplicit

Constructs a SwapBuffer, and resizes both internal buffers to size len.

Parameters
lenThe number of elements to allocate.

◆ SwapBuffer() [5/5]

template<typename T>
marvin::containers::SwapBuffer< T >::SwapBuffer ( size_t len,
T fillV )
inline

Constructs a SwapBuffer, resizes both internal buffers to size len, and then fills them with fillV.

Parameters
lenThe number of elements to allocate.
fillVThe value to fill the internal buffers with.

◆ ~SwapBuffer()

template<typename T>
marvin::containers::SwapBuffer< T >::~SwapBuffer ( )
defaultnoexcept

Member Function Documentation

◆ getBackBuffer()

template<typename T>
std::span< T > marvin::containers::SwapBuffer< T >::getBackBuffer ( )
inlinenodiscard

Constructs a non-owning view into the inactive "writeable" back buffer.

Returns
A non owning view into the current back buffer.

◆ getFrontBuffer()

template<typename T>
std::span< T > marvin::containers::SwapBuffer< T >::getFrontBuffer ( )
inlinenodiscard

Constructs a non-owning view to the active "readable" front buffer.

Returns
A non owning view into the current front buffer.

◆ operator=() [1/2]

template<typename T>
SwapBuffer & marvin::containers::SwapBuffer< T >::operator= ( const SwapBuffer< T > & other)
default

◆ operator=() [2/2]

template<typename T>
SwapBuffer & marvin::containers::SwapBuffer< T >::operator= ( SwapBuffer< T > && other)
defaultnoexcept

◆ reserve()

template<typename T>
void marvin::containers::SwapBuffer< T >::reserve ( size_t toReserve)
inline

Preallocates toReserve elements in the internal buffers, to allow for allocation-free resizing later on, provided the size given to resize is < the reserved size.
Note that after calling this, the size of the internal buffers is unchanged - to actually set the size of the buffers, call resize().

Parameters
toReserveThe number of elements to allocate.

◆ resize()

template<typename T>
void marvin::containers::SwapBuffer< T >::resize ( size_t newSize)
inline

Resizes the internal buffers to be newSize elements long. If enough space has not been preallocated via a call to reserve, and the previous size < newSize, this will allocate.

Parameters
newSizeThe new size of the internal buffers.

◆ size()

template<typename T>
size_t marvin::containers::SwapBuffer< T >::size ( ) const
inlinenodiscardnoexcept

Returns the number of elements allocated in the internal buffers. Only returns m_a.size(), but in debug asserts that the two sizes match.

Returns
The number of elements allocated in the internal buffers.

◆ swap()

template<typename T>
void marvin::containers::SwapBuffer< T >::swap ( )
inlinenoexcept

Swaps the front and back buffers. Internally this flips a bool, that causes subsequent calls to getFrontBuffer() and getBackBuffer() to flip the internal buffer they're using. Doesn't perform any allocations, and should not be thought of as analogous to std::swap.
In practice, this should be called when you want to "commit" the data from the back buffer to the active buffer.


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