22#include <StormByte/config/exception.hxx>
23#include <StormByte/config/item/type.hxx>
24#include <StormByte/clonable.hxx>
37 template<AllowedValueType T>
class Value;
38 bool STORMBYTE_CONFIG_PUBLIC IsNameValid(
const std::string&)
noexcept;
44 class STORMBYTE_CONFIG_PUBLIC
Base:
public Clonable<Base, std::shared_ptr<Base>> {
55 Base(
const std::string& name);
86 virtual ~Base() noexcept = default;
93 bool operator==(const
Base& other) const noexcept {
94 return this->Equals(other);
103 return !(*
this == other);
117 constexpr const std::optional<std::string>&
Name() const noexcept {
125 constexpr void Name(
const std::string& name)
noexcept {
134 return m_name.has_value() && Item::IsNameValid(m_name.value());
151 virtual std::optional<CommentType> GetCommentType() const noexcept {
160 return Item::TypeToString(this->
Type());
168 virtual std::string
Serialize(
const int& indent_level)
const noexcept;
174 operator std::string()
const {
175 return this->Serialize(0);
186 if constexpr (std::is_base_of_v<std::remove_reference_t<
decltype(*this)>, T>) {
187 return static_cast<const T&
>(*this);
188 }
else if constexpr (std::is_base_of_v<std::remove_reference_t<
decltype(*this)>,
Item::Value<T>>) {
203 return const_cast<T&
>(
static_cast<const Base&
>(*this).
Value<T>());
The base class for all configuration items.
Definition base.hxx:44
virtual ~Base() noexcept=default
Destructor.
virtual bool Equals(const Base &other) const noexcept=0
Polymorphic equality comparison.
Base(const std::string &name)
Constructs a Base item with a name.
Base()=default
Default constructor.
Base & operator=(const Base &base)=default
Copy assignment operator.
Base(Base &&base) noexcept=default
Move constructor.
const T & Value() const
Gets the item value (const).
Definition base.hxx:185
bool IsNameValid() const noexcept
Checks if the current name is valid.
Definition base.hxx:133
constexpr std::string TypeToString() const noexcept
Gets the item type as a string.
Definition base.hxx:159
constexpr void Name(const std::string &name) noexcept
Sets the item name.
Definition base.hxx:125
constexpr const std::optional< std::string > & Name() const noexcept
Gets the name of the item.
Definition base.hxx:117
virtual constexpr Type Type() const noexcept=0
Gets the item type.
virtual std::string Serialize(const int &indent_level) const noexcept
Serializes the item.
std::optional< std::string > m_name
Item name.
Definition base.hxx:207
bool operator!=(const Base &other) const noexcept
Inequality operator.
Definition base.hxx:102
Base & operator=(Base &&base) noexcept=default
Move assignment operator.
T & Value()
Gets the item value (mutable).
Definition base.hxx:202
Base(const Base &base)=default
Copy constructor.
Named or unnamed typed value.
Definition value.hxx:37
Thrown when a value is converted to an incorrect type.
Definition exception.hxx:45
Configuration items (values, comments, groups, lists).
Definition alias.hxx:30
enum STORMBYTE_CONFIG_PUBLIC List
< List of unnamed items
Definition type.hxx:98
Type
Represents the type of a configuration item.
Definition type.hxx:39
@ Container
Container item.
constexpr STORMBYTE_CONFIG_PUBLIC std::string TypeToString(const CommentType &t) noexcept
Converts a CommentType to a human-readable string.
Definition type.hxx:82