StormByte C++ Library 0.0.9999
StormByte is a comprehensive, cross-platform C++ library aimed at easing system programming, configuration management, logging, and database handling tasks. This library provides a unified API that abstracts away the complexities and inconsistencies of different platforms (Windows, Linux).
Loading...
Searching...
No Matches
typedefs.hxx
1#pragma once
2
3#include <StormByte/expected.hxx>
4
5#include <cstddef>
6#include <functional>
7#include <memory>
8#include <span>
9#include <type_traits>
10#include <vector>
11
25namespace StormByte::Buffer {
33 namespace Read {
48 enum class Position: unsigned short {
49 Begin = 0x01,
50 End = 0x02,
51 Relative = 0x04,
52 Absolute = 0x08
53 };
54
65 enum class Status: unsigned short {
66 Success,
67 Error
68 };
69 }
70
78 namespace Write {
89 enum class Status: unsigned short {
90 Success,
91 Error
92 };
93 }
94
106 enum class Status {
107 Ready,
108 ReadOnly,
109 Error
110 };
111
112 // Forward declarations
117 class Simple;
118
123 class Shared;
124
129 class Producer;
130
135 class Consumer;
136
137 // Data types
138 using Byte = std::byte;
139 using Data = std::vector<Byte>;
140 using ByteSpan = std::span<Byte>;
141 using ConstByteSpan = std::span<const Byte>;
142 template<class T>
144 template<class T>
146 template<class T>
148 template<class T>
150 template<class T>
152 template<class T>
154 template<class T>
156 using PipeFunction = std::function<void(Consumer, Producer)>;
157 using Processor = std::function<std::shared_ptr<Simple>(const Simple&)>;
158
173 template <typename PtrType, typename T,
174 typename = std::enable_if_t<
175 (std::is_same_v<PtrType, std::shared_ptr<typename PtrType::element_type>> ||
176 std::is_same_v<PtrType, std::unique_ptr<typename PtrType::element_type>>)
177 >
178 >
179 inline PtrType& operator<<(PtrType& ptr, const T& value) {
180 static_assert(std::is_same_v<PtrType, std::shared_ptr<typename PtrType::element_type>> ||
181 std::is_same_v<PtrType, std::unique_ptr<typename PtrType::element_type>>,
182 "PtrType must be a std::shared_ptr or std::unique_ptr");
183 if (ptr) {
184 *ptr << value; // Forward the call to the existing operator<<
185 }
186 return ptr;
187 }
188
203 template <typename PtrType, typename T,
204 typename = std::enable_if_t<
205 (std::is_same_v<PtrType, std::shared_ptr<typename PtrType::element_type>> ||
206 std::is_same_v<PtrType, std::unique_ptr<typename PtrType::element_type>>)
207 >
208 >
209 inline PtrType& operator<<(PtrType& ptr, T&& value) {
210 static_assert(std::is_same_v<PtrType, std::shared_ptr<typename PtrType::element_type>> ||
211 std::is_same_v<PtrType, std::unique_ptr<typename PtrType::element_type>>,
212 "PtrType must be a std::shared_ptr or std::unique_ptr");
213 if (ptr) {
214 *ptr << std::move(value); // Forward the call to the existing operator<<
215 }
216 return ptr;
217 }
218}
A read-only interface for accessing a shared buffer.
Definition consumer.hxx:37
A write-only interface for accessing a shared buffer.
Definition producer.hxx:43
A lightweight class for storing and manipulating simple byte buffers.
Definition simple.hxx:36
Namespace for read-related utilities in the StormByte library.
Namespace for buffer-related components in the StormByte library.
Definition consumer.hxx:19
std::span< const Byte > ConstByteSpan
Represents a constant span of bytes.
Definition typedefs.hxx:141
Expected< Byte, T > ExpectedByte
Represents a single byte with error handling.
Definition typedefs.hxx:143
std::function< std::shared_ptr< Simple >(const Simple &)> Processor
Represents a function that processes a buffer.
Definition typedefs.hxx:157
std::function< void(Consumer, Producer)> PipeFunction
Represents a function that processes a data pipe.
Definition typedefs.hxx:156
std::span< Byte > ByteSpan
Represents a span of bytes.
Definition typedefs.hxx:140
Expected< ByteSpan, T > ExpectedByteSpan
Represents a span of bytes with error handling.
Definition typedefs.hxx:147
std::byte Byte
Represents a single byte of data.
Definition typedefs.hxx:138
Expected< std::span< const Byte >, T > ExpectedConstByteSpan
Represents a constant span of bytes with error handling.
Definition typedefs.hxx:153
Expected< const Byte &, T > ExpectedConstByteRef
Represents a reference to a constant byte with error handling.
Definition typedefs.hxx:151
Expected< Byte &, T > ExpectedByteRef
Represents a reference to a single byte with error handling.
Definition typedefs.hxx:145
Expected< const Byte, T > ExpectedConstByte
Represents a constant byte with error handling.
Definition typedefs.hxx:149
Expected< Data, T > ExpectedData
Represents a collection of bytes with error handling.
Definition typedefs.hxx:155
std::vector< Byte > Data
Represents collection of bytes stored in the buffer.
Definition typedefs.hxx:139
Status
Defines the status of the buffer during producer/consumer operations.
Definition typedefs.hxx:106
@ ReadOnly
Indicates the buffer has closed its write end.
@ Error
Indicates the buffer has encountered an error.
@ Ready
Indicates the buffer is OK and ready for operations.
std::conditional_t< is_reference< T >::value, std::expected< std::reference_wrapper< std::remove_reference_t< T > >, std::shared_ptr< E > >, std::expected< T, std::shared_ptr< E > > > Expected
Expected type with support for reference types.
Definition expected.hxx:32
Namespace for write-related utilities in the StormByte library.