35 lines
1.2 KiB
Plaintext
35 lines
1.2 KiB
Plaintext
:sig
|
|
DValue DValue::get_by_path(String path, String delim = "/") const
|
|
|
|
:params
|
|
path : slash-delimited path to traverse
|
|
delim : optional path separator
|
|
return value : the resolved child node, or an empty `DValue` when the path cannot be followed
|
|
|
|
:see
|
|
0_DValue
|
|
0_Request
|
|
>types
|
|
json_decode
|
|
has
|
|
to_string
|
|
|
|
:content
|
|
Traverses a nested `DValue` without creating missing keys. This is a read accessor: it is `const` and never modifies the tree, unlike `operator[]`, which creates missing entries.
|
|
|
|
Empty path segments are ignored, so leading and trailing `/` characters are harmless. If any intermediate node is not a map or a segment is missing, `get_by_path()` returns an empty `DValue`.
|
|
|
|
A missing path therefore reads like an empty value — combine it with the `to_*` default arguments to express a fallback in one call:
|
|
|
|
## Example
|
|
|
|
```cpp
|
|
String label = context.cfg.get_by_path("theme/options/portal-dark/label").to_string("Portal Dark");
|
|
s64 page_size = context.cfg.get_by_path("app/page_size").to_s64(25);
|
|
```
|
|
|
|
## Related Concepts
|
|
|
|
- PHP: deep array access helpers for associative arrays, decoded JSON, or configuration trees
|
|
- JavaScript / Node.js: optional chaining like `obj?.a?.b`, lodash `get`, or small path-walking helpers
|