From 58ec5dbf495ad761f976360b0841a6a5da209ad1 Mon Sep 17 00:00:00 2001 From: Daniel Parker Date: Wed, 8 Nov 2023 12:16:47 -0500 Subject: [PATCH] basic_json_location --- include/jsoncons_ext/jsonpath/expression.hpp | 12 +++++------ .../jsoncons_ext/jsonpath/json_location.hpp | 21 +++++++++++-------- .../jsonpath/jsonpath_expression.hpp | 6 +++--- test/jsonpath/src/json_location_tests.cpp | 2 +- .../src/jsonpath_make_expression_tests.cpp | 6 +++--- 5 files changed, 25 insertions(+), 22 deletions(-) diff --git a/include/jsoncons_ext/jsonpath/expression.hpp b/include/jsoncons_ext/jsonpath/expression.hpp index 15e5e1ba51..3170c7c3d3 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 = path_node; - using json_location_type = 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 = path_node; - using json_location_type = 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 = path_node; - using json_location_type = json_location; + using json_location_type = basic_json_location; using path_value_pair_type = path_value_pair; allocator_type alloc_; @@ -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 = path_node; - using json_location_type = 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 = path_node; - using json_location_type = json_location; + using json_location_type = basic_json_location; private: allocator_type alloc_; Callback& callback_; @@ -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 = path_node; - using json_location_type = json_location; + using json_location_type = basic_json_location; using selector_type = jsonpath_selector; private: allocator_type alloc_; diff --git a/include/jsoncons_ext/jsonpath/json_location.hpp b/include/jsoncons_ext/jsonpath/json_location.hpp index 21b2d718de..b8f56f9eec 100644 --- a/include/jsoncons_ext/jsonpath/json_location.hpp +++ b/include/jsoncons_ext/jsonpath/json_location.hpp @@ -21,14 +21,14 @@ namespace jsoncons { namespace jsonpath { template - class json_location; + class basic_json_location; enum class path_node_kind { root, index, name }; template class path_node { - template friend class json_location; + template friend class basic_json_location; public: using string_view_type = jsoncons::basic_string_view; using char_type = CharT; @@ -317,7 +317,7 @@ namespace jsonpath { } // namespace detail template - class json_location + class basic_json_location { public: using allocator_type = typename Json::allocator_type; @@ -330,7 +330,7 @@ namespace jsonpath { using iterator = typename detail::json_location_iterator::iterator>; using const_iterator = typename detail::json_location_iterator::const_iterator>; - json_location(const path_node_type& node, const allocator_type& alloc = allocator_type()) + basic_json_location(const path_node_type& node, const allocator_type& alloc = allocator_type()) : alloc_(alloc) { std::size_t len = node.size(); @@ -399,7 +399,7 @@ namespace jsonpath { return buffer; } - int compare(const json_location& other) const + int compare(const basic_json_location& other) const { if (this == &other) { @@ -437,24 +437,24 @@ namespace jsonpath { return hash; } - friend bool operator==(const json_location& lhs, const json_location& rhs) + friend bool operator==(const basic_json_location& lhs, const basic_json_location& rhs) { return lhs.compare(rhs) == 0; } - friend bool operator!=(const json_location& lhs, const json_location& rhs) + friend bool operator!=(const basic_json_location& lhs, const basic_json_location& rhs) { return !(lhs == rhs); } - friend bool operator<(const json_location& lhs, const json_location& rhs) + friend bool operator<(const basic_json_location& lhs, const basic_json_location& rhs) { return lhs.compare(rhs) < 0; } }; template - Json* select(Json& root, const json_location::type>& path) + Json* select(Json& root, const basic_json_location::type>& path) { Json* current = std::addressof(root); for (const auto& path_node : path) @@ -484,6 +484,9 @@ namespace jsonpath { return current; } + using json_location = basic_json_location; + using wjson_location = basic_json_location; + } // namespace jsonpath } // namespace jsoncons diff --git a/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp b/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp index 3d6f7c01b7..31cbb5190d 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 = json_location; + using json_location_type = basic_json_location; using path_node_type = 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 = path_node; - using json_location_type = 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 = path_node; - using json_location_type = 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*; }; diff --git a/test/jsonpath/src/json_location_tests.cpp b/test/jsonpath/src/json_location_tests.cpp index 9de4a59fca..877c44b043 100644 --- a/test/jsonpath/src/json_location_tests.cpp +++ b/test/jsonpath/src/json_location_tests.cpp @@ -10,7 +10,7 @@ #include using path_node = jsoncons::jsonpath::path_node; -using json_location = jsoncons::jsonpath::json_location; +using jsoncons::jsonpath::json_location; TEST_CASE("test json_location equals") { diff --git a/test/jsonpath/src/jsonpath_make_expression_tests.cpp b/test/jsonpath/src/jsonpath_make_expression_tests.cpp index c37e278613..66adab38e9 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")) {