11#include <BufferStream.h>
35 sourcepp::math::Vec4ui8,
41 || std::same_as<V, int32_t>
42 || std::same_as<V, float>
43 || std::same_as<V, void*>
44 || std::same_as<V, std::wstring>
45 || std::same_as<V, sourcepp::math::Vec4ui8>
46 || std::same_as<V, uint64_t>;
53 [[nodiscard]] std::string_view
getKey()
const;
56 void setKey(std::string_view key_);
62 template<KV1BinaryValueNoChildren V>
63 [[nodiscard]] std::optional<V>
getValue()
const {
64 if (!std::holds_alternative<V>(this->
value)) {
67 return std::get<V>(this->
value);
77 template<KV1BinaryValueNoChildren V>
79 this->
value = std::move(value_);
83 template<KV1BinaryValueNoChildren V>
90 [[nodiscard]]
bool hasChild(std::string_view childKey)
const;
96 [[nodiscard]] uint64_t
getChildCount(std::string_view childKey)
const;
99 [[nodiscard]]
const std::vector<KV1BinaryElement>&
getChildren()
const;
105 template<KV1BinaryValueNoChildren V>
142 void removeChild(std::string_view childKey,
int n = -1);
144 using iterator = std::vector<KV1BinaryElement>::iterator;
190 explicit KV1Binary(std::span<const std::byte> kv1Data = {},
bool useEscapeSequences_ =
false);
192 [[nodiscard]] std::vector<std::byte>
bake()
const;
194 void bake(
const std::string& kv1Path)
const;
196 [[nodiscard]] std::string
bakeText()
const;
198 void bakeText(
const std::string& kv1Path)
const;
const std::vector< KV1BinaryElement > & getChildren() const
Get the child elements of the element.
KV1BinaryElement & addChild(std::string_view key_)
Add a child element to the element.
static void read(BufferStreamReadOnly &stream, std::vector< KV1BinaryElement > &elements, const sourcepp::parser::text::EscapeSequenceMap &escapeSequences)
constexpr const_iterator cend() const
std::vector< KV1BinaryElement > children
const KV1BinaryElement & operator()(std::string_view childKey) const
Get the first child element of the element with the given key.
KV1BinaryElement & operator=(V value_)
Set the value associated with the element.
constexpr iterator begin()
std::optional< V > getValue() const
Get the value associated with the element as the given type.
static const KV1BinaryElement & getInvalid()
void removeChild(unsigned int n)
Remove a child element from the element.
bool hasChild(std::string_view childKey) const
Check if the element has one or more children with the given name.
void setValue(V value_)
Set the value associated with the element.
void setKey(std::string_view key_)
Set the key associated with the element.
const KV1BinaryValue & getValue() const
Get the value associated with the element.
KV1BinaryElement & addChild(std::string_view key_, V value_={})
Add a child element to the element.
KV1BinaryElement()=default
uint64_t getChildCount() const
Get the number of child elements.
constexpr const_iterator cbegin() const
KV1BinaryElement & operator=(KV1BinaryValue value_)
Set the value associated with the element.
std::vector< KV1BinaryElement >::iterator iterator
void setValue(KV1BinaryValue value_)
Set the value associated with the element.
const KV1BinaryElement & operator[](unsigned int n) const
Get the child element of the element at the given index.
constexpr const_iterator end() const
bool isInvalid() const
Check if the given element is invalid.
std::vector< KV1BinaryElement >::const_iterator const_iterator
constexpr const_iterator begin() const
static void write(BufferStream &stream, const std::vector< KV1BinaryElement > &elements, const sourcepp::parser::text::EscapeSequenceMap &escapeSequences)
std::string_view getKey() const
Get the key associated with the element.
std::vector< std::byte > bake() const
std::string bakeText() const
std::variant< std::monostate, std::string, int32_t, float, void *, std::wstring, sourcepp::math::Vec4ui8, uint64_t > KV1BinaryValue
std::unordered_map< char, char > EscapeSequenceMap