StormByte-Config 3.0.0
C++26 configuration-document module of the StormByte suite
Loading...
Searching...
No Matches
comment.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/string.hxx>
46
47#include <string_view>
48#include <utility>
49
54namespace StormByte {
59 namespace Config {
64 namespace Item {
70 template<CommentType T>
71 class STORMBYTE_CONFIG_PUBLIC Comment final: public Base {
72 public:
73 static constexpr bool CommentTag = true;
74
80
86
91 Comment(const char* comment);
92
97 Comment(const Comment& comment);
98
103 Comment(Comment&& comment) noexcept;
104
110 Comment& operator=(const Comment& comment);
111
117 Comment& operator=(Comment&& comment) noexcept;
118
122 ~Comment() noexcept override;
123
129 bool Equals(const Base& other) const noexcept override;
130
136 StormByte::Safe::String Serialize(const int& indent_level) const noexcept override;
137
142 constexpr Item::Type Type() const noexcept override {
143 return Item::Type::Comment;
144 }
145
151 return T;
152 }
153
158 STORMBYTE_FORCE_INLINE constexpr std::string_view CommentTypeToString() const noexcept {
159 return Item::TypeToString(T);
160 }
161
167 return m_text;
168 }
169
174 const StormByte::Safe::String& Text() const noexcept {
175 return m_text;
176 }
177
182 PointerType Clone() const override;
183
188 PointerType Move() override;
189
190 private:
192 };
193
197 template<>
199
203 template<>
205
209 template<>
211
217 template<>
219
225 template<>
226 STORMBYTE_CONFIG_PUBLIC bool Comment<CommentType::SingleLineC>::Equals(const Base& other) const noexcept;
227
233 template<>
234 STORMBYTE_CONFIG_PUBLIC bool Comment<CommentType::MultiLineC>::Equals(const Base& other) const noexcept;
235
241 template<>
243
249 template<>
251
257 template<>
259
263 }
264 }
265}
266
Base() noexcept
Constructor.
Comment(StormByte::Safe::String &&comment)
Constructs a Comment by moving a Base-owned string.
bool Equals(const Base &other) const noexcept override
Polymorphic equality comparison.
StormByte::Safe::String Serialize(const int &indent_level) const noexcept override
Serializes the comment item.
Comment(Comment &&comment) noexcept
Move constructor.
Comment(const StormByte::Safe::String &comment)
Constructs a Comment with a Base-owned string.
const StormByte::Safe::String & Text() const noexcept
Gets const comment text.
Definition comment.hxx:174
Comment & operator=(Comment &&comment) noexcept
Move assignment operator.
Comment(const char *comment)
Constructs a Comment from a NUL-terminated string.
constexpr StormByte::Config::Item::CommentType CommentType() const noexcept
Gets the comment syntax.
Definition comment.hxx:150
static constexpr bool CommentTag
Identifies this as a comment item.
Definition comment.hxx:73
PointerType Move() override
Moves the comment to Base's heap.
Comment & operator=(const Comment &comment)
Copy assignment operator.
constexpr std::string_view CommentTypeToString() const noexcept
Converts comment syntax to its text representation.
Definition comment.hxx:158
~Comment() noexcept override
Destructor, defined in the Config module.
Comment(const Comment &comment)
Copy constructor.
PointerType Clone() const override
Clones the comment on Base's heap.
StormByte::Safe::String & Text() noexcept
Gets mutable comment text.
Definition comment.hxx:166
STORMBYTE_DECLARE_MAYBE_SAFE(StormByte::Config::Config)
All the classes for item configuration.
Configuration document items.
Definition base.hxx:55
@ Comment
Comment node.
Definition type.hxx:59
@ String
Text leaf (StormByte::Safe::String).
Definition type.hxx:63
static constexpr std::string_view TypeToString(const Type &t) noexcept
Converts a Type to its string representation.
Definition type.hxx:73
CommentType
Comment syntax used in the text document.
Definition type.hxx:91
@ SingleLineC
// until end of line
Definition type.hxx:93
@ MultiLineC
/* … */
Definition type.hxx:94
@ SingleLineBash
# until end of line
Definition type.hxx:92
Config module of the StormByte suite.
Definition alias.hxx:51
Root namespace of the StormByte suite.
#define STORMBYTE_FORCE_INLINE
#define STORMBYTE_CONFIG_PUBLIC
Definition visibility.h:53