Skip to main content

ReadWriteBuffer.ixx File

Combined read-write buffer for single-buffered access patterns. More...

Included Headers

#include <span> #include <vector> #include <helios.core.buffer.Buffer>

Namespaces Index

namespacehelios
namespacecore

Core utilities shared across the helios engine. More...

namespacebuffer

Double-buffering infrastructure for thread-safe message passing. More...

Classes Index

classReadWriteBuffer<T>

Combined read-write buffer with immediate visibility. More...

Description

Combined read-write buffer for single-buffered access patterns.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file ReadWriteBuffer.ixx
3 * @brief Combined read-write buffer for single-buffered access patterns.
4 */
5module;
6
7#include <span>
8#include <vector>
9
10export module helios.core.buffer.ReadWriteBuffer;
11
12import helios.core.buffer.Buffer;
13
14export namespace helios::core::buffer {
15
16 /**
17 * @brief Combined read-write buffer with immediate visibility.
18 *
19 * @details Unlike the double-buffered ReadBuffer/WriteBuffer pair, ReadWriteBuffer
20 * provides immediate access to pushed messages within the same frame. Messages
21 * are visible to readers as soon as they are pushed.
22 *
23 * Use this when message producers and consumers operate in the same phase and
24 * immediate visibility is required. For cross-phase communication, prefer
25 * ReadWriteDoubleBuffer.
26 *
27 * @tparam T The message type stored in the buffer.
28 */
29 template<typename T>
31
32 /**
33 * @brief Internal storage for buffered messages.
34 */
35 std::vector<T> bufferData_;
36
37 /**
38 * @brief Returns a mutable reference to the internal buffer.
39 *
40 * @return Reference to the internal vector.
41 */
42 [[nodiscard]] std::vector<T>& bufferData() {
43 return bufferData_;
44 }
45
46 public:
47
48 /**
49 * @brief Returns a read-only view of all buffered messages.
50 *
51 * @return A span over all messages in the buffer.
52 */
53 std::span<const T> read() const noexcept {
54 return bufferData_;
55 }
56
57 /**
58 * @brief Constructs and appends a message to the buffer.
59 *
60 * @tparam Args Constructor argument types for T.
61 *
62 * @param args Arguments forwarded to T's constructor.
63 *
64 * @return Reference to this buffer for method chaining.
65 */
66 template<typename... Args>
67 ReadWriteBuffer& push(Args&&... args) {
68 bufferData_.emplace_back(std::forward<Args>(args)...);
69 return *this;
70 }
71
72 /**
73 * @brief Pre-allocates memory for the specified number of messages.
74 *
75 * @param size The number of messages to reserve capacity for.
76 *
77 * @return Reference to this buffer for method chaining.
78 */
79 ReadWriteBuffer& reserve(size_t size) {
80 bufferData_.reserve(size);
81 return *this;
82 }
83
84 /**
85 * @brief Removes all messages from the buffer.
86 */
87 void clear() override {
88 bufferData_.clear();
89 }
90 };
91
92}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.