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
simple.hxx
1#pragma once
2
3#include <StormByte/buffer/exception.hxx>
4#include <StormByte/buffer/typedefs.hxx>
5#include <StormByte/visibility.h>
6
20namespace StormByte::Buffer {
36 class STORMBYTE_PUBLIC Simple {
37 public:
42 Simple() noexcept;
43
48 explicit Simple(const std::size_t& size);
49
56 Simple(const char* data, const std::size_t& length);
57
62 Simple(const std::string& data);
63
68 Simple(const Data& data);
69
74 Simple(Data&& data);
75
80 Simple(const std::span<const Byte>& data);
81
86 Simple(const Simple& other) = default;
87
92 Simple(Simple&& other) noexcept = default;
93
98 virtual ~Simple() noexcept = default;
99
105 Simple& operator=(const Simple& other) = default;
106
112 Simple& operator=(Simple&& other) noexcept = default;
113
120 virtual Simple& operator<<(const Data& data);
121
127 virtual Simple& operator<<(Data&& data);
128
134 virtual Simple& operator<<(const Simple& buffer);
135
141 virtual Simple& operator<<(Simple&& buffer);
142
148 virtual Simple& operator<<(const std::string& data);
149
161 template <typename NumericType, typename = std::enable_if_t<std::is_arithmetic_v<std::decay_t<NumericType>>>>
162 Simple& operator<<(const NumericType& value) {
163 const auto* raw_data = reinterpret_cast<const std::byte*>(&value);
164 m_data.insert(m_data.end(), raw_data, raw_data + sizeof(NumericType));
165 return *this;
166 }
167
173 virtual Simple& operator>>(Simple& buffer);
174
179 virtual size_t AvailableBytes() const noexcept;
180
185 virtual size_t Capacity() const noexcept;
186
191 virtual void Clear();
192
202 virtual Buffer::Data Data() const noexcept;
203
216 virtual void Discard(const std::size_t& length, const Read::Position& mode = Read::Position::Relative) noexcept;
217
222 virtual bool Empty() const noexcept;
223
228 virtual bool End() const noexcept;
229
236 virtual ExpectedData<BufferOverflow> Extract(const size_t& length);
237
250 virtual Read::Status ExtractInto(const size_t& length, Simple& output) noexcept;
251
257 virtual bool HasEnoughData(const std::size_t& length);
258
268 virtual std::string HexData(const std::size_t& column_size = 16) const;
269
274 virtual bool IsEoF() const noexcept;
275
286 virtual ExpectedByte<BufferOverflow> Peek() const;
287
292 virtual std::size_t Position() const noexcept;
293
310 Read::Status Process(const std::size_t& length, Processor function, Simple& output) noexcept;
311
324 virtual ExpectedData<BufferOverflow> Read(const size_t& length) const;
325
331 virtual void Reserve(const std::size_t& size);
332
338 virtual void Seek(const std::ptrdiff_t& position, const Read::Position& mode) const;
339
344 virtual std::size_t Size() const noexcept;
345
356 const std::span<const Byte> Span() const noexcept;
357
368 std::span<Byte> Span() noexcept;
369
378 virtual Write::Status Write(const Buffer::Data& data);
379
388 virtual Write::Status Write(Buffer::Data&& data);
389
398 virtual Write::Status Write(const Simple& buffer);
399
408 virtual Write::Status Write(Simple&& buffer);
409
418 virtual Write::Status Write(const std::string& data);
419
420 protected:
421 std::vector<std::byte> m_data;
422 mutable std::size_t m_position;
423 mutable std::size_t m_minimum_chunk_size;
424 };
425}
Exception class for buffer overflow errors.
Definition exception.hxx:48
A lightweight class for storing and manipulating simple byte buffers.
Definition simple.hxx:36
virtual Simple & operator>>(Simple &buffer)
Appends current simple buffer to target simple buffer.
virtual size_t AvailableBytes() const noexcept
Gets the available bytes to read from current position.
Simple() noexcept
Default constructor Initializes an empty simple buffer.
Namespace for buffer-related components in the StormByte library.
Namespace for read-related utilities in the StormByte library.
Namespace for buffer-related components in the StormByte library.
Definition consumer.hxx:19
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::byte Byte
Represents a single byte of data.
Definition typedefs.hxx:138
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
Namespace for write-related utilities in the StormByte library.