8#include <BufferStream.h>
16 || std::same_as<V, bool>
17 || std::same_as<V, int32_t>
18 || std::same_as<V, int64_t>
19 || std::same_as<V, float>;
28 [[nodiscard]] std::string_view
getKey()
const;
31 void setKey(std::string_view key_);
34 [[nodiscard]] std::string_view
getValue()
const;
37 template<BSPEntityKeyValueType V>
39 if constexpr (std::convertible_to<V, std::string_view>) {
41 }
else if constexpr (std::same_as<V, bool>) {
42 return static_cast<bool>(this->getValue<int32_t>());
43 }
else if constexpr (std::same_as<V, int32_t>) {
44 return std::stoi(std::string{this->
value});
45 }
else if constexpr (std::same_as<V, int64_t>) {
46 return std::stoll(std::string{this->
value});
47 }
else if constexpr (std::same_as<V, float>) {
48 return std::stof(std::string{this->
value});
54 template<BSPEntityKeyValueType V>
56 if constexpr (std::convertible_to<V, std::string_view>) {
57 this->
value = std::string_view{value_};
59 this->
setValue(std::to_string(value_));
64 template<BSPEntityKeyValueType V>
85 [[nodiscard]]
bool hasChild(std::string_view childKey)
const;
94 [[nodiscard]]
const std::vector<Element>&
getKeyValues()
const;
115 [[nodiscard]]
const Element&
operator()(std::string_view childKey,
unsigned int n)
const;
121 template<BSPEntityKeyValueType V = std::
string_view>
125 elem.setValue(value_);
133 [[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.
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.