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 | |
SwapBuffer & | operator= (const SwapBuffer< T > &other)=default |
SwapBuffer & | operator= (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 |
Convenience type to handle the concept of an "active" buffer, and a "back" buffer.
|
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.
|
default |
|
defaultnoexcept |
|
inlineexplicit |
Constructs a SwapBuffer, and resizes both internal buffers to size len
.
len | The number of elements to allocate. |
|
inline |
Constructs a SwapBuffer, resizes both internal buffers to size len
, and then fills them with fillV
.
len | The number of elements to allocate. |
fillV | The value to fill the internal buffers with. |
|
defaultnoexcept |
|
inlinenodiscard |
Constructs a non-owning view into the inactive "writeable" back buffer.
|
inlinenodiscard |
Constructs a non-owning view to the active "readable" front buffer.
|
default |
|
defaultnoexcept |
|
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()
.
toReserve | The number of elements to allocate. |
|
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.
newSize | The new size of the internal buffers. |
|
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.
|
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.