diff --git a/include/jsoncons_ext/jsonpath/expression.hpp b/include/jsoncons_ext/jsonpath/expression.hpp index dd08c2d12a..427a257fee 100644 --- a/include/jsoncons_ext/jsonpath/expression.hpp +++ b/include/jsoncons_ext/jsonpath/expression.hpp @@ -2070,7 +2070,7 @@ namespace detail { using reference = JsonReference; using value_pointer = typename std::conditional::type>::value,typename Json::const_pointer,typename Json::pointer>::type; using path_node_type = basic_path_node; - using json_location_type = basic_json_location; + using json_location_type = basic_json_location; using path_pointer = const path_node_type*; json_location_type path_; @@ -2131,7 +2131,7 @@ namespace detail { using reference = JsonReference; using value_pointer = typename std::conditional::type>::value,typename Json::const_pointer,typename Json::pointer>::type; using path_node_type = basic_path_node; - using json_location_type = basic_json_location; + using json_location_type = basic_json_location; using path_pointer = const path_node_type*; private: const path_node_type* last_ptr_; @@ -2177,7 +2177,7 @@ namespace detail { using char_type = typename Json::char_type; using string_type = typename Json::string_type; using path_node_type = basic_path_node; - using json_location_type = basic_json_location; + using json_location_type = basic_json_location; using path_value_pair_type = path_value_pair; allocator_type alloc_; @@ -2191,7 +2191,7 @@ namespace detail { void add(const path_node_type& tail_nodes, reference value) override { - nodes.emplace_back(json_location_type(tail_nodes, alloc_), std::addressof(value)); + nodes.emplace_back(json_location_type(tail_nodes), std::addressof(value)); } }; @@ -2320,7 +2320,7 @@ namespace detail { using pointer = typename std::conditional::type>::value,typename Json::const_pointer,typename Json::pointer>::type; using path_value_pair_type = path_value_pair; using path_node_type = basic_path_node; - using json_location_type = basic_json_location; + using json_location_type = basic_json_location; using node_receiver_type = node_receiver; using selector_type = jsonpath_selector; @@ -3005,7 +3005,7 @@ namespace detail { using char_type = typename Json::char_type; using string_type = typename Json::string_type; using path_node_type = basic_path_node; - using json_location_type = basic_json_location; + using json_location_type = basic_json_location; private: allocator_type alloc_; Callback& callback_; @@ -3019,7 +3019,7 @@ namespace detail { void add(const path_node_type& tail_nodes, reference value) override { - callback_(json_location_type(tail_nodes, alloc_), value); + callback_(tail_nodes, value); } }; @@ -3041,7 +3041,7 @@ namespace detail { using reference_arg_type = typename std::conditional::type>::value, const_reference_arg_t,reference_arg_t>::type; using path_node_type = basic_path_node; - using json_location_type = basic_json_location; + using json_location_type = basic_json_location; using selector_type = jsonpath_selector; private: allocator_type alloc_; @@ -3096,7 +3096,7 @@ namespace detail { } template - typename std::enable_if::value,void>::type + typename std::enable_if::value,void>::type evaluate(dynamic_resources& resources, reference root, const path_node_type& path, @@ -3128,7 +3128,7 @@ namespace detail { receiver.nodes.erase(last,receiver.nodes.end()); for (auto& node : receiver.nodes) { - callback(node.path(), node.value()); + callback(node.path().base_node(), node.value()); } } else @@ -3151,7 +3151,7 @@ namespace detail { } for (auto& node : temp2) { - callback(node.path(), node.value()); + callback(node.path().base_node(), node.value()); } } } @@ -3159,7 +3159,7 @@ namespace detail { { for (auto& node : receiver.nodes) { - callback(node.path(), node.value()); + callback(node.path().base_node(), node.value()); } } } @@ -3171,7 +3171,7 @@ namespace detail { } template - typename std::enable_if::value,void>::type + typename std::enable_if::value,void>::type evaluate_with_replacement(dynamic_resources& resources, reference root, const path_node_type& path, @@ -3196,7 +3196,7 @@ namespace detail { for (std::size_t i = receiver.nodes.size(); i-- > 0;) { auto& node = receiver.nodes[i]; - callback(node.path(), node.value()); + callback(node.path().base_node(), node.value()); } } } diff --git a/include/jsoncons_ext/jsonpath/json_location.hpp b/include/jsoncons_ext/jsonpath/json_location.hpp index 88544ea4e7..0f0053c794 100644 --- a/include/jsoncons_ext/jsonpath/json_location.hpp +++ b/include/jsoncons_ext/jsonpath/json_location.hpp @@ -387,7 +387,7 @@ namespace jsonpath { }; template - Json* select(Json& root, const basic_json_location& path) + Json* select(Json& root, const basic_json_location& path) { Json* current = std::addressof(root); for (const auto& basic_path_node : path) diff --git a/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp b/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp index 18a052f640..a93118aaaf 100644 --- a/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp +++ b/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp @@ -111,7 +111,7 @@ namespace detail { using token_type = token; using path_expression_type = path_expression; using expression_type = expression; - using json_location_type = basic_json_location; + using json_location_type = basic_json_location; using path_node_type = basic_path_node; using selector_type = jsonpath_selector; @@ -2497,7 +2497,7 @@ namespace detail { using allocator_type = typename value_type::allocator_type; using evaluator_type = typename jsoncons::jsonpath::detail::jsonpath_evaluator; using path_node_type = basic_path_node; - using json_location_type = basic_json_location; + using json_location_type = basic_json_location; using path_expression_type = jsoncons::jsonpath::detail::path_expression; using path_pointer = const path_node_type*; }; @@ -2516,7 +2516,7 @@ namespace detail { using allocator_type = typename value_type::allocator_type; using evaluator_type = typename jsoncons::jsonpath::detail::jsonpath_evaluator; using path_node_type = basic_path_node; - using json_location_type = basic_json_location; + using json_location_type = basic_json_location; using path_expression_type = jsoncons::jsonpath::detail::path_expression; using path_pointer = const path_node_type*; }; @@ -2537,6 +2537,7 @@ namespace detail { using const_reference = typename jsonpath_traits_type::const_reference; 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; private: allocator_type alloc_; std::unique_ptr> static_resources_; @@ -2562,29 +2563,14 @@ namespace detail { evaluate(reference instance, BinaryCallback callback, result_options options = result_options()) const { jsoncons::jsonpath::detail::dynamic_resources resources{alloc_}; - auto f = [&callback](const json_location_type& path, reference val) + auto f = [&callback](const path_node_type& path, reference val) { - callback(path.to_string(), val); + basic_json_location loc(path); + callback(loc.to_string(), val); }; expr_.evaluate(resources, instance, resources.root_path_node(), instance, f, options); } - template - typename std::enable_if::value,void>::type - select_nodes(reference instance, BinaryCallback callback, result_options options = result_options()) const - { - jsoncons::jsonpath::detail::dynamic_resources resources{alloc_}; - expr_.evaluate(resources, instance, resources.root_path_node(), instance, callback, options); - } - - template - typename std::enable_if::value,void>::type - update_nodes(reference instance, BinaryCallback callback) const - { - jsoncons::jsonpath::detail::dynamic_resources resources{alloc_}; - expr_.evaluate_with_replacement(resources, instance, resources.root_path_node(), instance, callback); - } - Json evaluate(reference instance, result_options options = result_options()) const { if ((options & result_options::path) == result_options::path) @@ -2592,9 +2578,10 @@ namespace detail { jsoncons::jsonpath::detail::dynamic_resources resources{alloc_}; Json result(json_array_arg, semantic_tag::none, alloc_); - auto callback = [&result](const json_location_type& p, reference) + auto callback = [&result](const path_node_type& path, reference) { - result.emplace_back(p.to_string()); + basic_json_location loc(path); + result.emplace_back(loc.to_string()); }; expr_.evaluate(resources, instance, resources.root_path_node(), instance, callback, options); return result; @@ -2623,6 +2610,7 @@ namespace detail { using const_reference = typename jsonpath_traits_type::const_reference; 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; private: allocator_type alloc_; std::unique_ptr> static_resources_; @@ -2644,7 +2632,7 @@ namespace detail { jsonpath_expr& operator=(jsonpath_expr&&) = default; template - typename std::enable_if::value,void>::type + typename std::enable_if::value,void>::type select_nodes(reference instance, BinaryCallback callback, result_options options = result_options()) const { jsoncons::jsonpath::detail::dynamic_resources resources{alloc_}; @@ -2673,7 +2661,7 @@ namespace detail { } template - typename std::enable_if::value,void>::type + typename std::enable_if::value,void>::type update_nodes(reference instance, BinaryCallback callback) const { jsoncons::jsonpath::detail::dynamic_resources resources{alloc_}; diff --git a/include/jsoncons_ext/jsonpath/jsonpath_selector.hpp b/include/jsoncons_ext/jsonpath/jsonpath_selector.hpp index 8573b22be1..525ea02816 100644 --- a/include/jsoncons_ext/jsonpath/jsonpath_selector.hpp +++ b/include/jsoncons_ext/jsonpath/jsonpath_selector.hpp @@ -583,7 +583,7 @@ namespace detail { if (ancestor != nullptr) { - json_location_type path(*ancestor, resources.get_allocator()); + json_location_type path(*ancestor); pointer ptr = jsoncons::jsonpath::select(root,path); if (ptr != nullptr) { @@ -609,11 +609,11 @@ namespace detail { if (ancestor != nullptr) { - json_location_type path(*ancestor, resources.get_allocator()); + json_location_type path(*ancestor); pointer ptr = jsoncons::jsonpath::select(root,path); if (ptr != nullptr) { - return this->evaluate_tail(resources, root, /*path.last()*/ *ancestor, *ptr, options, ec); + return this->evaluate_tail(resources, root, *ancestor, *ptr, options, ec); } else { diff --git a/test/jsonpath/src/jsonpath_make_expression_tests.cpp b/test/jsonpath/src/jsonpath_make_expression_tests.cpp index b45267d0d9..70214953e0 100644 --- a/test/jsonpath/src/jsonpath_make_expression_tests.cpp +++ b/test/jsonpath/src/jsonpath_make_expression_tests.cpp @@ -60,7 +60,7 @@ TEST_CASE("jsonpath make_expression test") auto expr = jsoncons::jsonpath::make_jsonpath_expr("$.books[*]"); - auto callback = [&](const jsonpath::json_location& /*location*/, const json& book) + auto callback = [&](const jsonpath::path_node& /*location*/, const json& book) { if (book.at("category") == "memoir" && !book.contains("price")) { @@ -82,7 +82,7 @@ TEST_CASE("jsonpath make_expression test") auto expr = jsoncons::jsonpath::make_jsonpath_expr("$.books[*]"); - auto callback1 = [&](const jsonpath::json_location& /*location*/, const json& book) + auto callback1 = [&](const jsonpath::path_node& /*location*/, const json& book) { if (book.at("category") == "memoir" && !book.contains("price")) { @@ -90,7 +90,7 @@ TEST_CASE("jsonpath make_expression test") } }; - auto callback2 = [](const jsonpath::json_location& /*location*/, json& book) + auto callback2 = [](const jsonpath::path_node& /*location*/, json& book) { if (book.at("category") == "memoir" && !book.contains("price")) {