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
24namespace StormByte::Buffer {
32 namespace Read {
47 enum class Position: unsigned short {
48 Begin = 0x01,
49 End = 0x02,
50 Relative = 0x04,
51 Absolute = 0x08
52 };
53
64 enum class Status: unsigned short {
65 Success,
66 Error
67 };
68 }
69
77 namespace Write {
88 enum class Status: unsigned short {
89 Success,
90 Error
91 };
92 }
93
105 enum class Status {
106 Ready,
107 ReadOnly,
108 Error
109 };
110
111 // Forward declarations
116 class Simple;
117
122 class Shared;
123
128 class Producer;
129
134 class Consumer;
135
136 // Data types
137 using Byte = std::byte;
138 using Data = std::vector<Byte>;
139 using ByteSpan = std::span<Byte>;
140 using ConstByteSpan = std::span<const Byte>;
141 template<class T>
142 using ExpectedByte = Expected<Byte, T>;
143 template<class T>
144 using ExpectedByteRef = Expected<Byte&, T>;
145 template<class T>
146 using ExpectedByteSpan = Expected<ByteSpan, T>;
147 template<class T>
148 using ExpectedConstByte = Expected<const Byte, T>;
149 template<class T>
150 using ExpectedConstByteRef = Expected<const Byte&, T>;
151 template<class T>
152 using ExpectedConstByteSpan = Expected<std::span<const Byte>, T>;
153 template<class T>
154 using ExpectedData = Expected<Data, T>;
155 using PipeFunction = std::function<void(Consumer, Producer)>;
156 using Processor = std::function<std::shared_ptr<Simple>(const Simple&)>;
157
172 template <typename PtrType, typename T,
173 typename = std::enable_if_t<
174 (std::is_same_v<PtrType, std::shared_ptr<typename PtrType::element_type>> ||
175 std::is_same_v<PtrType, std::unique_ptr<typename PtrType::element_type>>)
176 >
177 >
178 inline PtrType& operator<<(PtrType& ptr, const T& value) {
179 static_assert(std::is_same_v<PtrType, std::shared_ptr<typename PtrType::element_type>> ||
180 std::is_same_v<PtrType, std::unique_ptr<typename PtrType::element_type>>,
181 "PtrType must be a std::shared_ptr or std::unique_ptr");
182 if (ptr) {
183 *ptr << value; // Forward the call to the existing operator<<
184 }
185 return ptr;
186 }
187
202 template <typename PtrType, typename T,
203 typename = std::enable_if_t<
204 (std::is_same_v<PtrType, std::shared_ptr<typename PtrType::element_type>> ||
205 std::is_same_v<PtrType, std::unique_ptr<typename PtrType::element_type>>)
206 >
207 >
208 inline PtrType& operator<<(PtrType& ptr, T&& value) {
209 static_assert(std::is_same_v<PtrType, std::shared_ptr<typename PtrType::element_type>> ||
210 std::is_same_v<PtrType, std::unique_ptr<typename PtrType::element_type>>,
211 "PtrType must be a std::shared_ptr or std::unique_ptr");
212 if (ptr) {
213 *ptr << std::move(value); // Forward the call to the existing operator<<
214 }
215 return ptr;
216 }
217}
Namespace for read-related utilities in the StormByte library.
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.