Skip to main content

TypeIndexedReadWriteBuffer Class Template

Type-indexed container for immediate-access message buffers. More...

Declaration

template <typename Indexer> class helios::core::buffer::TypeIndexedReadWriteBuffer<Indexer> { ... }

Public Constructors Index

template <typename Indexer>
TypeIndexedReadWriteBuffer ()=default

Default constructor. More...

Public Destructor Index

template <typename Indexer>
~TypeIndexedReadWriteBuffer ()=default

Default destructor. More...

Public Member Functions Index

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

Pushes a message of type T to the buffer. More...

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

Returns a read-only view of all messages of type T. More...

template <typename T>
voidreserve (size_t size)

Pre-allocates capacity for messages of type T. More...

template <typename T>
auto getOrCreateBuffer () -> ReadWriteBuffer< T > &

Gets or creates the buffer for message type T. More...

template <typename Indexer>
voidclear ()

Clears all buffers. More...

Private Member Attributes Index

template <typename Indexer>
std::vector< std::unique_ptr< Buffer > >buffers_

Type-erased storage for message buffers, indexed by type. More...

Private Static Functions Index

template <typename T>
static size_tindex ()

Returns the buffer index for message type T. More...

Description

Type-indexed container for immediate-access message buffers.

Unlike TypeIndexedDoubleBuffer, this container provides immediate visibility of pushed messages within the same frame. Each message type T gets its own dedicated ReadWriteBuffer, indexed via TypeIndexer for O(1) access.

Use this when message producers and consumers operate in the same phase. For cross-phase communication with frame-boundary swapping, prefer TypeIndexedDoubleBuffer.

Template Parameters
Indexer

The TypeIndexer used for mapping message types to buffer indices.

Definition at line 36 of file TypeIndexedReadWriteBuffer.ixx.

Public Constructors

TypeIndexedReadWriteBuffer()

template <typename Indexer>
helios::core::buffer::TypeIndexedReadWriteBuffer< Indexer >::TypeIndexedReadWriteBuffer ()
default

Default constructor.

Definition at line 65 of file TypeIndexedReadWriteBuffer.ixx.

Public Destructor

~TypeIndexedReadWriteBuffer()

template <typename Indexer>
helios::core::buffer::TypeIndexedReadWriteBuffer< Indexer >::~TypeIndexedReadWriteBuffer ()
default

Default destructor.

Definition at line 60 of file TypeIndexedReadWriteBuffer.ixx.

Public Member Functions

clear()

template <typename Indexer>
void helios::core::buffer::TypeIndexedReadWriteBuffer< Indexer >::clear ()
inline

Clears all buffers.

Definition at line 142 of file TypeIndexedReadWriteBuffer.ixx.

142 void clear() {
143 for (auto& buffer : buffers_) {
144 if (buffer) {
145 buffer->clear();
146 }
147 }
148 }

getOrCreateBuffer()

template <typename T>
ReadWriteBuffer< T > & helios::core::buffer::TypeIndexedReadWriteBuffer< Indexer >::getOrCreateBuffer ()
inline

Gets or creates the buffer for message type T.

Template Parameters
T

The message type.

Returns

Reference to the ReadWriteBuffer for type T.

Definition at line 124 of file TypeIndexedReadWriteBuffer.ixx.

125 const size_t idx = index<T>();
126
127 if (buffers_.size() <= idx) {
128 buffers_.resize(idx + 1);
129 }
130
131 if (!buffers_[idx]) {
132 buffers_[idx] = std::make_unique<ReadWriteBuffer<T>>();
133 }
134
135 return *static_cast<ReadWriteBuffer<T>*>(buffers_[idx].get());
136 }

Referenced by helios::core::buffer::TypeIndexedReadWriteBuffer< Indexer >::push and helios::core::buffer::TypeIndexedReadWriteBuffer< Indexer >::reserve.

push()

template <typename T, typename... Args>
void helios::core::buffer::TypeIndexedReadWriteBuffer< Indexer >::push (Args &&... args)
inline

Pushes a message of type T to the buffer.

Template Parameters
T

The message type.

Args

Constructor argument types for T.

Parameters
args

Arguments forwarded to T's constructor.

Definition at line 76 of file TypeIndexedReadWriteBuffer.ixx.

76 void push(Args&&... args) {
77 getOrCreateBuffer<T>().push(std::forward<Args>(args)...);
78 }

Reference helios::core::buffer::TypeIndexedReadWriteBuffer< Indexer >::getOrCreateBuffer.

read()

template <typename T>
std::span< const T > helios::core::buffer::TypeIndexedReadWriteBuffer< Indexer >::read ()
inline noexcept

Returns a read-only view of all messages of type T.

Returns messages that were written to the buffer. If no messages of type T exist, returns an empty span.

Template Parameters
T

The message type to read.

Returns

A span over all messages of type T in the read buffer.

Definition at line 91 of file TypeIndexedReadWriteBuffer.ixx.

91 std::span<const T> read() const noexcept {
92
93 const size_t idx = index<T>();
94
95 if (buffers_.size() <= idx || !buffers_[idx]) {
96 return {};
97 }
98
99 return static_cast<ReadWriteBuffer<T>*>(buffers_[idx].get())->read();
100 }

Reference helios::core::buffer::ReadWriteBuffer< T >::read.

reserve()

template <typename T>
void helios::core::buffer::TypeIndexedReadWriteBuffer< Indexer >::reserve (size_t size)
inline

Pre-allocates capacity for messages of type T.

Call during initialization to avoid allocations during gameplay.

Template Parameters
T

The message type.

Parameters
size

The number of messages to reserve capacity for.

Definition at line 112 of file TypeIndexedReadWriteBuffer.ixx.

112 void reserve(size_t size) {
113 getOrCreateBuffer<T>().reserve(size);
114 }

Reference helios::core::buffer::TypeIndexedReadWriteBuffer< Indexer >::getOrCreateBuffer.

Private Member Attributes

buffers_

template <typename Indexer>
std::vector<std::unique_ptr<Buffer> > helios::core::buffer::TypeIndexedReadWriteBuffer< Indexer >::buffers_

Type-erased storage for message buffers, indexed by type.

Definition at line 41 of file TypeIndexedReadWriteBuffer.ixx.

41 std::vector<std::unique_ptr<Buffer>> buffers_;

Private Static Functions

index()

template <typename T>
size_t helios::core::buffer::TypeIndexedReadWriteBuffer< Indexer >::index ()
inline static

Returns the buffer index for message type T.

Template Parameters
T

The message type.

Returns

The index assigned to type T by the Indexer.

Definition at line 51 of file TypeIndexedReadWriteBuffer.ixx.

51 static size_t index() {
52 return Indexer::template typeIndex<T>();
53 }

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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.