Skip to main content

ReadWriteDoubleBuffer Class Template

Type-safe double-buffered container for messages of type T. More...

Declaration

template <typename T> class helios::engine::core::container::buffer::ReadWriteDoubleBuffer<T> { ... }

Base class

classDoubleBuffer

Abstract base class for type-erased message buffers. More...

Public Member Functions Index

template <typename T>
voidreserve (size_t size)

Pre-allocates memory for both buffers. More...

template <typename... Args>
voidpush (Args &&... args)

Constructs and pushes a message to the write buffer. More...

template <typename T>
auto read () const noexcept -> std::span< const T >

Returns a read-only view of messages in the read buffer. More...

template <typename T>
voidswap () override

Swaps read with write buffer. More...

template <typename T>
voidclearReadBuffer () override

Clears the read buffer. More...

template <typename T>
voidclearWriteBuffer () override

Clears the write buffer. More...

Private Member Attributes Index

template <typename T>
ReadBuffer< T >readBuffer_

Buffer containing messages available for reading. More...

template <typename T>
WriteBuffer< T >writeBuffer_

Buffer where new messages are pushed. More...

Description

Type-safe double-buffered container for messages of type T.

Implements a producer-consumer pattern where messages are written to one buffer while consumers read from another. This decouples message production from consumption and allows lock-free operation in single-threaded game loops.

Template Parameters
T

The message type stored in this buffer. Must be movable.

Definition at line 34 of file ReadWriteDoubleBuffer.ixx.

Public Member Functions

clearReadBuffer()

template <typename T>
void helios::engine::core::container::buffer::ReadWriteDoubleBuffer< T >::clearReadBuffer ()
inline virtual

Clears the read buffer.

Definition at line 93 of file ReadWriteDoubleBuffer.ixx.

93 void clearReadBuffer() override {
94 readBuffer_.clear();
95 }

Reference helios::engine::core::container::buffer::ReadBuffer< T >::clear.

clearWriteBuffer()

template <typename T>
void helios::engine::core::container::buffer::ReadWriteDoubleBuffer< T >::clearWriteBuffer ()
inline virtual

Clears the write buffer.

Definition at line 100 of file ReadWriteDoubleBuffer.ixx.

100 void clearWriteBuffer() override {
101 writeBuffer_.clear();
102 }

Reference helios::engine::core::container::buffer::WriteBuffer< T >::clear.

push()

template <typename... Args>
void helios::engine::core::container::buffer::ReadWriteDoubleBuffer< T >::push (Args &&... args)
inline

Constructs and pushes a message to the write buffer.

Template Parameters
Args

Constructor argument types for T.

Parameters
args

Arguments forwarded to T's constructor.

Definition at line 67 of file ReadWriteDoubleBuffer.ixx.

67 void push(Args&&... args) {
68 writeBuffer_.push(std::forward<Args>(args)...);
69 }

References helios::engine::core::container::buffer::WriteBuffer< T >::push and helios::registerComponents.

read()

template <typename T>
std::span< const T > helios::engine::core::container::buffer::ReadWriteDoubleBuffer< T >::read ()
inline noexcept

Returns a read-only view of messages in the read buffer.

Returns

A span over all messages written in the previous frame.

Definition at line 76 of file ReadWriteDoubleBuffer.ixx.

76 std::span<const T> read() const noexcept {
77 return readBuffer_.read();
78 }

Reference helios::engine::core::container::buffer::ReadBuffer< T >::read.

reserve()

template <typename T>
void helios::engine::core::container::buffer::ReadWriteDoubleBuffer< T >::reserve (size_t size)
inline

Pre-allocates memory for both buffers.

Parameters
size

The number of messages to reserve capacity for.

Definition at line 54 of file ReadWriteDoubleBuffer.ixx.

54 void reserve(size_t size) {
55 readBuffer_.reserve(size);
56 writeBuffer_.reserve(size);
57 }

References helios::engine::core::container::buffer::ReadBuffer< T >::reserve and helios::engine::core::container::buffer::WriteBuffer< T >::reserve.

swap()

template <typename T>
void helios::engine::core::container::buffer::ReadWriteDoubleBuffer< T >::swap ()
inline virtual

Swaps read with write buffer.

Swaps the read- with the write-buffer. The write buffer is empty after this operation, while the read buffer contains the contents of the write buffer.

Definition at line 86 of file ReadWriteDoubleBuffer.ixx.

86 void swap() override {
87 readBuffer_.clear().bufferData().swap(writeBuffer_.bufferData());
88 }

Reference helios::engine::core::container::buffer::ReadBuffer< T >::clear.

Private Member Attributes

readBuffer_

template <typename T>
ReadBuffer<T> helios::engine::core::container::buffer::ReadWriteDoubleBuffer< T >::readBuffer_

Buffer containing messages available for reading.

Definition at line 39 of file ReadWriteDoubleBuffer.ixx.

39 ReadBuffer<T> readBuffer_;

writeBuffer_

template <typename T>
WriteBuffer<T> helios::engine::core::container::buffer::ReadWriteDoubleBuffer< T >::writeBuffer_

Buffer where new messages are pushed.

Definition at line 44 of file ReadWriteDoubleBuffer.ixx.

44 WriteBuffer<T> writeBuffer_;

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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.