28#if defined(__cpp_lib_generator) && __cpp_lib_generator >= 202207L
30#define PARCEL_HAS_GENERATOR 1
32#define PARCEL_HAS_GENERATOR 0
50inline std::string jp_escape(
const std::string_view k) {
52 out.reserve(k.size());
53 for (
const char c : k) {
56 }
else if (c ==
'/') {
65inline void walk_collect(cell_t
const& root,
const std::string& path, std::vector<WalkEntry>& out) {
69 out.push_back({path, root});
71 if (
auto const* list =
dynamic_cast<ListCell const*
>(root.get()); list !=
nullptr) {
73 for (
auto const& el : list->value) {
74 std::string sub = path;
76 sub += std::to_string(i);
77 walk_collect(el, sub, out);
83 if (
auto const* map =
dynamic_cast<MapCell const*
>(root.get()); map !=
nullptr) {
84 for (
auto const& [k, v] : map->value) {
85 std::string sub = path;
88 walk_collect(v, sub, out);
106 std::vector<WalkEntry> out;
107 detail::walk_collect(root,
"", out);
111#if PARCEL_HAS_GENERATOR
116inline std::generator<WalkEntry> walk_node(cell_t root, std::string path) {
120 co_yield WalkEntry{path, root};
122 if (
auto const* list =
dynamic_cast<ListCell const*
>(root.get()); list !=
nullptr) {
124 for (
auto const& el : list->value) {
125 std::string sub = path;
127 sub += std::to_string(i);
128 for (
auto&& entry : walk_node(el, std::move(sub))) {
129 co_yield std::move(entry);
136 if (
auto const* map =
dynamic_cast<MapCell const*
>(root.get()); map !=
nullptr) {
137 for (
auto const& [k, v] : map->value) {
138 std::string sub = path;
141 for (
auto&& entry : walk_node(v, std::move(sub))) {
142 co_yield std::move(entry);
164inline std::generator<WalkEntry> walk(cell_t root) {
165 return detail::walk_node(std::move(root),
"");
Core ICell interface, cell_t handle, BaseCell CRTP base, and CellLike concept.
std::shared_ptr< ICell > cell_t
Shared handle to any ICell-derived value — the canonical cell pointer.
Definition cell.h:68
TypedListCell<T> and heterogeneous ListCell with their descriptors.
TypedMapCell<T> and heterogeneous MapCell with their descriptors.
StructCell CRTP base, FieldsBuilder, and the per-field descriptors.
One node yielded by a tree walk: (json-pointer-path, cell).
Definition walk.h:38
std::string path
JSON-pointer-style path to the cell ("" for the root).
Definition walk.h:40
cell_t cell
The cell at that path.
Definition walk.h:42
UnionCell<Ts...> closed-set polymorphic cell and its descriptor.
std::vector< WalkEntry > walk_to_vector(cell_t const &root)
Eagerly collect every cell in root's tree, depth-first.
Definition walk.h:105