22#include <StormByte/config/item/base.hxx>
36 template<AllowedValueType T>
53 template <
typename U = T>
54 Value(
const char* value)
requires std::is_same_v<U, std::string>
55 :
Base(), m_value(std::string(value)) {}
62 template <
typename U = T>
63 Value(
const char* name,
const char* value)
requires std::is_same_v<U, std::string>
64 :
Base(std::string(name)), m_value(std::string(value)) {}
70 Value(T&& value):
Base(), m_value(std::move(value)) {}
77 Value(
const std::string& name,
const T& value):
Base(name), m_value(value) {}
84 Value(std::string&& name, T&& value):
Base(std::move(name)), m_value(std::move(value)) {}
91 Value(
const std::string& name,
const char* value)
requires std::is_same_v<T, std::string>
92 :
Base(name), m_value(std::string(value)) {}
99 Value(std::string&& name,
const char* value)
requires std::is_same_v<T, std::string>
100 :
Base(std::move(name)), m_value(std::string(value)) {}
131 virtual ~Value() noexcept override = default;
143 bool Equals(const
Base& other) const noexcept
override {
144 if (this->
Type() != other.Type())
146 if (this->Name() != other.Name())
149 return m_value == other_value.
m_value;
157 if constexpr (std::is_same_v<T, std::string>) {
158 return Item::Type::String;
159 }
else if constexpr (std::is_same_v<T, int>) {
160 return Item::Type::Integer;
161 }
else if constexpr (std::is_same_v<T, double>) {
162 return Item::Type::Double;
163 }
else if constexpr (std::is_same_v<T, bool>) {
164 return Item::Type::Bool;
165 }
else if constexpr (std::is_same_v<T, std::vector<std::byte>>) {
166 return Item::Type::Binary;
176 return Equals(single);
185 return !operator==(single);
209 std::string
Serialize(
const int& indent_level)
const noexcept override;
215 virtual PointerType
Clone()
const override {
216 return MakePointer<Value<T>>(*this);
223 virtual PointerType
Move()
override {
224 return MakePointer<Value<T>>(std::move(*
this));
The base class for all configuration items.
Definition base.hxx:44
Named or unnamed typed value.
Definition value.hxx:37
Value(const char *value)
Constructs a string Value from a C string.
Definition value.hxx:54
virtual constexpr Item::Type Type() const noexcept override
Gets the type of the item.
Definition value.hxx:156
const T & operator*() const noexcept
Gets the item value (const).
Definition value.hxx:200
virtual PointerType Move() override
Moves the item.
Definition value.hxx:223
Value(const std::string &name, const T &value)
Constructs a named Value.
Definition value.hxx:77
T & operator*() noexcept
Gets the item value (mutable).
Definition value.hxx:192
virtual ~Value() noexcept override=default
Destructor.
Value(const std::string &name, const char *value)
Named string constructor from C string value.
Definition value.hxx:91
Value(std::string &&name, const char *value)
Named string constructor (move name) from C string value.
Definition value.hxx:99
Value(T &&value)
Move constructor from value.
Definition value.hxx:70
Value(const Value &single)=default
Copy constructor.
T m_value
The value of the item.
Definition value.hxx:229
Value(Value &&single) noexcept=default
Move constructor.
Value & operator=(Value &&single) noexcept=default
Move assignment operator.
Value(const T &value)
Constructs a Value with the given value.
Definition value.hxx:47
bool operator==(const Value< T > &single) const noexcept
Checks if two Value objects are equal.
Definition value.hxx:175
virtual PointerType Clone() const override
Clones the item.
Definition value.hxx:215
Value(const char *name, const char *value)
Constructs a named string Value from C strings.
Definition value.hxx:63
Value(std::string &&name, T &&value)
Constructs a named Value (move).
Definition value.hxx:84
Value & operator=(const Value &single)=default
Copy assignment operator.
std::string Serialize(const int &indent_level) const noexcept override
Serializes the item to a string.
bool operator!=(const Value< T > &single) const noexcept
Inequality operator.
Definition value.hxx:184
Configuration items (values, comments, groups, lists).
Definition alias.hxx:30
Type
Represents the type of a configuration item.
Definition type.hxx:39