3#include <StormByte/config/exception.hxx>
4#include <StormByte/config/item/type.hxx>
5#include <StormByte/clonable.hxx>
11namespace StormByte::Config::Item {
16 template<AllowedValueType T>
class Value;
23 bool STORMBYTE_CONFIG_PUBLIC IsNameValid(
const std::string&)
noexcept;
29 class STORMBYTE_CONFIG_PUBLIC
Base:
public Clonable<Base, std::shared_ptr<Base>> {
41 Base(
const std::string& name);
70 virtual ~Base() noexcept = default;
77 inline
bool operator==(const
Base& base) const noexcept {
78 return m_name == base.m_name;
87 return !operator==(base);
94 constexpr const std::optional<std::string>&
Name() const noexcept {
102 constexpr void Name(
const std::string& name)
noexcept {
111 return m_name.has_value() && Item::IsNameValid(m_name.value());
118 constexpr virtual Type
Type() const noexcept = 0;
124 constexpr std::
string TypeToString() const noexcept {
125 return Item::TypeToString(this->Type());
132 virtual std::string
Serialize(
const int& indent_level)
const noexcept;
138 operator std::string()
const {
139 return this->Serialize(0);
149 if constexpr (std::is_base_of_v<std::remove_reference_t<
decltype(*this)>, T>) {
151 return static_cast<const T&
>(*this);
152 }
else if constexpr (std::is_base_of_v<std::remove_reference_t<
decltype(*this)>,
Item::Value<T>>) {
168 return const_cast<T&
>(
static_cast<const Base&
>(*this).
Value<T>());
The base class for all configuration items.
Definition base.hxx:29
virtual ~Base() noexcept=default
Base(const std::string &name)
Constructs a Base item with an optional name.
bool operator!=(const Base &base) const noexcept
Definition base.hxx:86
Base()=default
Constructs a Base item with an optional name.
Base & operator=(const Base &base)=default
Base(Base &&base) noexcept=default
const T & Value() const
Definition base.hxx:148
bool IsNameValid() const noexcept
Definition base.hxx:110
constexpr void Name(const std::string &name) noexcept
Definition base.hxx:102
constexpr const std::optional< std::string > & Name() const noexcept
Gets the name of the item.
Definition base.hxx:94
virtual constexpr Type Type() const noexcept=0
virtual std::string Serialize(const int &indent_level) const noexcept
std::optional< std::string > m_name
Item name.
Definition base.hxx:173
Base & operator=(Base &&base) noexcept=default
T & Value()
Definition base.hxx:167
Base(const Base &base)=default
Represents a configuration item with a value.
Definition value.hxx:16
Thrown when a value is converted to an incorrect type.
Definition exception.hxx:27