Skip to content

Commit

Permalink
make_expression<json>
Browse files Browse the repository at this point in the history
  • Loading branch information
danielaparker committed Nov 3, 2023
1 parent fe96ada commit 730aeb7
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 41 deletions.
34 changes: 17 additions & 17 deletions include/jsoncons_ext/jsonpath/expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2069,8 +2069,8 @@ namespace detail {
using value_type = Json;
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<string_type>;
using json_location_type = json_location<string_type>;
using path_node_type = path_node<Json>;
using json_location_type = json_location<value_type>;
using path_pointer = const path_node_type*;

json_location_type path_;
Expand Down Expand Up @@ -2130,8 +2130,8 @@ namespace detail {
using value_type = Json;
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<string_type>;
using json_location_type = json_location<string_type>;
using path_node_type = path_node<Json>;
using json_location_type = json_location<value_type>;
using path_pointer = const path_node_type*;
private:
const path_node_type* last_ptr_;
Expand Down Expand Up @@ -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<string_type>;
using path_node_type = path_node<Json>;

virtual ~node_receiver() noexcept = default;

Expand All @@ -2176,8 +2176,8 @@ 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<string_type>;
using json_location_type = json_location<string_type>;
using path_node_type = path_node<Json>;
using json_location_type = json_location<Json>;
using path_value_pair_type = path_value_pair<Json,JsonReference>;

allocator_type alloc_;
Expand All @@ -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<string_type>;
using path_node_type = path_node<Json>;
using path_stem_value_pair_type = path_component_value_pair<Json,JsonReference>;

std::vector<path_stem_value_pair_type> nodes;
Expand All @@ -2222,7 +2222,7 @@ namespace detail {
using string_type = typename Json::string_type;
using reference = JsonReference;
using pointer = typename std::conditional<std::is_const<typename std::remove_reference<reference>::type>::value,typename Json::const_pointer,typename Json::pointer>::type;
using path_node_type = path_node<string_type>;
using path_node_type = path_node<Json>;
using path_stem_value_pair_type = path_component_value_pair<Json,JsonReference>;

allocator_type alloc_;
Expand Down Expand Up @@ -2319,8 +2319,8 @@ namespace detail {
using reference = JsonReference;
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<string_type>;
using json_location_type = json_location<string_type>;
using path_node_type = path_node<Json>;
using json_location_type = json_location<Json>;
using node_receiver_type = node_receiver<Json,JsonReference>;
using selector_type = jsonpath_selector<Json,JsonReference>;

Expand Down Expand Up @@ -2623,7 +2623,7 @@ namespace detail {
using reference = JsonReference;
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<string_type>;
using path_node_type = path_node<Json>;

virtual ~expression_base() noexcept = default;

Expand Down Expand Up @@ -3004,8 +3004,8 @@ 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<string_type>;
using json_location_type = json_location<string_type>;
using path_node_type = path_node<Json>;
using json_location_type = json_location<Json>;
private:
allocator_type alloc_;
Callback& callback_;
Expand Down Expand Up @@ -3040,8 +3040,8 @@ namespace detail {
using token_type = token<Json,JsonReference>;
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<string_type>;
using json_location_type = json_location<string_type>;
using path_node_type = path_node<Json>;
using json_location_type = json_location<Json>;
using selector_type = jsonpath_selector<Json,JsonReference>;
private:
allocator_type alloc_;
Expand Down Expand Up @@ -3238,7 +3238,7 @@ namespace detail {
using token_type = token<Json,reference>;
using reference_arg_type = typename std::conditional<std::is_const<typename std::remove_reference<reference>::type>::value,
const_reference_arg_t,reference_arg_t>::type;
using path_node_type = path_node<string_type>;
using path_node_type = path_node<Json>;
using stack_item_type = value_or_pointer<Json,JsonReference>;
private:
std::vector<token_type> token_list_;
Expand Down
20 changes: 10 additions & 10 deletions include/jsoncons_ext/jsonpath/json_location.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@
namespace jsoncons {
namespace jsonpath {

template <class StringT>
template <class Json>
class json_location;

enum class path_node_kind { root, index, name };

template <class StringT>
template <class Json>
class path_node
{
friend class json_location<StringT>;
friend class json_location<Json>;
public:
using string_type = StringT;
using char_type = typename StringT::value_type;
using string_type = typename Json::string_type;
using char_type = typename string_type::value_type;
private:

const path_node* parent_;
Expand Down Expand Up @@ -265,13 +265,13 @@ namespace jsonpath {

} // namespace detail

template <class StringT>
template <class Json>
class json_location
{
public:
using allocator_type = typename StringT::allocator_type;
using string_type = StringT;
using path_node_type = path_node<StringT>;
using allocator_type = typename Json::allocator_type;
using string_type = typename Json::string_type;
using path_node_type = path_node<Json>;
private:
allocator_type alloc_;
std::vector<const path_node_type*> nodes_;
Expand Down Expand Up @@ -402,7 +402,7 @@ namespace jsonpath {
};

template <class Json>
Json* select(Json& root, const json_location<typename Json::string_type>& path)
Json* select(Json& root, const json_location<typename std::remove_cv<Json>::type>& path)
{
Json* current = std::addressof(root);
for (const auto& path_node : path)
Expand Down
12 changes: 6 additions & 6 deletions include/jsoncons_ext/jsonpath/jsonpath_expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ 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<string_type>;
using path_node_type = path_node<string_type>;
using json_location_type = json_location<Json>;
using path_node_type = path_node<Json>;
using selector_type = jsonpath_selector<Json,JsonReference>;

private:
Expand Down Expand Up @@ -2496,8 +2496,8 @@ namespace detail {
using pointer = typename std::conditional<std::is_const<typename std::remove_reference<reference>::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<value_type, reference>;
using path_node_type = path_node<string_type>;
using json_location_type = json_location<string_type>;
using path_node_type = path_node<Json>;
using json_location_type = json_location<value_type>;
using path_expression_type = jsoncons::jsonpath::detail::path_expression<value_type,reference>;
using path_pointer = const path_node_type*;
};
Expand All @@ -2515,8 +2515,8 @@ namespace detail {
using pointer = typename std::conditional<std::is_const<typename std::remove_reference<reference>::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<value_type, reference>;
using path_node_type = path_node<string_type>;
using json_location_type = json_location<string_type>;
using path_node_type = path_node<Json>;
using json_location_type = json_location<value_type>;
using path_expression_type = jsoncons::jsonpath::detail::path_expression<value_type,reference>;
using path_pointer = const path_node_type*;
};
Expand Down
4 changes: 2 additions & 2 deletions include/jsoncons_ext/jsonpath/jsonpath_selector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<string_type>;
using path_node_type = path_node<Json>;

Json* val;

Expand All @@ -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<string_type>;
using path_node_type = path_node<Json>;

static const path_node_type& generate(dynamic_resources<Json,JsonReference>& resources,
const path_node_type& last,
Expand Down
7 changes: 4 additions & 3 deletions test/jsonpath/src/json_location_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
#if defined(_MSC_VER)
#include "windows.h" // test no inadvertant macro expansions
#endif
#include <jsoncons/json.hpp>
#include <jsoncons_ext/jsonpath/json_location.hpp>
#include <catch/catch.hpp>
#include <iostream>

using path_node = jsoncons::jsonpath::path_node<std::string>;
using json_location = jsoncons::jsonpath::json_location<std::string>;
using path_node = jsoncons::jsonpath::path_node<jsoncons::json>;
using json_location = jsoncons::jsonpath::json_location<jsoncons::json>;

TEST_CASE("test json_location equals")
{
Expand All @@ -26,7 +27,7 @@ TEST_CASE("test json_location equals")
json_location path1(component4);
json_location path2(component14);

CHECK(path1 == path2);
CHECK((path1 == path2));
}

TEST_CASE("test json_location to_string")
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<std::string>& /*location*/, const json& book)
auto callback = [&](const jsonpath::json_location<json>& /*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<std::string>& /*location*/, const json& book)
auto callback1 = [&](const jsonpath::json_location<json>& /*location*/, const json& book)
{
if (book.at("category") == "memoir" && !book.contains("price"))
{
++count;
}
};

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

0 comments on commit 730aeb7

Please sign in to comment.