Skip to content

Commit

Permalink
jsonpath one static_resources
Browse files Browse the repository at this point in the history
  • Loading branch information
danielaparker committed Dec 14, 2024
1 parent 049bca2 commit f5f7c04
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 42 deletions.
20 changes: 16 additions & 4 deletions include/jsoncons_ext/jsonpath/expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2399,16 +2399,18 @@ namespace detail {
}
};

template <typename Json,typename JsonReference>
template <typename Json>
struct static_resources
{
using allocator_type = typename Json::allocator_type;
using char_type = typename Json::char_type;
using string_type = typename Json::string_type;
using value_type = Json;
using reference = JsonReference;
using reference = typename jsonpath_traits<Json>::reference;
using const_reference = typename jsonpath_traits<Json>::const_reference;
using function_base_type = function_base<Json>;
using selector_type = jsonpath_selector<Json,JsonReference>;
using selector_type = jsonpath_selector<Json,reference>;
using const_selector_type = jsonpath_selector<Json,const_reference>;

struct MyHash
{
Expand All @@ -2428,6 +2430,7 @@ namespace detail {

allocator_type alloc_;
std::vector<std::unique_ptr<selector_type>> selectors_;
std::vector<std::unique_ptr<const_selector_type>> const_selectors_;
std::vector<std::unique_ptr<Json>> temp_json_values_;
std::vector<std::unique_ptr<unary_operator<Json>>> unary_operators_;

Expand Down Expand Up @@ -2623,7 +2626,16 @@ namespace detail {
}

template <typename T>
selector_type* new_selector(T&& val)
typename std::enable_if<std::is_const<typename std::remove_reference<typename T::reference>::type>::value,const_selector_type*>::type
new_selector(T&& val)
{
const_selectors_.emplace_back(jsoncons::make_unique<T>(std::forward<T>(val)));
return const_selectors_.back().get();
}

template <typename T>
typename std::enable_if<!std::is_const<typename std::remove_reference<typename T::reference>::type>::value,selector_type*>::type
new_selector(T&& val)
{
selectors_.emplace_back(jsoncons::make_unique<T>(std::forward<T>(val)));
return selectors_.back().get();
Expand Down
10 changes: 5 additions & 5 deletions include/jsoncons_ext/jsonpath/json_query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace jsonpath {
using path_expression_type = typename jsonpath_traits_type::path_expression_type;
using path_node_type = typename jsonpath_traits_type::path_node_type;

auto static_resources = jsoncons::make_unique<jsoncons::jsonpath::detail::static_resources<value_type,reference>>(funcs);
auto static_resources = jsoncons::make_unique<jsoncons::jsonpath::detail::static_resources<value_type>>(funcs);
evaluator_type evaluator;
path_expression_type expr = evaluator.compile(*static_resources, path);

Expand Down Expand Up @@ -117,7 +117,7 @@ namespace jsonpath {
using path_expression_type = typename jsonpath_traits_type::path_expression_type;
using path_node_type = typename jsonpath_traits_type::path_node_type;

auto static_resources = jsoncons::make_unique<jsoncons::jsonpath::detail::static_resources<value_type,reference>>(funcs, alloc_set.get_allocator());
auto static_resources = jsoncons::make_unique<jsoncons::jsonpath::detail::static_resources<value_type>>(funcs, alloc_set.get_allocator());
evaluator_type evaluator{alloc_set.get_allocator()};
path_expression_type expr = evaluator.compile(*static_resources, path);

Expand All @@ -143,7 +143,7 @@ namespace jsonpath {
using path_expression_type = typename jsonpath_traits_type::path_expression_type;
using path_node_type = typename jsonpath_traits_type::path_node_type;

auto static_resources = jsoncons::make_unique<jsoncons::jsonpath::detail::static_resources<value_type,reference>>(funcs);
auto static_resources = jsoncons::make_unique<jsoncons::jsonpath::detail::static_resources<value_type>>(funcs);
evaluator_type evaluator;
path_expression_type expr = evaluator.compile(*static_resources, path);

Expand Down Expand Up @@ -171,7 +171,7 @@ namespace jsonpath {
using path_expression_type = typename jsonpath_traits_type::path_expression_type;
using path_node_type = typename jsonpath_traits_type::path_node_type;

auto static_resources = jsoncons::make_unique<jsoncons::jsonpath::detail::static_resources<value_type,reference>>(funcs, alloc_set.get_allocator());
auto static_resources = jsoncons::make_unique<jsoncons::jsonpath::detail::static_resources<value_type>>(funcs, alloc_set.get_allocator());
evaluator_type evaluator{alloc_set.get_allocator()};
path_expression_type expr = evaluator.compile(*static_resources, path);

Expand All @@ -198,7 +198,7 @@ namespace jsonpath {
using path_expression_type = typename jsonpath_traits_type::path_expression_type;
using path_node_type = typename jsonpath_traits_type::path_node_type;

auto static_resources = jsoncons::make_unique<jsoncons::jsonpath::detail::static_resources<value_type,reference>>();
auto static_resources = jsoncons::make_unique<jsoncons::jsonpath::detail::static_resources<value_type>>();
evaluator_type evaluator;
path_expression_type expr = evaluator.compile(*static_resources, path);

Expand Down
46 changes: 16 additions & 30 deletions include/jsoncons_ext/jsonpath/jsonpath_expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,23 @@ namespace jsonpath {
using reference = typename jsonpath_traits<Json>::reference;
using const_reference = typename jsonpath_traits<Json>::const_reference;

using static_resources_type = jsoncons::jsonpath::detail::static_resources<value_type,reference>;
using const_static_resources_type = jsoncons::jsonpath::detail::static_resources<value_type,const_reference>;
using static_resources_type = jsoncons::jsonpath::detail::static_resources<value_type>;
using path_expression_type = jsoncons::jsonpath::detail::path_expression<value_type,reference>;
using const_path_expression_type = jsoncons::jsonpath::detail::path_expression<value_type,const_reference>;
using path_node_type = basic_path_node<typename Json::char_type>;
private:
allocator_type alloc_;
std::unique_ptr<const_static_resources_type> const_static_resources_;
const_path_expression_type const_expr_;
std::unique_ptr<static_resources_type> static_resources_;
const_path_expression_type const_expr_;
path_expression_type expr_;
public:
jsonpath_expression(const allocator_set<allocator_type,TempAllocator>& alloc_set,
std::unique_ptr<const_static_resources_type>&& const_resources,
const_path_expression_type&& const_expr,
std::unique_ptr<static_resources_type>&& resources,
const_path_expression_type&& const_expr,
path_expression_type&& expr)
: alloc_(alloc_set.get_allocator()),
const_static_resources_(std::move(const_resources)),
const_expr_(std::move(const_expr)),
static_resources_(std::move(resources)),
const_expr_(std::move(const_expr)),
expr_(std::move(expr))
{
}
Expand Down Expand Up @@ -166,22 +162,19 @@ namespace jsonpath {
using value_type = typename jsonpath_traits<Json>::value_type;
using reference = typename jsonpath_traits<Json>::reference;
using const_reference = typename jsonpath_traits<Json>::const_reference;
using static_resources_type = jsoncons::jsonpath::detail::static_resources<value_type,reference>;
using const_static_resources_type = jsoncons::jsonpath::detail::static_resources<value_type,const_reference>;
using static_resources_type = jsoncons::jsonpath::detail::static_resources<value_type>;
using evaluator_type = typename jsoncons::jsonpath::detail::jsonpath_evaluator<value_type, reference>;
using const_evaluator_type = typename jsoncons::jsonpath::detail::jsonpath_evaluator<value_type, const_reference>;

auto const_static_resources = jsoncons::make_unique<const_static_resources_type>(funcs);
auto static_resources = jsoncons::make_unique<static_resources_type>(funcs);
const_evaluator_type const_evaluator;
auto const_expr = const_evaluator.compile(*const_static_resources, path);
auto const_expr = const_evaluator.compile(*static_resources, path);

auto static_resources = jsoncons::make_unique<static_resources_type>(funcs);
evaluator_type evaluator;
auto expr = evaluator.compile(*static_resources, path);

return jsonpath_expression<Json>(jsoncons::combine_allocators(),
std::move(const_static_resources), std::move(const_expr),
std::move(static_resources), std::move(expr));
std::move(static_resources), std::move(const_expr), std::move(expr));
}

template <typename Json>
Expand All @@ -205,24 +198,20 @@ namespace jsonpath {
using value_type = typename jsonpath_traits<Json>::value_type;
using reference = typename jsonpath_traits<Json>::reference;
using const_reference = typename jsonpath_traits<Json>::const_reference;
using static_resources_type = jsoncons::jsonpath::detail::static_resources<value_type,reference>;
using const_static_resources_type = jsoncons::jsonpath::detail::static_resources<value_type,const_reference>;
using static_resources_type = jsoncons::jsonpath::detail::static_resources<value_type>;
using evaluator_type = typename jsoncons::jsonpath::detail::jsonpath_evaluator<value_type, reference>;
using const_evaluator_type = typename jsoncons::jsonpath::detail::jsonpath_evaluator<value_type, const_reference>;

auto const_static_resources = jsoncons::make_unique<const_static_resources_type>(funcs,
auto static_resources = jsoncons::make_unique<static_resources_type>(funcs,
alloc_set.get_allocator());
const_evaluator_type const_evaluator{alloc_set.get_allocator()};
auto const_expr = const_evaluator.compile(*const_static_resources, path);
auto const_expr = const_evaluator.compile(*static_resources, path);

auto static_resources = jsoncons::make_unique<static_resources_type>(funcs,
alloc_set.get_allocator());
evaluator_type evaluator{alloc_set.get_allocator()};
auto expr = evaluator.compile(*static_resources, path);

return jsonpath_expression<Json>(alloc_set,
std::move(const_static_resources), std::move(const_expr),
std::move(static_resources), std::move(expr));
std::move(static_resources), std::move(const_expr), std::move(expr));
}

template <typename Json,typename TempAllocator >
Expand All @@ -233,22 +222,19 @@ namespace jsonpath {
using value_type = typename jsonpath_traits<Json>::value_type;
using reference = typename jsonpath_traits<Json>::reference;
using const_reference = typename jsonpath_traits<Json>::const_reference;
using static_resources_type = jsoncons::jsonpath::detail::static_resources<value_type,reference>;
using const_static_resources_type = jsoncons::jsonpath::detail::static_resources<value_type,const_reference>;
using static_resources_type = jsoncons::jsonpath::detail::static_resources<value_type>;
using evaluator_type = typename jsoncons::jsonpath::detail::jsonpath_evaluator<value_type, reference>;
using const_evaluator_type = typename jsoncons::jsonpath::detail::jsonpath_evaluator<value_type, const_reference>;

auto const_static_resources = jsoncons::make_unique<const_static_resources_type>(funcs);
auto static_resources = jsoncons::make_unique<static_resources_type>(funcs);
const_evaluator_type const_evaluator{alloc_set.get_allocator()};
auto const_expr = const_evaluator.compile(*const_static_resources, path, ec);
auto const_expr = const_evaluator.compile(*static_resources, path, ec);

auto static_resources = jsoncons::make_unique<static_resources_type>(funcs);
evaluator_type evaluator{alloc_set.get_allocator()};
auto expr = evaluator.compile(*static_resources, path, ec);

return jsonpath_expression<Json>(alloc_set,
std::move(const_static_resources), std::move(const_expr),
std::move(static_resources), std::move(expr));
std::move(static_resources), std::move(const_expr), std::move(expr));
}

template <typename Json>
Expand Down
6 changes: 3 additions & 3 deletions include/jsoncons_ext/jsonpath/jsonpath_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ namespace detail {
return column_;
}

path_expression_type compile(static_resources<value_type,reference>& resources, const string_view_type& path)
path_expression_type compile(static_resources<value_type>& resources, const string_view_type& path)
{
std::error_code ec;
auto result = compile(resources, path, ec);
Expand All @@ -166,7 +166,7 @@ namespace detail {
return result;
}

path_expression_type compile(static_resources<value_type,reference>& resources,
path_expression_type compile(static_resources<value_type>& resources,
const string_view_type& path,
std::error_code& ec)
{
Expand Down Expand Up @@ -2151,7 +2151,7 @@ namespace detail {
operator_stack_.erase(it.base(),operator_stack_.end());
}

void push_token(jsoncons::jsonpath::detail::static_resources<value_type,reference>& resources, token_type&& tok, std::error_code& ec)
void push_token(jsoncons::jsonpath::detail::static_resources<value_type>& resources, token_type&& tok, std::error_code& ec)
{
//std::cout << tok.to_string() << "\n";
switch (tok.token_kind())
Expand Down

0 comments on commit f5f7c04

Please sign in to comment.