refactor: rename DTree to DValue
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
#pragma once
|
||||
|
||||
String json_escape(String s, char quote_char = '"');
|
||||
|
||||
// DValue is UCE's general-purpose structured value container.
|
||||
// It stores scalar values, nested map/list-like values, and internal references.
|
||||
// Numeric and boolean reads are intentionally permissive so request data,
|
||||
// JSON-decoded values, and metadata trees can be consumed without repetitive
|
||||
// manual parsing at each call site.
|
||||
struct DValue {
|
||||
|
||||
char type = 'S';
|
||||
|
||||
String _String;
|
||||
f64 _float;
|
||||
s64 _array_index = 0;
|
||||
bool _bool;
|
||||
bool _list_mode = false;
|
||||
void* _ptr;
|
||||
std::map<String, DValue> _map;
|
||||
|
||||
// Read accessors are const and never create or modify nodes. The to_*
|
||||
// conversions take an optional default that is returned when the value is
|
||||
// missing (empty) or cannot be converted to the requested type.
|
||||
void each(std::function <void (const DValue& t, String key)> f) const;
|
||||
bool is_array() const;
|
||||
bool is_list() const;
|
||||
String to_string(String default_value = "") const;
|
||||
s64 to_s64(s64 default_value = 0) const;
|
||||
u64 to_u64(u64 default_value = 0) const;
|
||||
f64 to_f64(f64 default_value = 0) const;
|
||||
bool to_bool(bool default_value = false) const;
|
||||
StringMap to_stringmap() const;
|
||||
String to_json(char quote_char = '"') const;
|
||||
String get_type_name() const;
|
||||
DValue get_by_path(String path, String delim = "/") const;
|
||||
bool is_reference() const;
|
||||
DValue* reference_target();
|
||||
const DValue* reference_target() const;
|
||||
DValue& deref();
|
||||
const DValue& deref() const;
|
||||
void set_type(char t);
|
||||
void set(String s);
|
||||
void set(void* p);
|
||||
void set(f64 f);
|
||||
void set_bool(bool b);
|
||||
void set(DValue source);
|
||||
void set(StringMap source);
|
||||
void set_array();
|
||||
void set_reference(DValue* target);
|
||||
bool has(String s) const;
|
||||
DValue* key(String s);
|
||||
const DValue* key(String s) const;
|
||||
DValue* get_or_create(String s);
|
||||
DValue& operator [] (String s);
|
||||
void operator = (String v);
|
||||
void operator = (f64 v);
|
||||
void operator = (void* v);
|
||||
void operator = (DValue v);
|
||||
void operator = (StringMap v);
|
||||
|
||||
void push(const DValue& child);
|
||||
DValue pop();
|
||||
void remove(String s);
|
||||
void clear();
|
||||
};
|
||||
|
||||
String to_String(DValue t);
|
||||
String var_dump(const DValue& map, String prefix = "", String postfix = "\n");
|
||||
Reference in New Issue
Block a user