13bool parseSegment(
const std::string& seg, std::string&
key, std::vector<size_t>& indexes) {
16 if (seg.empty())
return false;
20 while (i < seg.size() && seg[i] !=
'[')
key.push_back(seg[i++]);
22 if (
key.empty() && (i >= seg.size()))
return false;
24 while (i < seg.size()) {
25 if (seg[i] !=
'[')
return false;
26 const size_t close = seg.find(
']', i);
27 if (close == std::string::npos)
return false;
28 const std::string
idx = seg.substr(i + 1, close - i - 1);
29 if (
idx.empty() ||
idx.find_first_not_of(
"0123456789") != std::string::npos)
return false;
30 indexes.push_back(
static_cast<size_t>(std::stoull(
idx)));
39 switch (
value.kind()) {
47 array.reserve(
value.arraySize());
61 switch (
value.type()) {
101 sv.s_ = std::move(
v);
108 for (
auto& kv : obj_) {
109 if (kv.first ==
key) {
110 kv.second = std::move(
v);
114 obj_.emplace_back(
key, std::move(
v));
118 for (
const auto& kv : obj_)
119 if (kv.first ==
key)
return &kv.second;
124 for (
auto& kv : obj_)
125 if (kv.first ==
key)
return &kv.second;
130 std::vector<std::string>
out;
131 out.reserve(obj_.size());
132 for (
const auto& kv : obj_)
out.push_back(kv.first);
140 const size_t dot = dottedPath.find(
'.',
start);
141 const bool last = (dot == std::string::npos);
142 const std::string seg = dottedPath.substr(
start, last ? std::string::npos : dot -
start);
145 std::vector<size_t> indexes;
146 if (!parseSegment(seg,
key, indexes))
return nullptr;
149 if (!cur)
return nullptr;
151 for (
const size_t idx : indexes) {
152 if (!cur->
isArray() ||
idx >= cur->arr_.size())
return nullptr;
153 cur = &cur->arr_[
idx];
155 if (last)
return cur;
165 std::vector<std::string> segs;
168 const size_t dot = dottedPath.find(
'.',
start);
169 if (dot == std::string::npos) {
170 segs.push_back(dottedPath.substr(
start));
173 segs.push_back(dottedPath.substr(
start, dot -
start));
176 if (segs.empty() || (segs.size() == 1 && segs[0].empty()))
return false;
179 for (
size_t si = 0; si + 1 < segs.size(); ++si) {
181 std::vector<size_t> indexes;
184 if (!parseSegment(segs[si],
key, indexes) ||
key.empty() || !indexes.empty())
return false;
195 std::vector<size_t> indexes;
196 if (!parseSegment(segs.back(),
key, indexes))
return false;
197 if (!indexes.empty()) {
201 if (!arr || !arr->
isArray())
return false;
204 if (!cur->
isArray() || indexes.size() != 1 || indexes[0] >= cur->arr_.size())
return false;
205 cur->arr_[indexes[0]] = std::move(
v);
216 for (
const auto& kv :
defaults.obj_) {
219 set(kv.first, kv.second);
221 }
else if (mine->
isObject() && kv.second.isObject()) {
229 if (kind_ != o.kind_)
return false;
238 if (obj_.size() != o.obj_.size())
return false;
239 for (
const auto& [
key,
value] : obj_) {
240 const auto* other = o.
find(
key);
241 if (!other ||
value != *other)
return false;
std::vector< Value > defaults
float(ui::Theme::* member)[4]
JSON-compatible state value tree used by state hot reload.
static StateValue object()
Empty object.
static StateValue boolean(bool v)
Boolean value.
static StateValue array()
Empty array.
bool setPath(const std::string &dottedPath, StateValue v)
Set a value at a dotted path, creating missing intermediate objects along the way.
static StateValue integer(int64_t v)
Integer value.
bool mergeDefaults(const StateValue &defaults)
Fill missing members from defaults; object members merge recursively, existing values are never overw...
void pushBack(StateValue v)
Append an element; only valid on arrays.
const StateValue * get(const std::string &dottedPath) const
Navigate a dotted path ("a.b[2].c").
bool operator==(const StateValue &o) const
Compare typed values; object key order is ignored, array order is significant. @cost Scalars are cons...
static StateValue number(double v)
Floating-point value.
const StateValue * find(const std::string &key) const
Look up key; nullptr when absent.
static StateValue null()
Null value.
std::vector< std::string > keys() const
Member names in insertion order.
static StateValue string(std::string v)
String value.
void set(const std::string &key, StateValue v)
Insert or replace key; only valid on objects.
The canonical owning dynamic value used by data-facing protocols.
static Value null()
Compatibility factory for a null value.
std::map< std::string, Value > Object
static Value number(double value)
Compatibility factory for a Double value.
static Value string(std::string value)
Compatibility factory for a string value.
std::vector< Value > Array
static Value array(Array value)
Compatibility factory for an array value.
static Value integer(std::int64_t value)
Compatibility factory for an Int64 value.
static Value boolean(bool value)
Compatibility factory for a boolean value.
static Value object(Object value)
Compatibility factory for an object value.
Build metadata (engine git commit, build time, third-party version).
StateValue toLegacyStateValue(const Value &value)
Project a canonical value into the legacy reload snapshot format.
Value toCanonicalStateValue(const StateValue &value)
Copy a legacy reload tree into the canonical owning value protocol.