StormByte-Config 2.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. 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
45
46#include <string_view>
47#include <utility>
48
58 template<CommentType T>
59 class STORMBYTE_CONFIG_PUBLIC Comment final: public Base {
60 public:
61 static constexpr bool CommentTag = true;
62
67 Comment(const StormByte::Safe::String& comment): Base(), m_text(comment) {}
68
73 Comment(StormByte::Safe::String&& comment): Base(), m_text(std::move(comment)) {}
74
79 Comment(const char* comment): Base(), m_text(StormByte::Safe::String(comment)) {}
80
85 Comment(const Comment& base) = default;
86
91 Comment(Comment&& base) noexcept = default;
92
98 Comment& operator=(const Comment& base) = default;
99
105 Comment& operator=(Comment&& base) noexcept = default;
106
110 ~Comment() noexcept override;
111
117 bool Equals(const Base& other) const noexcept override;
118
124 StormByte::Safe::String Serialize(const int& indent_level) const noexcept override;
125
130 constexpr Item::Type Type() const noexcept override {
131 return Item::Type::Comment;
132 }
133
139 return T;
140 }
141
146 constexpr std::string_view CommentTypeToString() const noexcept {
147 return Item::TypeToString(T);
148 }
149
155 return m_text;
156 }
157
162 const StormByte::Safe::String& Text() const noexcept {
163 return m_text;
164 }
165
170 PointerType Clone() const override {
171 return MakePointer<Comment<T>>(*this);
172 }
173
178 PointerType Move() override {
179 return MakePointer<Comment<T>>(std::move(*this));
180 }
181
182 private:
184 };
185
189 template<>
191
195 template<>
197
201 template<>
203
209 template<>
210 STORMBYTE_CONFIG_PUBLIC bool Comment<CommentType::SingleLineBash>::Equals(const Base& other) const noexcept;
211
217 template<>
218 STORMBYTE_CONFIG_PUBLIC bool Comment<CommentType::SingleLineC>::Equals(const Base& other) const noexcept;
219
225 template<>
226 STORMBYTE_CONFIG_PUBLIC bool Comment<CommentType::MultiLineC>::Equals(const Base& other) const noexcept;
227
233 template<>
234 STORMBYTE_CONFIG_PUBLIC StormByte::Safe::String Comment<CommentType::SingleLineBash>::Serialize(const int& indent_level) const noexcept;
235
241 template<>
242 STORMBYTE_CONFIG_PUBLIC StormByte::Safe::String Comment<CommentType::SingleLineC>::Serialize(const int& indent_level) const noexcept;
243
249 template<>
250 STORMBYTE_CONFIG_PUBLIC StormByte::Safe::String Comment<CommentType::MultiLineC>::Serialize(const int& indent_level) const noexcept;
251
255}
Base class for all configuration items.
Definition base.hxx:65
Comment item (#, // or /* *\/).
Definition comment.hxx:59
Comment(StormByte::Safe::String &&comment)
Move constructor from comment string.
Definition comment.hxx:73
Comment(Comment &&base) noexcept=default
Move constructor.
Comment & operator=(Comment &&base) noexcept=default
Move assignment operator.
Comment & operator=(const Comment &base)=default
Copy assignment operator.
Comment(const Comment &base)=default
Copy constructor.
Comment(const StormByte::Safe::String &comment)
Constructs a Comment with the given string.
Definition comment.hxx:67
const StormByte::Safe::String & Text() const noexcept
Comment text.
Definition comment.hxx:162
Comment(const char *comment)
Constructs a Comment from a C string.
Definition comment.hxx:79
constexpr StormByte::Config::Item::CommentType CommentType() const noexcept
Gets the comment syntax.
Definition comment.hxx:138
PointerType Move() override
Moves the comment.
Definition comment.hxx:178
constexpr std::string_view CommentTypeToString() const noexcept
Converts comment syntax to string.
Definition comment.hxx:146
~Comment() noexcept override
Destructor.
PointerType Clone() const override
Clones the comment.
Definition comment.hxx:170
StormByte::Safe::String & Text() noexcept
Comment text.
Definition comment.hxx:154
All the classes for item configuration.
Configuration items (values, comments, groups, lists).
Definition hook.hxx:49
@ String
Text leaf (StormByte::Safe::String).
CommentType
Comment syntax used in the text document.
Definition type.hxx:90
@ SingleLineC
// until end of line
@ SingleLineBash
# until end of line
STL namespace.
#define STORMBYTE_CONFIG_PUBLIC
Definition visibility.h:52