Skip to content

Commit

Permalink
basic_json_location
Browse files Browse the repository at this point in the history
  • Loading branch information
danielaparker committed Nov 8, 2023
1 parent 58ec5db commit 1eead99
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
12 changes: 6 additions & 6 deletions include/jsoncons_ext/jsonpath/expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2070,7 +2070,7 @@ namespace detail {
using reference = JsonReference;
using value_pointer = typename std::conditional<std::is_const<typename std::remove_reference<JsonReference>::type>::value,typename Json::const_pointer,typename Json::pointer>::type;
using path_node_type = path_node<typename Json::char_type>;
using json_location_type = basic_json_location<Json>;
using json_location_type = basic_json_location<char_type,typename Json::allocator_type>;
using path_pointer = const path_node_type*;

json_location_type path_;
Expand Down Expand Up @@ -2131,7 +2131,7 @@ namespace detail {
using reference = JsonReference;
using value_pointer = typename std::conditional<std::is_const<typename std::remove_reference<JsonReference>::type>::value,typename Json::const_pointer,typename Json::pointer>::type;
using path_node_type = path_node<typename Json::char_type>;
using json_location_type = basic_json_location<Json>;
using json_location_type = basic_json_location<char_type,typename Json::allocator_type>;
using path_pointer = const path_node_type*;
private:
const path_node_type* last_ptr_;
Expand Down Expand Up @@ -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<typename Json::char_type>;
using json_location_type = basic_json_location<Json>;
using json_location_type = basic_json_location<char_type,allocator_type>;
using path_value_pair_type = path_value_pair<Json,JsonReference>;

allocator_type alloc_;
Expand Down Expand Up @@ -2320,7 +2320,7 @@ namespace detail {
using pointer = typename std::conditional<std::is_const<typename std::remove_reference<JsonReference>::type>::value,typename Json::const_pointer,typename Json::pointer>::type;
using path_value_pair_type = path_value_pair<Json,JsonReference>;
using path_node_type = path_node<typename Json::char_type>;
using json_location_type = basic_json_location<Json>;
using json_location_type = basic_json_location<char_type,typename Json::allocator_type>;
using node_receiver_type = node_receiver<Json,JsonReference>;
using selector_type = jsonpath_selector<Json,JsonReference>;

Expand Down Expand Up @@ -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<typename Json::char_type>;
using json_location_type = basic_json_location<Json>;
using json_location_type = basic_json_location<char_type,typename Json::allocator_type>;
private:
allocator_type alloc_;
Callback& callback_;
Expand Down Expand Up @@ -3041,7 +3041,7 @@ namespace detail {
using reference_arg_type = typename std::conditional<std::is_const<typename std::remove_reference<JsonReference>::type>::value,
const_reference_arg_t,reference_arg_t>::type;
using path_node_type = path_node<typename Json::char_type>;
using json_location_type = basic_json_location<Json>;
using json_location_type = basic_json_location<char_type,allocator_type>;
using selector_type = jsonpath_selector<Json,JsonReference>;
private:
allocator_type alloc_;
Expand Down
20 changes: 11 additions & 9 deletions include/jsoncons_ext/jsonpath/json_location.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
namespace jsoncons {
namespace jsonpath {

template <class Json>
template <class CharT,class Allocator>
class basic_json_location;

enum class path_node_kind { root, index, name };

template <class CharT>
class path_node
{
template<class Json> friend class basic_json_location;
template <class Ch,class Allocator> friend class basic_json_location;
public:
using string_view_type = jsoncons::basic_string_view<CharT>;
using char_type = CharT;
Expand Down Expand Up @@ -316,13 +316,15 @@ namespace jsonpath {

} // namespace detail

template <class Json>
template <class CharT, class Allocator = std::allocator<char>>
class basic_json_location
{
public:
using allocator_type = typename Json::allocator_type;
using string_type = typename Json::string_type;
using path_node_type = path_node<typename Json::char_type>;
using char_type = CharT;
using allocator_type = Allocator;
using char_allocator_type = typename std::allocator_traits<allocator_type>:: template rebind_alloc<char_type>;
using string_type = std::basic_string<char_type,std::char_traits<char_type>,char_allocator_type>;
using path_node_type = path_node<char_type>;
private:
allocator_type alloc_;
std::vector<const path_node_type*> nodes_;
Expand Down Expand Up @@ -454,7 +456,7 @@ namespace jsonpath {
};

template <class Json>
Json* select(Json& root, const basic_json_location<typename std::remove_cv<Json>::type>& path)
Json* select(Json& root, const basic_json_location<typename Json::char_type,typename Json::allocator_type>& path)
{
Json* current = std::addressof(root);
for (const auto& path_node : path)
Expand Down Expand Up @@ -484,8 +486,8 @@ namespace jsonpath {
return current;
}

using json_location = basic_json_location<json>;
using wjson_location = basic_json_location<wjson>;
using json_location = basic_json_location<char>;
using wjson_location = basic_json_location<wchar_t>;

} // namespace jsonpath
} // namespace jsoncons
Expand Down
6 changes: 3 additions & 3 deletions include/jsoncons_ext/jsonpath/jsonpath_expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ namespace detail {
using token_type = token<Json,JsonReference>;
using path_expression_type = path_expression<Json,JsonReference>;
using expression_type = expression<Json,JsonReference>;
using json_location_type = basic_json_location<Json>;
using json_location_type = basic_json_location<char_type,allocator_type>;
using path_node_type = path_node<typename Json::char_type>;
using selector_type = jsonpath_selector<Json,JsonReference>;

Expand Down Expand Up @@ -2497,7 +2497,7 @@ namespace detail {
using allocator_type = typename value_type::allocator_type;
using evaluator_type = typename jsoncons::jsonpath::detail::jsonpath_evaluator<value_type, reference>;
using path_node_type = path_node<typename Json::char_type>;
using json_location_type = basic_json_location<Json>;
using json_location_type = basic_json_location<typename Json::char_type,typename Json::allocator_type>;
using path_expression_type = jsoncons::jsonpath::detail::path_expression<value_type,reference>;
using path_pointer = const path_node_type*;
};
Expand All @@ -2516,7 +2516,7 @@ namespace detail {
using allocator_type = typename value_type::allocator_type;
using evaluator_type = typename jsoncons::jsonpath::detail::jsonpath_evaluator<value_type, reference>;
using path_node_type = path_node<typename Json::char_type>;
using json_location_type = basic_json_location<Json>;
using json_location_type = basic_json_location<typename Json::char_type,typename Json::allocator_type>;
using path_expression_type = jsoncons::jsonpath::detail::path_expression<value_type,reference>;
using path_pointer = const path_node_type*;
};
Expand Down

0 comments on commit 1eead99

Please sign in to comment.