StormByte-Config 3.0.0
C++26 configuration-document module of the StormByte suite
Loading...
Searching...
No Matches
value.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-Config.
5 *
6 * StormByte-Config 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-Config 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-String tree and
23 * the StormByte Base tree it vendors), which remains under its own license.
24 *
25 * Neither license grants any patent rights. Any patent licenses required
26 * to use this software or third-party components must be obtained separately
27 * from the patent holders.
28 *
29 * StormByte-Config is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU Lesser General Public License for more details.
33 *
34 * You should have received a copy of the GNU Lesser General Public License
35 * version 3 along with StormByte-Config. If not, see
36 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
37 *
38 * SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-StormByte-Commercial
39 */
40
41#pragma once
42
45#include <StormByte/safe/binary.hxx>
46#include <StormByte/safe/string.hxx>
47#include <StormByte/safe/variant.hxx>
48
49#include <string_view>
50
55namespace StormByte {
60 namespace Config {
65 namespace Item {
74 public:
79 explicit Value(int value);
80
85 explicit Value(double value);
86
91 explicit Value(bool value);
92
97 explicit Value(const char* value);
98
103 explicit Value(std::string_view value);
104
110
115 explicit Value(const StormByte::Safe::Binary& value);
116
122
128 Value(std::string_view name, int value);
129
135 Value(std::string_view name, double value);
136
142 Value(std::string_view name, bool value);
143
149 Value(std::string_view name, const char* value);
150
156 Value(std::string_view name, std::string_view value);
157
163 Value(std::string_view name, const StormByte::Safe::Binary& value);
164
170 Value(std::string_view name, StormByte::Safe::Binary&& value);
171
176 Value(const Value& value);
177
182 Value(Value&& value) noexcept;
183
187 ~Value() noexcept override;
188
194 Value& operator=(const Value& value);
195
201 Value& operator=(Value&& value) noexcept;
202
207 Item::Type Kind() const noexcept;
208
213 Item::Type Type() const noexcept override;
214
221 Value& operator=(int value);
222
229 Value& operator=(double value);
230
237 Value& operator=(bool value);
238
245 Value& operator=(const char* value);
246
253 Value& operator=(std::string_view value);
254
261 Value& operator=(const StormByte::Safe::Binary& value);
262
268 operator int&();
269
275 operator const int&() const;
276
282 operator double() const;
283
289 operator double&();
290
296 operator bool&();
297
303 operator const bool&() const;
304
310 operator StormByte::Safe::String&();
311
317 operator const StormByte::Safe::String&() const;
318
324 operator StormByte::Safe::Binary&();
325
331 operator const StormByte::Safe::Binary&() const;
332
337 PointerType Clone() const override;
338
343 PointerType Move() override;
344
350 StormByte::Safe::String Serialize(const int& indent_level) const override;
351
352 protected:
358 bool Equals(const Base& base) const override;
359
360 private:
361 using Payload = StormByte::Safe::Variant<int, double, bool, StormByte::Safe::String, StormByte::Safe::Binary>;
362
363 Payload m_store;
364
369 [[noreturn]] void Fail(const char* wanted) const;
370 };
371 }
372 }
373}
374
375#include <StormByte/config/item/base.txx>
376
Base() noexcept
Constructor.
Scalar configuration item.
Definition value.hxx:73
Value(int value)
Integer payload.
Value(std::string_view name, int value)
Named integer.
Value(std::string_view name, double value)
Named double.
Value(Value &&value) noexcept
Move constructor.
Value(std::string_view value)
Text payload from a view.
Item::Type Kind() const noexcept
Payload kind.
Value(const Value &value)
Copy constructor.
Value(const StormByte::Safe::Binary &value)
Byte payload.
StormByte::Safe::String Serialize(const int &indent_level) const override
Text form of this item.
Value(std::string_view name, bool value)
Named bool.
~Value() noexcept override
Destructor.
Value(std::string_view name, const StormByte::Safe::Binary &value)
Named bytes.
Value(std::string_view name, std::string_view value)
Named text.
PointerType Clone() const override
Clone onto the Config heap.
Value(const char *value)
Text payload from a C string.
PointerType Move() override
Move onto the Config heap.
Value(std::string_view name, StormByte::Safe::Binary &&value)
Named bytes.
Value(StormByte::Safe::Binary &&value)
Byte payload.
bool Equals(const Base &base) const override
Compare payloads after the base has matched the type.
Value(StormByte::Safe::String &&value)
Text payload.
Value(bool value)
Bool payload.
Value(double value)
Double payload.
Value(std::string_view name, const char *value)
Named text from a C string.
STORMBYTE_DECLARE_MAYBE_SAFE(StormByte::Config::Config)
All the classes for item configuration.
Configuration document items.
Definition base.hxx:55
Config module of the StormByte suite.
Definition alias.hxx:51
Root namespace of the StormByte suite.
STL namespace.
Tag for As<Binary>() → StormByte::Safe::Binary.
Definition type.hxx:151
#define STORMBYTE_CONFIG_PUBLIC
Definition visibility.h:53