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 b0727bd commit 58ec5db
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 22 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 = json_location<Json>;
using json_location_type = basic_json_location<Json>;
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 = json_location<Json>;
using json_location_type = basic_json_location<Json>;
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 = json_location<Json>;
using json_location_type = basic_json_location<Json>;
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 = json_location<Json>;
using json_location_type = basic_json_location<Json>;
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 = json_location<Json>;
using json_location_type = basic_json_location<Json>;
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 = json_location<Json>;
using json_location_type = basic_json_location<Json>;
using selector_type = jsonpath_selector<Json,JsonReference>;
private:
allocator_type alloc_;
Expand Down
21 changes: 12 additions & 9 deletions include/jsoncons_ext/jsonpath/json_location.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ namespace jsoncons {
namespace jsonpath {

template <class Json>
class json_location;
class basic_json_location;

enum class path_node_kind { root, index, name };

template <class CharT>
class path_node
{
template<class Json> friend class json_location;
template<class Json> friend class basic_json_location;
public:
using string_view_type = jsoncons::basic_string_view<CharT>;
using char_type = CharT;
Expand Down Expand Up @@ -317,7 +317,7 @@ namespace jsonpath {
} // namespace detail

template <class Json>
class json_location
class basic_json_location
{
public:
using allocator_type = typename Json::allocator_type;
Expand All @@ -330,7 +330,7 @@ namespace jsonpath {
using iterator = typename detail::json_location_iterator<typename std::vector<const path_node_type*>::iterator>;
using const_iterator = typename detail::json_location_iterator<typename std::vector<const path_node_type*>::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();
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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 <class Json>
Json* select(Json& root, const json_location<typename std::remove_cv<Json>::type>& path)
Json* select(Json& root, const basic_json_location<typename std::remove_cv<Json>::type>& path)
{
Json* current = std::addressof(root);
for (const auto& path_node : path)
Expand Down Expand Up @@ -484,6 +484,9 @@ namespace jsonpath {
return current;
}

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

} // 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 = json_location<Json>;
using json_location_type = basic_json_location<Json>;
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 = json_location<Json>;
using json_location_type = basic_json_location<Json>;
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 = json_location<Json>;
using json_location_type = basic_json_location<Json>;
using path_expression_type = jsoncons::jsonpath::detail::path_expression<value_type,reference>;
using path_pointer = const path_node_type*;
};
Expand Down
2 changes: 1 addition & 1 deletion test/jsonpath/src/json_location_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <iostream>

using path_node = jsoncons::jsonpath::path_node<char>;
using json_location = jsoncons::jsonpath::json_location<jsoncons::json>;
using jsoncons::jsonpath::json_location;

TEST_CASE("test json_location equals")
{
Expand Down
6 changes: 3 additions & 3 deletions test/jsonpath/src/jsonpath_make_expression_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ TEST_CASE("jsonpath make_expression test")

auto expr = jsoncons::jsonpath::make_update_expression<const json>("$.books[*]");

auto callback = [&](const jsonpath::json_location<json>& /*location*/, const json& book)
auto callback = [&](const jsonpath::json_location& /*location*/, const json& book)
{
if (book.at("category") == "memoir" && !book.contains("price"))
{
Expand All @@ -82,15 +82,15 @@ TEST_CASE("jsonpath make_expression test")

auto expr = jsoncons::jsonpath::make_update_expression<json>("$.books[*]");

auto callback1 = [&](const jsonpath::json_location<json>& /*location*/, const json& book)
auto callback1 = [&](const jsonpath::json_location& /*location*/, const json& book)
{
if (book.at("category") == "memoir" && !book.contains("price"))
{
++count;
}
};

auto callback2 = [](const jsonpath::json_location<json>& /*location*/, json& book)
auto callback2 = [](const jsonpath::json_location& /*location*/, json& book)
{
if (book.at("category") == "memoir" && !book.contains("price"))
{
Expand Down

0 comments on commit 58ec5db

Please sign in to comment.