35 explicit operator uint64_t() const noexcept {
50 sourcepp::math::Vec4ui8,
56 || std::same_as<V, int32_t>
57 || std::same_as<V, float>
58 || std::same_as<V, KV1BinaryPointer>
59 || std::same_as<V, std::wstring>
60 || std::same_as<V, sourcepp::math::Vec4ui8>
61 || std::same_as<V, uint64_t>;
68 [[nodiscard]] std::string_view
getKey()
const;
71 void setKey(std::string_view key_);
77 template<KV1BinaryValueNoChildren V>
78 [[nodiscard]] std::optional<V>
getValue()
const {
79 if (!std::holds_alternative<V>(this->
value)) {
82 return std::get<V>(this->
value);
92 template<KV1BinaryValueNoChildren V>
94 this->
value = std::move(value_);
98 template<KV1BinaryValueNoChildren V>
105 [[nodiscard]]
bool hasChild(std::string_view childKey)
const;
111 template<KV1BinaryValueNoChildren V>
116 this->
children.push_back(std::move(elem));
124 [[nodiscard]] uint64_t
getChildCount(std::string_view childKey)
const;
127 [[nodiscard]]
const std::vector<KV1BinaryElement>&
getChildren()
const;
130 [[nodiscard]] std::vector<KV1BinaryElement>&
getChildren();
132 using iterator = std::vector<KV1BinaryElement>::iterator;
188 void removeChild(std::string_view childKey,
int n = -1);
195 [[nodiscard]]
explicit operator bool()
const;
205 explicit KV1Binary(std::span<const std::byte> kv1Data = {},
bool use64BitPointers =
true);
207 explicit KV1Binary(
const std::filesystem::path& kv1Path,
bool use64BitPointers =
true);
209 [[nodiscard]] std::vector<std::byte>
bake()
const;
211 void bake(
const std::filesystem::path& kv1Path)
const;
213 [[nodiscard]] std::string
bakeText()
const;
215 void bakeText(
const std::filesystem::path& kv1Path)
const;
const std::vector< KV1BinaryElement > & getChildren() const
Get the child elements of the element.
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.
KV1BinaryElement & addChild(std::string_view key_, KV1BinaryValue value_={})
Add a child element to the element.
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
std::string_view getKey() const
Get the key associated with the element.
std::vector< std::byte > bake() const
KV1Binary(std::span< const std::byte > kv1Data={}, bool use64BitPointers=true)
std::string bakeText() const
std::variant< std::monostate, std::string, int32_t, float, KV1BinaryPointer, std::wstring, sourcepp::math::Vec4ui8, uint64_t > KV1BinaryValue
static constexpr auto MAGIC_64_BIT