StormByte C++ Library: Config module 1.0.1.9999
StormByte-Config is the configuration module of the StormByte C++ suite.
Loading...
Searching...
No Matches
comment.hxx
1/*
2 * Copyright (C) 2024-2026 David C. Manuelda (StormBytePP)
3 *
4 * This file is part of StormByte-Config.
5 *
6 * StormByte-Config is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License version 3
8 * or later, as published by the Free Software Foundation.
9 *
10 * StormByte-Config is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with StormByte-Config. If not, see
17 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
18 */
19
20#pragma once
21
22#include <StormByte/config/item/value.hxx>
23
24#include <string>
25
35 template<CommentType T>
36 class STORMBYTE_CONFIG_PUBLIC Comment final: public Value<std::string> {
37 public:
46 Comment(const std::string& comment): Value<std::string>(comment) {}
47
52 Comment(std::string&& comment): Value<std::string>(std::move(comment)) {}
53
58 Comment(const Comment& base) = default;
59
64 Comment(Comment&& base) = default;
65
71 Comment& operator=(const Comment& base) = default;
72
78 Comment& operator=(Comment&& base) = default;
79
83 ~Comment() noexcept override = default;
95 bool Equals(const Base& other) const noexcept override {
96 if (this->Type() != other.Type())
97 return false;
98 if (this->Name() != other.Name())
99 return false;
100
101 auto other_comment_type = other.GetCommentType();
102 if (!other_comment_type || *other_comment_type != T)
103 return false;
104
105 const Comment<T>& other_comment = static_cast<const Comment<T>&>(other);
106 return **this == *other_comment;
107 }
108
114 std::string Serialize(const int& indent_level) const noexcept override;
115
120 constexpr Item::Type Type() const noexcept override {
121 return Type::Comment;
122 }
123
128 std::optional<CommentType> GetCommentType() const noexcept override {
129 return T;
130 }
131
137 return T;
138 }
139
144 constexpr std::string CommentTypeToString() const noexcept {
145 return Item::TypeToString(T);
146 }
147
152 PointerType Clone() const override {
153 return MakePointer<Comment<T>>(*this);
154 }
155
160 PointerType Move() override {
161 return MakePointer<Comment<T>>(std::move(*this));
162 }
164 };
165}
The base class for all configuration items.
Definition base.hxx:44
Comment item (#, // or /* *\/).
Definition comment.hxx:36
std::optional< CommentType > GetCommentType() const noexcept override
Returns the concrete comment type of this Comment specialization.
Definition comment.hxx:128
Comment(const std::string &comment)
Constructs a Comment with the given string.
Definition comment.hxx:46
Comment(Comment &&base)=default
Move constructor.
Comment & operator=(const Comment &base)=default
Copy assignment operator.
Comment(const Comment &base)=default
Copy constructor.
std::string Serialize(const int &indent_level) const noexcept override
Serializes the comment item.
~Comment() noexcept override=default
Destructor.
constexpr Item::Type Type() const noexcept override
Gets the item type.
Definition comment.hxx:120
constexpr std::string CommentTypeToString() const noexcept
Converts comment syntax to string.
Definition comment.hxx:144
constexpr StormByte::Config::Item::CommentType CommentType() const noexcept
Gets the comment syntax.
Definition comment.hxx:136
Comment(std::string &&comment)
Move constructor from comment string.
Definition comment.hxx:52
PointerType Move() override
Moves the comment.
Definition comment.hxx:160
Comment & operator=(Comment &&base)=default
Move assignment operator.
PointerType Clone() const override
Clones the comment.
Definition comment.hxx:152
Named or unnamed typed value.
Definition value.hxx:37
Configuration items (values, comments, groups, lists).
Definition alias.hxx:30
enum STORMBYTE_CONFIG_PUBLIC CommentType
# until end of line
Definition type.hxx:71
Type
Represents the type of a configuration item.
Definition type.hxx:39