Skip to content

Commit

Permalink
use path_node
Browse files Browse the repository at this point in the history
  • Loading branch information
danielaparker committed Nov 13, 2023
1 parent a3184ee commit 3381efc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
24 changes: 14 additions & 10 deletions include/jsoncons_ext/jsonpath/json_query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ namespace jsonpath {
using reference = typename jsonpath_traits_type::reference;
using evaluator_type = typename jsonpath_traits_type::evaluator_type;
using path_expression_type = typename jsonpath_traits_type::path_expression_type;
using json_location_type = typename jsonpath_traits_type::json_location_type;
using path_node_type = typename jsonpath_traits_type::path_node_type;

auto static_resources = jsoncons::make_unique<jsoncons::jsonpath::detail::static_resources<value_type,reference>>(funcs);
evaluator_type evaluator;
path_expression_type expr = evaluator.compile(*static_resources, path);

jsoncons::jsonpath::detail::dynamic_resources<Json,reference> resources;
auto callback = [&new_value](const json_location_type&, reference v)
auto callback = [&new_value](const path_node_type&, reference v)
{
v = std::forward<T>(new_value);
};
Expand All @@ -94,14 +94,14 @@ namespace jsonpath {
using reference = typename jsonpath_traits_type::reference;
using evaluator_type = typename jsonpath_traits_type::evaluator_type;
using path_expression_type = typename jsonpath_traits_type::path_expression_type;
using json_location_type = typename jsonpath_traits_type::json_location_type;
using path_node_type = typename jsonpath_traits_type::path_node_type;

auto static_resources = jsoncons::make_unique<jsoncons::jsonpath::detail::static_resources<value_type,reference>>(funcs, alloc_set.get_allocator());
evaluator_type evaluator{alloc_set.get_allocator()};
path_expression_type expr = evaluator.compile(*static_resources, path);

jsoncons::jsonpath::detail::dynamic_resources<Json,reference> resources{alloc_set.get_allocator()};
auto callback = [&new_value](const json_location_type&, reference v)
auto callback = [&new_value](const path_node_type&, reference v)
{
v = Json(std::forward<T>(new_value), semantic_tag::none);
};
Expand All @@ -119,6 +119,7 @@ namespace jsonpath {
using reference = typename jsonpath_traits_type::reference;
using evaluator_type = typename jsonpath_traits_type::evaluator_type;
using path_expression_type = typename jsonpath_traits_type::path_expression_type;
using path_node_type = typename jsonpath_traits_type::path_node_type;
using json_location_type = typename jsonpath_traits_type::json_location_type;

auto static_resources = jsoncons::make_unique<jsoncons::jsonpath::detail::static_resources<value_type,reference>>(funcs);
Expand All @@ -127,9 +128,10 @@ namespace jsonpath {

jsoncons::jsonpath::detail::dynamic_resources<Json,reference> resources;

auto f = [&callback](const json_location_type& pathp, reference val)
auto f = [&callback](const path_node_type& path, reference val)
{
callback(pathp.to_string(), val);
json_location_type loc(path);
callback(loc.to_string(), val);
};
expr.evaluate_with_replacement(resources, instance, resources.root_path_node(), instance, f);
}
Expand All @@ -146,6 +148,7 @@ namespace jsonpath {
using reference = typename jsonpath_traits_type::reference;
using evaluator_type = typename jsonpath_traits_type::evaluator_type;
using path_expression_type = typename jsonpath_traits_type::path_expression_type;
using path_node_type = typename jsonpath_traits_type::path_node_type;
using json_location_type = typename jsonpath_traits_type::json_location_type;

auto static_resources = jsoncons::make_unique<jsoncons::jsonpath::detail::static_resources<value_type,reference>>(funcs, alloc_set.get_allocator());
Expand All @@ -154,9 +157,10 @@ namespace jsonpath {

jsoncons::jsonpath::detail::dynamic_resources<Json,reference> resources{alloc_set.get_allocator()};

auto f = [&callback](const json_location_type& pathp, reference val)
auto f = [&callback](const path_node_type& path, reference val)
{
callback(pathp.to_string(), val);
json_location_type loc(path);
callback(loc.to_string(), val);
};
expr.evaluate_with_replacement(resources, instance, resources.root_path_node(), instance, f);
}
Expand All @@ -172,14 +176,14 @@ namespace jsonpath {
using reference = typename jsonpath_traits_type::reference;
using evaluator_type = typename jsonpath_traits_type::evaluator_type;
using path_expression_type = typename jsonpath_traits_type::path_expression_type;
using json_location_type = typename jsonpath_traits_type::json_location_type;
using path_node_type = typename jsonpath_traits_type::path_node_type;

auto static_resources = jsoncons::make_unique<jsoncons::jsonpath::detail::static_resources<value_type,reference>>();
evaluator_type evaluator;
path_expression_type expr = evaluator.compile(*static_resources, path);

jsoncons::jsonpath::detail::dynamic_resources<Json,reference> resources;
auto f = [callback](const json_location_type&, reference v)
auto f = [callback](const path_node_type&, reference v)
{
v = callback(v);
};
Expand Down
3 changes: 1 addition & 2 deletions include/jsoncons_ext/jsonpath/jsonpath_selector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ namespace detail {
using pointer = typename supertype::pointer;
using path_value_pair_type = typename supertype::path_value_pair_type;
using path_node_type = typename supertype::path_node_type;
using json_location_type = basic_json_location<char_type>;
using json_location_type = typename supertype::path_node_type;
using path_generator_type = path_generator<Json,JsonReference>;
using node_receiver_type = typename supertype::node_receiver_type;

Expand Down Expand Up @@ -895,7 +895,6 @@ namespace detail {
using pointer = typename supertype::pointer;
using path_value_pair_type = typename supertype::path_value_pair_type;
using path_node_type = typename supertype::path_node_type;
using json_location_type = basic_json_location<char_type>;
using path_expression_type = path_expression<Json, JsonReference>;
using path_generator_type = path_generator<Json,JsonReference>;
using node_receiver_type = typename supertype::node_receiver_type;
Expand Down

0 comments on commit 3381efc

Please sign in to comment.