Skip to main content

TypeIndexedReadWriteBuffer.ixx File

Type-indexed single-buffered message system for immediate-access patterns. More...

Included Headers

#include <memory> #include <span> #include <vector> #include <cstddef> #include <helios.engine.core.container.buffer:ReadWriteBuffer> #include <helios.engine.core.container.buffer.concepts.IsTypeIndexerLike>

Namespaces Index

namespacehelios
namespaceengine
namespacecore
namespacecontainer
namespacebuffer

Classes Index

classTypeIndexedReadWriteBuffer<Indexer>

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

Description

Type-indexed single-buffered message system for immediate-access patterns.

File Listing

The file content with the documentation metadata removed is:

1
5module;
6
7#include <memory>
8#include <span>
9#include <vector>
10#include <cstddef>
11
12export module helios.engine.core.container.buffer:TypeIndexedReadWriteBuffer;
13
14import helios.engine.core.container.buffer.concepts.IsTypeIndexerLike;
15import :Buffer;
16import :ReadWriteBuffer;
17
18using namespace helios::engine::core::container::buffer::concepts;
20
34 template<typename Indexer>
37
41 std::vector<std::unique_ptr<Buffer>> buffers_;
42
50 template<typename T>
51 static size_t index() {
52 return Indexer::template typeIndex<T>();
53 }
54
55 public:
56
61
66
75 template<typename T, typename... Args>
76 void push(Args&&... args) {
77 getOrCreateBuffer<T>().push(std::forward<Args>(args)...);
78 }
79
90 template<typename T>
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 }
101
111 template<typename T>
112 void reserve(size_t size) {
113 getOrCreateBuffer<T>().reserve(size);
114 }
115
123 template<typename T>
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 }
137
138
142 void clear() {
143 for (auto& buffer : buffers_) {
144 if (buffer) {
145 buffer->clear();
146 }
147 }
148 }
149
150 };
151
152
153}
154

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.