Skip to main content

ReadBuffer.ixx File

Read-only buffer for the double-buffering pattern. More...

Included Headers

#include <span> #include <vector>

Namespaces Index

namespacehelios
namespacecore

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

namespacebuffer

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

Classes Index

classReadWriteDoubleBuffer<T>

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

classReadBuffer<T>

Read-only buffer for consuming messages in a double-buffered system. More...

Description

Read-only buffer for the double-buffering pattern.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file ReadBuffer.ixx
3 * @brief Read-only buffer for the double-buffering pattern.
4 */
5module;
6
7#include <span>
8#include <vector>
9
10export module helios.core.buffer.ReadBuffer;
11
12export namespace helios::core::buffer {
13
14 template <typename T>
16
17 /**
18 * @class ReadBuffer
19 * @brief Read-only buffer for consuming messages in a double-buffered system.
20 *
21 * @details ReadBuffer is the consumer-side of a double-buffered message system.
22 * After a swap operation, this buffer contains messages that were pushed to the
23 * corresponding WriteBuffer during the previous frame. Consumers iterate over
24 * these messages via the read() method.
25 *
26 * The internal storage is only accessible to ReadWriteDoubleBuffer for swap operations.
27 *
28 * @tparam T The message type stored in the buffer.
29 */
30 template<typename T>
31 class ReadBuffer {
32
33 friend class ReadWriteDoubleBuffer<T>;
34
35 /**
36 * @brief Internal storage for buffered messages.
37 */
38 std::vector<T> bufferData_;
39
40 /**
41 * @brief Returns a mutable reference to the internal buffer.
42 *
43 * @details Only accessible to ReadWriteDoubleBuffer for swap operations.
44 *
45 * @return Reference to the internal vector.
46 */
47 [[nodiscard]] std::vector<T>& bufferData() {
48 return bufferData_;
49 }
50
51 public:
52
53 /**
54 * @brief Returns a read-only view of all buffered messages.
55 *
56 * @return A span over all messages in the buffer.
57 */
58 std::span<const T> read() const noexcept {
59 return bufferData_;
60 }
61
62 /**
63 * @brief Pre-allocates memory for the specified number of messages.
64 *
65 * @param size The number of messages to reserve capacity for.
66 *
67 * @return Reference to this buffer for method chaining.
68 */
69 ReadBuffer& reserve(size_t size) {
70 bufferData_.reserve(size);
71 return *this;
72 }
73
74 /**
75 * @brief Removes all messages from the buffer.
76 *
77 * @return Reference to this buffer for method chaining.
78 */
80 bufferData_.clear();
81 return *this;
82 }
83 };
84
85}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.