25 this->
value = std::move(value_);
79 for (
const auto& element : this->
children) {
88 for (
auto& element : this->
children) {
97 unsigned int count = 0;
98 for (
const auto& element : this->
children) {
110 unsigned int count = 0;
111 for (
auto& element: this->
children) {
129 unsigned int count = 0;
130 for (
auto element = this->
children.begin(); element != this->children.end(); ++element) {
132 if (n < 0 || count == n) {
133 element = this->
children.erase(element);
159 element.
key = stream.read_string();
166 element.
value = stream.read_string();
169 element.
value = stream.read<int32_t>();
172 element.
value = stream.read<
float>();
175 element.
value =
reinterpret_cast<void*
>(stream.read<int32_t>());
178 const auto len = stream.read<uint16_t>();
180 for (
int i = 0; i < len; i++) {
181 value += stream.read<
char16_t>();
188 value[0] = stream.read<uint8_t>();
189 value[1] = stream.read<uint8_t>();
190 value[2] = stream.read<uint8_t>();
191 value[3] = stream.read<uint8_t>();
196 element.
value = stream.read<uint64_t>();
205 for (
const auto& element : elements) {
209 .write(element.getKey());
216 stream.write(*element.getValue<std::string>());
219 stream.write(*element.getValue<int32_t>());
222 stream.write(*element.getValue<
float>());
225 stream.write(
static_cast<int32_t
>(
reinterpret_cast<uint64_t
>(*element.getValue<
void*>())));
228 const auto val = *element.getValue<std::wstring>();
230 .write<uint16_t>(val.size() + 1)
231 .
write(
reinterpret_cast<const char16_t*
>(val.data()), val.size() *
sizeof(char16_t) /
sizeof(
wchar_t))
236 const auto val = *element.getValue<math::Vec4ui8>();
237 stream << val[0] << val[1] << val[2] << val[3];
241 stream.write(*element.getValue<uint64_t>());
252 , useEscapeSequences(useEscapeSequences_) {
253 if (kv1Data.empty()) {
256 BufferStreamReadOnly stream{kv1Data.data(), kv1Data.size()};
261 std::vector<std::byte> buffer;
262 BufferStream stream{buffer};
264 buffer.resize(stream.size());
280 for (
const auto& elementChild : element.
getChildren()) {
281 recurseBinaryKeyValues(elementChild, child);
285 child = *element.
getValue<std::string>();
288 child = *element.
getValue<int32_t>();
294 child =
reinterpret_cast<int64_t
>(*element.
getValue<
void*>());
299 const auto val = *element.
getValue<math::Vec4ui8>();
300 child = std::format(
"{} {} {} {}", val[0], val[1], val[2], val[3]);
304 child = std::format(
"{}", *element.
getValue<uint64_t>());
310 recurseBinaryKeyValues(*
this, writer);
311 return writer.
bake();
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)
std::vector< KV1BinaryElement > children
const KV1BinaryElement & operator()(std::string_view childKey) const
Get the first child element of the element with the given key.
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 setKey(std::string_view key_)
Set the key associated with the element.
const KV1BinaryValue & getValue() const
Get the value associated with the element.
uint64_t getChildCount() const
Get the number of child elements.
KV1BinaryElement & operator=(KV1BinaryValue value_)
Set the value associated with the element.
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.
bool isInvalid() const
Check if the given element is invalid.
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
KV1Binary(std::span< const std::byte > kv1Data={}, bool useEscapeSequences_=false)
std::string bakeText() const
KV1ElementWritable & addChild(std::string_view key_, V value_={}, std::string_view conditional_="")
std::variant< std::monostate, std::string, int32_t, float, void *, std::wstring, sourcepp::math::Vec4ui8, uint64_t > KV1BinaryValue
bool writeFileText(const std::string &filepath, const std::string &text)
bool writeFileBuffer(const std::string &filepath, std::span< const std::byte > buffer)
std::unordered_map< char, char > EscapeSequenceMap
const EscapeSequenceMap & getDefaultEscapeSequencesOrNone(bool useEscapes)
bool iequals(std::string_view s1, std::string_view s2)