From 730aeb7b9072e64aae98bab361e5e557a24fd0e8 Mon Sep 17 00:00:00 2001 From: Daniel Parker Date: Fri, 3 Nov 2023 16:49:27 -0400 Subject: [PATCH] make_expression --- include/jsoncons_ext/jsonpath/expression.hpp | 34 +++++++++---------- .../jsoncons_ext/jsonpath/json_location.hpp | 20 +++++------ .../jsonpath/jsonpath_expression.hpp | 12 +++---- .../jsonpath/jsonpath_selector.hpp | 4 +-- test/jsonpath/src/json_location_tests.cpp | 7 ++-- .../src/jsonpath_make_expression_tests.cpp | 6 ++-- 6 files changed, 42 insertions(+), 41 deletions(-) diff --git a/include/jsoncons_ext/jsonpath/expression.hpp b/include/jsoncons_ext/jsonpath/expression.hpp index e3c7ad8c3a..4c06d6d278 100644 --- a/include/jsoncons_ext/jsonpath/expression.hpp +++ b/include/jsoncons_ext/jsonpath/expression.hpp @@ -2069,8 +2069,8 @@ namespace detail { using value_type = Json; using reference = JsonReference; using value_pointer = typename std::conditional::type>::value,typename Json::const_pointer,typename Json::pointer>::type; - using path_node_type = path_node; - using json_location_type = json_location; + using path_node_type = path_node; + using json_location_type = json_location; using path_pointer = const path_node_type*; json_location_type path_; @@ -2130,8 +2130,8 @@ namespace detail { using value_type = Json; using reference = JsonReference; using value_pointer = typename std::conditional::type>::value,typename Json::const_pointer,typename Json::pointer>::type; - using path_node_type = path_node; - using json_location_type = json_location; + using path_node_type = path_node; + using json_location_type = json_location; using path_pointer = const path_node_type*; private: const path_node_type* last_ptr_; @@ -2160,7 +2160,7 @@ namespace detail { using char_type = typename Json::char_type; using string_type = typename Json::string_type; using reference = JsonReference; - using path_node_type = path_node; + using path_node_type = path_node; virtual ~node_receiver() noexcept = default; @@ -2176,8 +2176,8 @@ namespace detail { using reference = JsonReference; using char_type = typename Json::char_type; using string_type = typename Json::string_type; - using path_node_type = path_node; - using json_location_type = json_location; + using path_node_type = path_node; + using json_location_type = json_location; using path_value_pair_type = path_value_pair; allocator_type alloc_; @@ -2202,7 +2202,7 @@ namespace detail { using reference = JsonReference; using char_type = typename Json::char_type; using string_type = typename Json::string_type; - using path_node_type = path_node; + using path_node_type = path_node; using path_stem_value_pair_type = path_component_value_pair; std::vector nodes; @@ -2222,7 +2222,7 @@ namespace detail { using string_type = typename Json::string_type; using reference = JsonReference; using pointer = typename std::conditional::type>::value,typename Json::const_pointer,typename Json::pointer>::type; - using path_node_type = path_node; + using path_node_type = path_node; using path_stem_value_pair_type = path_component_value_pair; allocator_type alloc_; @@ -2319,8 +2319,8 @@ namespace detail { using reference = JsonReference; 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 = path_node; - using json_location_type = json_location; + using path_node_type = path_node; + using json_location_type = json_location; using node_receiver_type = node_receiver; using selector_type = jsonpath_selector; @@ -2623,7 +2623,7 @@ namespace detail { using reference = JsonReference; 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 = path_node; + using path_node_type = path_node; virtual ~expression_base() noexcept = default; @@ -3004,8 +3004,8 @@ namespace detail { using reference = JsonReference; using char_type = typename Json::char_type; using string_type = typename Json::string_type; - using path_node_type = path_node; - using json_location_type = json_location; + using path_node_type = path_node; + using json_location_type = json_location; private: allocator_type alloc_; Callback& callback_; @@ -3040,8 +3040,8 @@ namespace detail { using token_type = token; using reference_arg_type = typename std::conditional::type>::value, const_reference_arg_t,reference_arg_t>::type; - using path_node_type = path_node; - using json_location_type = json_location; + using path_node_type = path_node; + using json_location_type = json_location; using selector_type = jsonpath_selector; private: allocator_type alloc_; @@ -3238,7 +3238,7 @@ namespace detail { using token_type = token; using reference_arg_type = typename std::conditional::type>::value, const_reference_arg_t,reference_arg_t>::type; - using path_node_type = path_node; + using path_node_type = path_node; using stack_item_type = value_or_pointer; private: std::vector token_list_; diff --git a/include/jsoncons_ext/jsonpath/json_location.hpp b/include/jsoncons_ext/jsonpath/json_location.hpp index b198b92416..4215e70c19 100644 --- a/include/jsoncons_ext/jsonpath/json_location.hpp +++ b/include/jsoncons_ext/jsonpath/json_location.hpp @@ -20,18 +20,18 @@ namespace jsoncons { namespace jsonpath { - template + template class json_location; enum class path_node_kind { root, index, name }; - template + template class path_node { - friend class json_location; + friend class json_location; public: - using string_type = StringT; - using char_type = typename StringT::value_type; + using string_type = typename Json::string_type; + using char_type = typename string_type::value_type; private: const path_node* parent_; @@ -265,13 +265,13 @@ namespace jsonpath { } // namespace detail - template + template class json_location { public: - using allocator_type = typename StringT::allocator_type; - using string_type = StringT; - using path_node_type = path_node; + using allocator_type = typename Json::allocator_type; + using string_type = typename Json::string_type; + using path_node_type = path_node; private: allocator_type alloc_; std::vector nodes_; @@ -402,7 +402,7 @@ namespace jsonpath { }; template - Json* select(Json& root, const json_location& path) + Json* select(Json& root, const json_location::type>& path) { Json* current = std::addressof(root); for (const auto& path_node : path) diff --git a/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp b/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp index 389b3bb572..a8da2258ee 100644 --- a/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp +++ b/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp @@ -111,8 +111,8 @@ namespace detail { using token_type = token; using path_expression_type = path_expression; using expression_type = expression; - using json_location_type = json_location; - using path_node_type = path_node; + using json_location_type = json_location; + using path_node_type = path_node; using selector_type = jsonpath_selector; private: @@ -2496,8 +2496,8 @@ namespace detail { using pointer = typename std::conditional::type>::value, typename Json::const_pointer, typename Json::pointer>::type; using allocator_type = typename value_type::allocator_type; using evaluator_type = typename jsoncons::jsonpath::detail::jsonpath_evaluator; - using path_node_type = path_node; - using json_location_type = json_location; + using path_node_type = path_node; + using json_location_type = json_location; using path_expression_type = jsoncons::jsonpath::detail::path_expression; using path_pointer = const path_node_type*; }; @@ -2515,8 +2515,8 @@ namespace detail { using pointer = typename std::conditional::type>::value, typename Json::const_pointer, typename Json::pointer>::type; using allocator_type = typename value_type::allocator_type; using evaluator_type = typename jsoncons::jsonpath::detail::jsonpath_evaluator; - using path_node_type = path_node; - using json_location_type = json_location; + using path_node_type = path_node; + using json_location_type = json_location; using path_expression_type = jsoncons::jsonpath::detail::path_expression; using path_pointer = const path_node_type*; }; diff --git a/include/jsoncons_ext/jsonpath/jsonpath_selector.hpp b/include/jsoncons_ext/jsonpath/jsonpath_selector.hpp index 56c29079a0..caee3d300a 100644 --- a/include/jsoncons_ext/jsonpath/jsonpath_selector.hpp +++ b/include/jsoncons_ext/jsonpath/jsonpath_selector.hpp @@ -114,7 +114,7 @@ namespace detail { using reference = JsonReference; using char_type = typename Json::char_type; using string_type = typename Json::string_type; - using path_node_type = path_node; + using path_node_type = path_node; Json* val; @@ -135,7 +135,7 @@ namespace detail { using char_type = typename Json::char_type; using string_view_type = typename Json::string_view_type; using string_type = typename Json::string_type; - using path_node_type = path_node; + using path_node_type = path_node; static const path_node_type& generate(dynamic_resources& resources, const path_node_type& last, diff --git a/test/jsonpath/src/json_location_tests.cpp b/test/jsonpath/src/json_location_tests.cpp index 011e81b265..6763269184 100644 --- a/test/jsonpath/src/json_location_tests.cpp +++ b/test/jsonpath/src/json_location_tests.cpp @@ -4,12 +4,13 @@ #if defined(_MSC_VER) #include "windows.h" // test no inadvertant macro expansions #endif +#include #include #include #include -using path_node = jsoncons::jsonpath::path_node; -using json_location = jsoncons::jsonpath::json_location; +using path_node = jsoncons::jsonpath::path_node; +using json_location = jsoncons::jsonpath::json_location; TEST_CASE("test json_location equals") { @@ -26,7 +27,7 @@ TEST_CASE("test json_location equals") json_location path1(component4); json_location path2(component14); - CHECK(path1 == path2); + CHECK((path1 == path2)); } TEST_CASE("test json_location to_string") diff --git a/test/jsonpath/src/jsonpath_make_expression_tests.cpp b/test/jsonpath/src/jsonpath_make_expression_tests.cpp index 73a9b798d0..140ae65943 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_update_expression("$.books[*]"); - auto callback = [&](const jsonpath::json_location& /*location*/, const json& book) + auto callback = [&](const jsonpath::json_location& /*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_update_expression("$.books[*]"); - auto callback1 = [&](const jsonpath::json_location& /*location*/, const json& book) + auto callback1 = [&](const jsonpath::json_location& /*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::json_location& /*location*/, json& book) { if (book.at("category") == "memoir" && !book.contains("price")) {