Skip to main content

WriteBuffer.ixx File

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

Included Headers

#include <vector> #include <helios.core.container.buffer.ReadBuffer>

Namespaces Index

namespacehelios
namespacecore

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

namespacecontainer

Generic container types shared across the 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...

classWriteBuffer<T>

Write-only buffer for accumulating messages in a double-buffered system. More...

Description

Write-only buffer for the double-buffering pattern.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file WriteBuffer.ixx
3 * @brief Write-only buffer for the double-buffering pattern.
4 */
5module;
6
7#include <vector>
8
9export module helios.core.container.buffer.WriteBuffer;
10
11import helios.core.container.buffer.ReadBuffer;
12
13export namespace helios::core::container::buffer {
14
15 template <typename T>
17
18 /**
19 * @class WriteBuffer
20 * @brief Write-only buffer for accumulating messages in a double-buffered system.
21 *
22 * @details WriteBuffer is the producer-side of a double-buffered message system.
23 * Messages are pushed to this buffer during frame processing, then swapped with a
24 * ReadBuffer at frame boundaries. This separation enables lock-free, single-threaded
25 * producer-consumer patterns.
26 *
27 * The internal storage is only accessible to ReadWriteDoubleBuffer for swap operations.
28 *
29 * @tparam T The message type stored in the buffer. Must be move-constructible.
30 */
31 template<typename T>
32 class WriteBuffer {
33
34 friend class ReadWriteDoubleBuffer<T>;
35
36 /**
37 * @brief Internal storage for buffered messages.
38 */
39 std::vector<T> bufferData_;
40
41 /**
42 * @brief Returns a mutable reference to the internal buffer.
43 *
44 * @details Only accessible to ReadWriteDoubleBuffer for swap operations.
45 *
46 * @return Reference to the internal vector.
47 */
48 [[nodiscard]] std::vector<T>& bufferData() {
49 return bufferData_;
50 }
51
52 public:
53
54 /**
55 * @brief Constructs and appends a message to the buffer.
56 *
57 * @tparam Args Constructor argument types for T.
58 *
59 * @param args Arguments forwarded to T's constructor.
60 *
61 * @return Reference to this buffer for method chaining.
62 */
63 template<typename... Args>
64 WriteBuffer& push(Args&&... args) {
65 bufferData_.emplace_back(std::forward<Args>(args)...);
66 return *this;
67 }
68
69 /**
70 * @brief Pre-allocates memory for the specified number of messages.
71 *
72 * @param size The number of messages to reserve capacity for.
73 *
74 * @return Reference to this buffer for method chaining.
75 */
76 WriteBuffer& reserve(size_t size) {
77 bufferData_.reserve(size);
78 return *this;
79 }
80
81 /**
82 * @brief Removes all messages from the buffer.
83 *
84 * @return Reference to this buffer for method chaining.
85 */
87 bufferData_.clear();
88 return *this;
89 }
90 };
91
92}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.