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 (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
46
47#include <string_view>
48#include <utility>
49
59 template<CommentType T>
60 class STORMBYTE_CONFIG_PUBLIC Comment final: public Base {
61 public:
62 static constexpr bool CommentTag = true;
63
68 Comment(const StormByte::String::String& comment): Base(), m_text(comment) {}
69
74 Comment(StormByte::String::String&& comment): Base(), m_text(std::move(comment)) {}
75
80 Comment(const char* comment): Base(), m_text(StormByte::String::String(comment)) {}
81
86 Comment(const Comment& base) = default;
87
92 Comment(Comment&& base) noexcept = default;
93
99 Comment& operator=(const Comment& base) = default;
100
106 Comment& operator=(Comment&& base) noexcept = default;
107
111 ~Comment() noexcept override;
112
118 bool Equals(const Base& other) const noexcept override;
119
125 StormByte::String::String Serialize(const int& indent_level) const noexcept override;
126
131 constexpr Item::Type Type() const noexcept override {
132 return Item::Type::Comment;
133 }
134
140 return T;
141 }
142
147 constexpr std::string_view CommentTypeToString() const noexcept {
148 return Item::TypeToString(T);
149 }
150
156 return m_text;
157 }
158
163 const StormByte::String::String& Text() const noexcept {
164 return m_text;
165 }
166
171 PointerType Clone() const override {
172 return MakePointer<Comment<T>>(*this);
173 }
174
179 PointerType Move() override {
180 return MakePointer<Comment<T>>(std::move(*this));
181 }
182
183 private:
185 };
186
190 template<>
192
196 template<>
198
202 template<>
204
210 template<>
211 STORMBYTE_CONFIG_PUBLIC bool Comment<CommentType::SingleLineBash>::Equals(const Base& other) const noexcept;
212
218 template<>
219 STORMBYTE_CONFIG_PUBLIC bool Comment<CommentType::SingleLineC>::Equals(const Base& other) const noexcept;
220
226 template<>
227 STORMBYTE_CONFIG_PUBLIC bool Comment<CommentType::MultiLineC>::Equals(const Base& other) const noexcept;
228
234 template<>
235 STORMBYTE_CONFIG_PUBLIC StormByte::String::String Comment<CommentType::SingleLineBash>::Serialize(const int& indent_level) const noexcept;
236
242 template<>
243 STORMBYTE_CONFIG_PUBLIC StormByte::String::String Comment<CommentType::SingleLineC>::Serialize(const int& indent_level) const noexcept;
244
250 template<>
251 STORMBYTE_CONFIG_PUBLIC StormByte::String::String Comment<CommentType::MultiLineC>::Serialize(const int& indent_level) const noexcept;
252
256}
Base class for all configuration items.
Definition base.hxx:66
Comment item (#, // or /* *\/).
Definition comment.hxx:60
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 char *comment)
Constructs a Comment from a C string.
Definition comment.hxx:80
constexpr StormByte::Config::Item::CommentType CommentType() const noexcept
Gets the comment syntax.
Definition comment.hxx:139
Comment(StormByte::String::String &&comment)
Move constructor from comment string.
Definition comment.hxx:74
const StormByte::String::String & Text() const noexcept
Comment text.
Definition comment.hxx:163
PointerType Move() override
Moves the comment.
Definition comment.hxx:179
constexpr std::string_view CommentTypeToString() const noexcept
Converts comment syntax to string.
Definition comment.hxx:147
Comment(const StormByte::String::String &comment)
Constructs a Comment with the given string.
Definition comment.hxx:68
~Comment() noexcept override
Destructor.
StormByte::String::String & Text() noexcept
Comment text.
Definition comment.hxx:155
PointerType Clone() const override
Clones the comment.
Definition comment.hxx:171
All the classes for item configuration.
Configuration items (values, comments, groups, lists).
Definition hook.hxx:50
CommentType
Comment syntax used in the text document.
Definition type.hxx:91
@ SingleLineC
// until end of line
@ SingleLineBash
# until end of line
STL namespace.
#define STORMBYTE_CONFIG_PUBLIC
Definition visibility.h:53