StormByte-Buffer 4.0.0
C++26 buffer module of the StormByte suite
Loading...
Searching...
No Matches
exception.hxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024-2026 David C. Manuelda (StormBytePP)
3 *
4 * This file is part of StormByte-Buffer.
5 *
6 * StormByte-Buffer original source is dual-licensed:
7 *
8 * 1. GNU Lesser General Public License v3.0 (or later)
9 * You may redistribute and/or modify this file under the terms of the
10 * GNU Lesser General Public License as published by the Free Software
11 * Foundation, either version 3 of the License, or (at your option)
12 * any later version.
13 *
14 * 2. Commercial license
15 * Alternatively, this file may be used under the terms of a commercial
16 * license agreement with the copyright holder
17 * (David C. Manuelda <StormByte@gmail.com>).
18 *
19 * Both licenses apply only to original StormByte-Buffer source in this
20 * repository. They do not cover other StormByte modules or any third-party
21 * material shipped with this repository (including everything under
22 * thirdparty/, and in particular the bundled StormByte-Logger tree and
23 * the rest of the StormByte suite it vendors), which remains under its own
24 * license.
25 *
26 * Neither license grants any patent rights. Any patent licenses required
27 * to use this software or third-party components must be obtained separately
28 * from the patent holders.
29 *
30 * StormByte-Buffer is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU Lesser General Public License for more details.
34 *
35 * You should have received a copy of the GNU Lesser General Public License
36 * version 3 along with StormByte-Buffer. If not, see
37 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
38 *
39 * SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-StormByte-Commercial
40 */
41
42#pragma once
43
44#include <StormByte/type_traits/safe.hxx>
45
47#include <StormByte/exception.hxx>
48#include <StormByte/safe/string.hxx>
49
50#include <string_view>
51#include <utility>
52
57namespace StormByte {
62 namespace Buffer {
76 public:
81 struct Path {
82 std::string_view segments;
83
88 explicit constexpr Path(std::string_view segments) noexcept: segments(segments) {}
89 };
90
97 template <typename... Args>
98 requires (sizeof...(Args) >= 1)
99 explicit Exception(std::string_view pattern, Args&&... args)
100 : StormByte::Exception(StormByte::Exception::Path{"Buffer"}, pattern, std::forward<Args>(args)...) {}
101
106 explicit Exception(std::string_view message);
107
112 Exception(const Exception& other);
113
118 Exception(Exception&& other) noexcept;
119
126
132 Exception& operator=(Exception&& other) noexcept;
133
137 ~Exception() noexcept override;
138
139 protected:
145 Exception(Path path, std::string_view message);
146
154 template <typename... Args>
155 requires (sizeof...(Args) >= 1)
156 Exception(Path path, std::string_view pattern, Args&&... args)
157 : Exception(path, static_cast<std::string_view>(StormByte::Safe::String::ReplaceToken(pattern, std::forward<Args>(args)...))) {}
158 };
159
167 public:
172
177 Error(const Error& other);
178
183 Error(Error&& other) noexcept;
184
190 Error& operator=(const Error& other);
191
197 Error& operator=(Error&& other) noexcept;
198
202 ~Error() noexcept override;
203 };
204
210 public:
217 template <typename... Args>
218 requires (sizeof...(Args) >= 1)
219 explicit ReadError(std::string_view pattern, Args&&... args)
220 : Error(Path{"Read"}, pattern, std::forward<Args>(args)...) {}
221
226 explicit ReadError(std::string_view message);
227
232 ReadError(const ReadError& other);
233
238 ReadError(ReadError&& other) noexcept;
239
246
252 ReadError& operator=(ReadError&& other) noexcept;
253
257 ~ReadError() noexcept override;
258 };
259
265 public:
272 template <typename... Args>
273 requires (sizeof...(Args) >= 1)
274 explicit WriteError(std::string_view pattern, Args&&... args)
275 : Error(Path{"Write"}, pattern, std::forward<Args>(args)...) {}
276
281 explicit WriteError(std::string_view message);
282
287 WriteError(const WriteError& other);
288
293 WriteError(WriteError&& other) noexcept;
294
301
307 WriteError& operator=(WriteError&& other) noexcept;
308
312 ~WriteError() noexcept override;
313 };
314 }
315}
316
Error & operator=(const Error &other)
Copy the message through the Base storage provider.
Error(const Error &other)
Copy the message through the Base storage provider.
Error(Error &&other) noexcept
Transfer Base-owned message storage.
~Error() noexcept override
Destroy the error.
Error & operator=(Error &&other) noexcept
Transfer Base-owned message storage.
Exception(std::string_view pattern, Args &&... args)
Inherit the Buffer message constructors without adding a segment.
Definition exception.hxx:99
Exception & operator=(Exception &&other) noexcept
Transfer Base-owned message storage without allocating.
Exception(const Exception &other)
Copy Base-owned message storage through its provider.
Exception(std::string_view message)
Copy a borrowed plain message under StormByte.Buffer in the provider.
Exception(Exception &&other) noexcept
Transfer Base-owned message storage without allocating.
~Exception() noexcept override
Destroy the exception.
Exception & operator=(const Exception &other)
Copy Base-owned message storage through its provider.
Exception(std::string_view pattern, Args &&... args)
Replace literal {} under StormByte.Buffer.
Definition exception.hxx:99
ReadError & operator=(ReadError &&other) noexcept
Transfer Base-owned message storage.
ReadError(ReadError &&other) noexcept
Transfer Base-owned message storage.
~ReadError() noexcept override
Destroy the error.
ReadError(std::string_view message)
Copy a borrowed plain message under StormByte.Buffer.Read in the provider.
ReadError & operator=(const ReadError &other)
Copy the message through the Base storage provider.
ReadError(const ReadError &other)
Copy the message through the Base storage provider.
ReadError(std::string_view pattern, Args &&... args)
Replace literal {} under StormByte.Buffer.Read.
Definition exception.hxx:219
WriteError(const WriteError &other)
Copy the message through the Base storage provider.
WriteError(WriteError &&other) noexcept
Transfer Base-owned message storage.
WriteError(std::string_view message)
Copy a borrowed plain message under StormByte.Buffer.Write in the provider.
WriteError & operator=(const WriteError &other)
Copy the message through the Base storage provider.
~WriteError() noexcept override
Destroy the error.
WriteError & operator=(WriteError &&other) noexcept
Transfer Base-owned message storage.
WriteError(std::string_view pattern, Args &&... args)
Replace literal {} under StormByte.Buffer.Write.
Definition exception.hxx:274
STORMBYTE_DECLARE_MAYBE_SAFE(class StormByte::System::Device::Access)
Buffer module of the StormByte suite.
Root namespace of the StormByte C++ suite.
STL namespace.
Additional path segments nested below StormByte.Buffer.
Definition exception.hxx:81
std::string_view segments
Additional dotted path segments.
Definition exception.hxx:82
constexpr Path(std::string_view segments) noexcept
Wraps additional path segments.
Definition exception.hxx:88
#define STORMBYTE_BUFFER_PUBLIC
Definition visibility.h:54