9#include <BufferStream.h>
17 || std::same_as<V, bool>
18 || std::same_as<V, int32_t>
19 || std::same_as<V, int64_t>
20 || std::same_as<V, float>;
29 [[nodiscard]] std::string_view
getKey()
const;
32 void setKey(std::string_view key_);
35 [[nodiscard]] std::string_view
getValue()
const;
38 template<BSPEntityKeyValueType V>
40 if constexpr (std::convertible_to<V, std::string_view>) {
42 }
else if constexpr (std::same_as<V, bool>) {
44 }
else if constexpr (std::same_as<V, int32_t>) {
45 return std::stoi(std::string{this->
value});
46 }
else if constexpr (std::same_as<V, int64_t>) {
47 return std::stoll(std::string{this->
value});
48 }
else if constexpr (std::same_as<V, float>) {
49 return std::stof(std::string{this->
value});
55 template<BSPEntityKeyValueType V>
57 if constexpr (std::convertible_to<V, std::string_view>) {
58 this->
value = std::string_view{value_};
59 }
else if constexpr (std::same_as<V, bool>) {
60 this->
setValue(std::format(
"{:b}", value_));
62 this->
setValue(std::format(
"{}", value_));
67 template<BSPEntityKeyValueType V>
88 [[nodiscard]]
bool hasChild(std::string_view childKey)
const;
97 [[nodiscard]]
const std::vector<Element>&
getKeyValues()
const;
118 [[nodiscard]]
const Element&
operator()(std::string_view childKey,
unsigned int n)
const;
124 template<BSPEntityKeyValueType V = std::
string_view>
128 elem.setValue(value_);
136 [[nodiscard]] std::string
bake(
bool useEscapes)
const;
static const Element & getInvalid()
V getValue() const
Get the value associated with the element as the given type.
void setValue(V value_)
Set the value associated with the element.
Element & operator=(V value_)
Set the value associated with the element.
std::string_view getKey() const
Get the key associated with the element.
std::string_view getValue() const
Get the value associated with the element.
friend class BSPEntityKeyValues
bool isInvalid() const
Check if the given element is invalid.
void setKey(std::string_view key_)
Set the key associated with the element.
const Element & operator()(std::string_view childKey) const
Get the first keyvalue of the entity with the given key.
bool hasChild(std::string_view childKey) const
Check if this entity has one or more keyvalues with the given name.
Element & addKeyValue(std::string_view key_, V value_={})
Add a new keyvalue to the entity.
uint64_t getKeyValuesCount() const
Get the number of keyvalues.
std::string bake(bool useEscapes) const
BSPEntityKeyValues()=default
const std::vector< Element > & getKeyValues() const
Get the keyvalues of the entity.
void removeKeyValue(std::string_view childKey, int n=-1)
Remove a keyvalue from the entity. -1 means all keyvalues with the given key.
std::vector< Element > keyvalues
const Element & operator[](unsigned int n) const
Get the keyvalue of the entity at the given index.