10#include <unordered_map>
15namespace Steam::Utils::VDF {
22 using Object = std::unordered_map<std::string, VDFNode>;
50 if (
auto obj = std::get_if<Object>(&
value)) {
51 auto it = obj->find(key);
60 if (
auto obj = std::get_if<Object>(&
value)) {
61 auto it = obj->find(key);
73 std::string
get_string_or(
const std::string& key, std::string def)
const {
74 if (
auto node =
get(key)) {
75 if (
auto val = std::get_if<std::string>(&node->value))
82 int32_t
get_int_or(
const std::string& key, int32_t def)
const {
83 if (
auto node =
get(key)) {
84 if (
auto val = std::get_if<int32_t>(&node->value))
92 if (
auto node =
get(key)) {
93 if (
auto val = std::get_if<uint64_t>(&node->value))
101 if (
auto node =
get(key)) {
102 if (
auto val = std::get_if<float>(&node->value))
120 for (
const auto& key : keys) {
124 auto obj = std::get_if<Object>(¤t->
value);
128 auto it = obj->find(key);
129 if (it == obj->end())
132 current = &it->second;
142 return std::get<Object>(
value);
147 return std::get<Object>(
value);
154 return std::get<std::string>(
value);
159 return std::get<std::string>(
value);
164 return std::get<int32_t>(
value);
169 return std::get<uint64_t>(
value);
174 return std::get<float>(
value);
194 static void stringify_object(
const Object& obj, std::string& out,
int indent = 0);
202 stringify_object(obj, out, 0);
Node in a VDF tree.
Definition vdf.hpp:40
VDFNode * get(const std::string &key)
Find a child node by key.
Definition vdf.hpp:59
std::string & as_string()
Access the node as a string.
Definition vdf.hpp:153
const VDFNode * get(const std::string &key) const
Find a child node by key.
Definition vdf.hpp:49
float get_float_or(const std::string &key, float def) const
Retrieve a float value by key with fallback.
Definition vdf.hpp:100
uint64_t as_uint64() const
Access the node as a uint64_t.
Definition vdf.hpp:168
Object & as_object()
Access the node as an object.
Definition vdf.hpp:141
int32_t as_int() const
Access the node as an int32_t.
Definition vdf.hpp:163
std::string get_string_or(const std::string &key, std::string def) const
Retrieve a string value by key with a default fallback.
Definition vdf.hpp:73
int32_t get_int_or(const std::string &key, int32_t def) const
Retrieve an int32_t value by key with fallback.
Definition vdf.hpp:82
uint64_t get_uint64_or(const std::string &key, uint64_t def) const
Retrieve a uint64_t value by key with fallback.
Definition vdf.hpp:91
const std::string & as_string() const
Access the node as a string.
Definition vdf.hpp:158
Value value
Stored node value.
Definition vdf.hpp:43
const VDFNode * get_path(std::initializer_list< std::string > keys) const
Find a nested node using a path of keys.
Definition vdf.hpp:117
float as_float() const
Access the node as a float.
Definition vdf.hpp:173
const Object & as_object() const
Access the node as an object.
Definition vdf.hpp:146
std::variant< std::string, int32_t, uint64_t, float, Object > Value
Value stored in a VDF node.
Definition vdf.hpp:27
Object parse_text(std::string_view text)
Parse VDF text into an object tree.
Object parse_binary(const uint8_t *data, size_t size)
Parse binary VDF data.
std::string stringify(const Object &obj)
Convert a VDF object into a human-readable string.
Definition vdf.hpp:199
std::unordered_map< std::string, VDFNode > Object
Object node type.
Definition vdf.hpp:22