From c7ef160356685c8ca8bc68413669ff717f5706dc Mon Sep 17 00:00:00 2001 From: Daniel Parker Date: Mon, 13 Nov 2023 22:53:12 -0500 Subject: [PATCH] json_location --- include/jsoncons/json_location.hpp | 42 ++++++++++++--------- include/jsoncons_ext/jsonpath/path_node.hpp | 4 -- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/include/jsoncons/json_location.hpp b/include/jsoncons/json_location.hpp index ffc12f87c3..04776f0e94 100644 --- a/include/jsoncons/json_location.hpp +++ b/include/jsoncons/json_location.hpp @@ -20,34 +20,45 @@ namespace jsoncons { template class basic_json_location; - enum class location_element_kind { root, index, name }; + enum class location_element_kind { root, name, index }; - template + template class basic_location_element { template friend class basic_json_location; public: using char_type = CharT; - using string_view_type = jsoncons::basic_string_view; + using allocator_type = Allocator; + using char_allocator_type = typename std::allocator_traits:: template rebind_alloc; + using string_type = std::basic_string,char_allocator_type>; private: location_element_kind node_kind_; - string_view_type name_; + string_type name_; std::size_t index_; public: - basic_location_element() = default; - - basic_location_element(location_element_kind node_kind, string_view_type name, std::size_t index) + basic_location_element(location_element_kind node_kind, + const string_type& name, std::size_t index) : node_kind_(node_kind), name_(name), index_(index) { } + basic_location_element(location_element_kind node_kind, + string_type&& name, std::size_t index) + : node_kind_(node_kind), name_(std::move(name)), index_(index) + { + } + + basic_location_element(const basic_location_element& other) = default; + + basic_location_element& operator=(const basic_location_element& other) = default; + location_element_kind node_kind() const { return node_kind_; } - const string_view_type& name() const + const string_type& name() const { return name_; } @@ -57,19 +68,16 @@ namespace jsoncons { return index_; } - basic_location_element(const basic_location_element&) = default; - basic_location_element& operator=(const basic_location_element&) = default; - private: std::size_t node_hash() const { - std::size_t h = node_kind_ == location_element_kind::index ? std::hash{}(index_) : std::hash{}(name_); + std::size_t h = node_kind_ == location_element_kind::index ? std::hash{}(index_) : std::hash{}(name_); return h; } - int compare_node(const basic_location_element& other) const + int compare(const basic_location_element& other) const { int diff = 0; if (node_kind_ != other.node_kind_) @@ -103,7 +111,7 @@ namespace jsoncons { 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 location_element_type = basic_location_element; + using location_element_type = basic_location_element; using location_element_allocator_type = typename std::allocator_traits:: template rebind_alloc; private: allocator_type alloc_; @@ -143,7 +151,7 @@ namespace jsoncons { auto it2 = other.elements_.begin(); while (it1 != elements_.end() && it2 != other.elements_.end()) { - int diff = it1->compare_node(*it2); + int diff = it1->compare(*it2); if (diff != 0) { return diff; @@ -188,8 +196,8 @@ namespace jsoncons { using json_location = basic_json_location; using wjson_location = basic_json_location; - using location_element = basic_location_element; - using wlocation_element = basic_location_element; + using location_element = basic_location_element>; + using wlocation_element = basic_location_element>; } // namespace jsoncons diff --git a/include/jsoncons_ext/jsonpath/path_node.hpp b/include/jsoncons_ext/jsonpath/path_node.hpp index 599c158cbb..be51a3c852 100644 --- a/include/jsoncons_ext/jsonpath/path_node.hpp +++ b/include/jsoncons_ext/jsonpath/path_node.hpp @@ -319,10 +319,6 @@ namespace jsonpath { return buffer; } - using json_location = basic_json_location; - using wjson_location = basic_json_location; - using location_element = basic_location_element; - using wlocation_element = basic_location_element; using path_node = basic_path_node; using wpath_node = basic_path_node;