StormByte-Config 2.0.0
C++26 configuration-document module of the StormByte suite
 
Loading...
Searching...
No Matches
base.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. The bundled StormByte Base tree
22 * under thirdparty/ remains under its own license.
23 *
24 * Neither license grants any patent rights. Any patent licenses required
25 * to use this software or third-party components must be obtained separately
26 * from the patent holders.
27 *
28 * StormByte-Config is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU Lesser General Public License for more details.
32 *
33 * You should have received a copy of the GNU Lesser General Public License
34 * version 3 along with StormByte-Config. If not, see
35 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
36 *
37 * SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-StormByte-Commercial
38 */
39
40#pragma once
41
47
48#include <string_view>
49
55 class Container;
56 class Group;
57 class List;
58 class Value;
59 template<CommentType T> class Comment;
60
65 class STORMBYTE_CONFIG_PUBLIC Base: public StormByte::Safe::Clonable<Base, StormByte::Safe::Shared<Base>> {
66 public:
70 Base() noexcept;
71
76 Base(const StormByte::Safe::String& name);
77
82 Base(const Base& base) noexcept = default;
83
88 Base(Base&& base) noexcept = default;
89
95 Base& operator=(const Base& base) noexcept = default;
96
102 Base& operator=(Base&& base) noexcept = default;
103
107 ~Base() noexcept override;
108
114 bool operator==(const Base& base) const noexcept;
115
121 bool operator!=(const Base& base) const noexcept;
122
127 constexpr const StormByte::Safe::String& Name() const noexcept {
128 return m_name;
129 }
130
135 constexpr void Name(const StormByte::Safe::String& name) {
136 m_name = name;
137 }
138
143 void Name(std::string_view name);
144
149 constexpr virtual Item::Type Type() const noexcept = 0;
150
155 constexpr std::string_view TypeToString() const noexcept {
156 return Item::TypeToString(this->Type());
157 }
158
164 static bool IsNameValid(const StormByte::Safe::String& name) noexcept;
165
171 static bool IsNameValid(std::string_view name) noexcept;
172
178 template<class T> decltype(auto) As();
179
185 template<class T> decltype(auto) As() const;
186
192 virtual StormByte::Safe::String Serialize(const int& indent_level = 0) const;
193
194 protected:
196
202 virtual bool Equals(const Base& base) const = 0;
203 };
204}
Base class for all configuration items.
Definition base.hxx:65
constexpr void Name(const StormByte::Safe::String &name)
Sets the name of the item.
Definition base.hxx:135
virtual bool Equals(const Base &base) const =0
Equals.
decltype(auto) As()
Typed view of this item.
Base() noexcept
Constructor.
static bool IsNameValid(const StormByte::Safe::String &name) noexcept
Checks if name is valid.
static bool IsNameValid(std::string_view name) noexcept
Checks if name is valid.
decltype(auto) As() const
Typed view of this item.
StormByte::Safe::String m_name
Name of the item.
Definition base.hxx:195
void Name(std::string_view name)
Sets the name of the item.
virtual constexpr Item::Type Type() const noexcept=0
Gets the type of the item.
virtual StormByte::Safe::String Serialize(const int &indent_level=0) const
Serializes the item as text.
Configuration items (values, comments, groups, lists).
Definition hook.hxx:49
Type
Node kind in the document tree.
Definition type.hxx:56
@ Value
Any leaf (Value node). Not used on the wire.
STL namespace.
#define STORMBYTE_CONFIG_PUBLIC
Definition visibility.h:52