3#include <StormByte/config/item/base.hxx>
9namespace StormByte::Config::Item {
15 template<AllowedValueType T>
25 template <
typename U = T>
26 Value(
const char* value)
requires std::is_same_v<U, std::string>
27 :
Base(), m_value(std::string(value)) {}
30 template <
typename U = T>
31 Value(
const char* name,
const char* value)
requires std::is_same_v<U, std::string>
32 : Base(std::string(name)), m_value(std::string(value)) {}
38 Value(T&& value):
Base(), m_value(std::move(value)) {}
45 Value(
const std::string& name,
const T& value):
Base(name), m_value(value) {}
52 Value(std::string&& name, T&& value):
Base(std::move(name)), m_value(std::move(value)) {}
59 Value(
const std::string& name,
const char* value)
requires std::is_same_v<T, std::string>
60 :
Base(name), m_value(std::string(value)) {}
67 Value(std::string&& name,
const char* value)
requires std::is_same_v<T, std::string>
68 :
Base(std::move(name)), m_value(std::string(value)) {}
97 virtual ~Value() noexcept override = default;
103 constexpr virtual
Item::Type Type() const noexcept
override {
104 if constexpr (std::is_same_v<T, std::string>) {
105 return Item::Type::String;
106 }
else if constexpr (std::is_same_v<T, int>) {
107 return Item::Type::Integer;
108 }
else if constexpr (std::is_same_v<T, double>) {
109 return Item::Type::Double;
110 }
else if constexpr (std::is_same_v<T, bool>)
111 return Item::Type::Bool;
121 if (Base::operator!=(single))
return false;
124 if constexpr (!std::is_same_v<T,
decltype(m_value)>) {
129 return m_value == single.m_value;
138 return !operator==(single);
162 std::string
Serialize(
const int& indent_level)
const noexcept override;
168 virtual PointerType
Clone()
const override {
169 return MakePointer<Value<T>>(*this);
176 virtual PointerType
Move()
override {
177 return MakePointer<Value<T>>(std::move(*
this));
The base class for all configuration items.
Definition base.hxx:29
Represents a configuration item with a value.
Definition value.hxx:16
const T & operator*() const noexcept
Definition value.hxx:153
virtual PointerType Move() override
Definition value.hxx:176
Value(const std::string &name, const T &value)
Definition value.hxx:45
T & operator*() noexcept
Definition value.hxx:145
virtual ~Value() noexcept override=default
Value(const std::string &name, const char *value)
Definition value.hxx:59
Value(std::string &&name, const char *value)
Definition value.hxx:67
Value(T &&value)
Definition value.hxx:38
Value(const Value &single)=default
T m_value
The value of the item.
Definition value.hxx:181
Value(Value &&single) noexcept=default
Value & operator=(Value &&single) noexcept=default
Value(const T &value)
Constructs a Value with the given value.
Definition value.hxx:22
bool operator==(const Value< T > &single) const noexcept
Checks if two Value objects are equal.
Definition value.hxx:119
virtual PointerType Clone() const override
Definition value.hxx:168
Value(std::string &&name, T &&value)
Definition value.hxx:52
Value & operator=(const Value &single)=default
std::string Serialize(const int &indent_level) const noexcept override
Serializes the item to a string.
bool operator!=(const Value< T > &single) const noexcept
Definition value.hxx:137
All the configuration item classes namespace.