diff --git a/include/jsoncons_ext/jsonpath/expression.hpp b/include/jsoncons_ext/jsonpath/expression.hpp index e8e59760a7..dd08c2d12a 100644 --- a/include/jsoncons_ext/jsonpath/expression.hpp +++ b/include/jsoncons_ext/jsonpath/expression.hpp @@ -2069,7 +2069,7 @@ 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 path_node_type = basic_path_node; using json_location_type = basic_json_location; using path_pointer = const path_node_type*; @@ -2130,7 +2130,7 @@ 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 path_node_type = basic_path_node; using json_location_type = basic_json_location; using path_pointer = const path_node_type*; private: @@ -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 = basic_path_node; virtual ~node_receiver() noexcept = default; @@ -2176,7 +2176,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 = basic_path_node; using json_location_type = basic_json_location; using path_value_pair_type = path_value_pair; @@ -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 = basic_path_node; using path_component_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 = basic_path_node; using path_component_value_pair_type = path_component_value_pair; allocator_type alloc_; @@ -2319,7 +2319,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 = basic_path_node; using json_location_type = basic_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 = basic_path_node; virtual ~expression_base() noexcept = default; @@ -3004,7 +3004,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 = basic_path_node; using json_location_type = basic_json_location; private: allocator_type alloc_; @@ -3040,7 +3040,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 = basic_path_node; using json_location_type = basic_json_location; using selector_type = jsonpath_selector; private: @@ -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 = basic_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 de10ab9f32..4d40bbca77 100644 --- a/include/jsoncons_ext/jsonpath/json_location.hpp +++ b/include/jsoncons_ext/jsonpath/json_location.hpp @@ -26,7 +26,7 @@ namespace jsonpath { enum class path_node_kind { root, index, name }; template - class path_node + class basic_path_node { template friend class basic_json_location; public: @@ -35,30 +35,30 @@ namespace jsonpath { private: char_type root_; - const path_node* parent_; + const basic_path_node* parent_; path_node_kind node_kind_; string_view_type name_; std::size_t index_; public: - path_node(char_type root) + basic_path_node(char_type root) : root_{root}, parent_(nullptr), node_kind_(path_node_kind::root), name_(&root_,1), index_(0) { } - path_node(const path_node* parent, const string_view_type& name) + basic_path_node(const basic_path_node* parent, const string_view_type& name) : root_(0), parent_(parent), node_kind_(path_node_kind::name), name_(name), index_(0) { } - path_node(const path_node* parent, std::size_t index) + basic_path_node(const basic_path_node* parent, std::size_t index) : root_(0), parent_(parent), node_kind_(path_node_kind::index), index_(index) { } - path_node(const path_node& other) + basic_path_node(const basic_path_node& other) : root_(other.root_), parent_(other.parent_), node_kind_(other.node_kind_), @@ -67,7 +67,7 @@ namespace jsonpath { { } - path_node(path_node&& other) + basic_path_node(basic_path_node&& other) : root_(other.root_), parent_(other.parent_), node_kind_(other.node_kind_), @@ -76,7 +76,7 @@ namespace jsonpath { { } - path_node& operator=(const path_node& other) + basic_path_node& operator=(const basic_path_node& other) { root_ = other.root_; parent_ = other.parent_; @@ -86,7 +86,7 @@ namespace jsonpath { return *this; } - path_node& operator=(path_node&& other) + basic_path_node& operator=(basic_path_node&& other) { root_ = other.root_; parent_ = other.parent_; @@ -96,7 +96,7 @@ namespace jsonpath { return *this; } - const path_node* parent() const { return parent_;} + const basic_path_node* parent() const { return parent_;} path_node_kind node_kind() const { @@ -124,7 +124,7 @@ namespace jsonpath { return index_; } - void swap(path_node& node) + void swap(basic_path_node& node) { std::swap(parent_, node.parent_); std::swap(node_kind_, node.node_kind_); @@ -141,7 +141,7 @@ namespace jsonpath { return h; } - int compare_node(const path_node& other) const + int compare_node(const basic_path_node& other) const { int diff = 0; if (node_kind_ != other.node_kind_) @@ -248,7 +248,7 @@ namespace jsonpath { using allocator_type = Allocator; using char_allocator_type = typename std::allocator_traits:: template rebind_alloc; using string_type = std::basic_string,char_allocator_type>; - using path_node_type = path_node; + using path_node_type = basic_path_node; using path_element_type = basic_path_element; using path_element_allocator_type = typename std::allocator_traits:: template rebind_alloc; private: @@ -384,23 +384,23 @@ namespace jsonpath { Json* select(Json& root, const basic_json_location& path) { Json* current = std::addressof(root); - for (const auto& path_node : path) + for (const auto& basic_path_node : path) { - if (path_node.node_kind() == path_node_kind::index) + if (basic_path_node.node_kind() == path_node_kind::index) { - if (current->type() != json_type::array_value || path_node.index() >= current->size()) + if (current->type() != json_type::array_value || basic_path_node.index() >= current->size()) { return nullptr; } - current = std::addressof(current->at(path_node.index())); + current = std::addressof(current->at(basic_path_node.index())); } - else if (path_node.node_kind() == path_node_kind::name) + else if (basic_path_node.node_kind() == path_node_kind::name) { if (current->type() != json_type::object_value) { return nullptr; } - auto it = current->find(path_node.name()); + auto it = current->find(basic_path_node.name()); if (it == current->object_range().end()) { return nullptr; @@ -415,6 +415,8 @@ namespace jsonpath { using wjson_location = basic_json_location; using path_element = basic_path_element; using wpath_element = basic_path_element; + using path_node = basic_path_node; + using wpath_node = basic_path_node; } // namespace jsonpath } // namespace jsoncons diff --git a/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp b/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp index 4120a155b6..18a052f640 100644 --- a/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp +++ b/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp @@ -112,7 +112,7 @@ namespace detail { using path_expression_type = path_expression; using expression_type = expression; using json_location_type = basic_json_location; - using path_node_type = path_node; + using path_node_type = basic_path_node; using selector_type = jsonpath_selector; private: @@ -2496,7 +2496,7 @@ 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 path_node_type = basic_path_node; using json_location_type = basic_json_location; using path_expression_type = jsoncons::jsonpath::detail::path_expression; using path_pointer = const path_node_type*; @@ -2515,7 +2515,7 @@ 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 path_node_type = basic_path_node; 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/include/jsoncons_ext/jsonpath/jsonpath_selector.hpp b/include/jsoncons_ext/jsonpath/jsonpath_selector.hpp index e08529b5c0..8573b22be1 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 = basic_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 = basic_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 877c44b043..3a6220c9af 100644 --- a/test/jsonpath/src/json_location_tests.cpp +++ b/test/jsonpath/src/json_location_tests.cpp @@ -9,20 +9,20 @@ #include #include -using path_node = jsoncons::jsonpath::path_node; +using basic_path_node = jsoncons::jsonpath::basic_path_node; using jsoncons::jsonpath::json_location; TEST_CASE("test json_location equals") { - path_node component1('$'); - path_node component2(&component1,"foo"); - path_node component3(&component2,"bar"); - path_node component4(&component3,0); + basic_path_node component1('$'); + basic_path_node component2(&component1,"foo"); + basic_path_node component3(&component2,"bar"); + basic_path_node component4(&component3,0); - path_node component11('$'); - path_node component12(&component11,"foo"); - path_node component13(&component12,"bar"); - path_node component14(&component13,0); + basic_path_node component11('$'); + basic_path_node component12(&component11,"foo"); + basic_path_node component13(&component12,"bar"); + basic_path_node component14(&component13,0); json_location path1(component4); json_location path2(component14); @@ -32,10 +32,10 @@ TEST_CASE("test json_location equals") TEST_CASE("test json_location to_string") { - path_node component1('$'); - path_node component2(&component1,"foo"); - path_node component3(&component2,"bar"); - path_node component4(&component3,0); + basic_path_node component1('$'); + basic_path_node component2(&component1,"foo"); + basic_path_node component3(&component2,"bar"); + basic_path_node component4(&component3,0); json_location path1(component4); @@ -44,10 +44,10 @@ TEST_CASE("test json_location to_string") TEST_CASE("test json_location with solidus to_string") { - path_node component1('$'); - path_node component2(&component1,"foo's"); - path_node component3(&component2,"bar"); - path_node component4(&component3,0); + basic_path_node component1('$'); + basic_path_node component2(&component1,"foo's"); + basic_path_node component3(&component2,"bar"); + basic_path_node component4(&component3,0); json_location path1(component4);