diff --git a/include/jsoncons_ext/jsonpath/expression.hpp b/include/jsoncons_ext/jsonpath/expression.hpp index 7ec4bf672f..a4a4a6e830 100644 --- a/include/jsoncons_ext/jsonpath/expression.hpp +++ b/include/jsoncons_ext/jsonpath/expression.hpp @@ -2399,16 +2399,18 @@ namespace detail { } }; - template + template 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::reference; + using const_reference = typename jsonpath_traits::const_reference; using function_base_type = function_base; - using selector_type = jsonpath_selector; + using selector_type = jsonpath_selector; + using const_selector_type = jsonpath_selector; struct MyHash { @@ -2428,6 +2430,7 @@ namespace detail { allocator_type alloc_; std::vector> selectors_; + std::vector> const_selectors_; std::vector> temp_json_values_; std::vector>> unary_operators_; @@ -2623,7 +2626,16 @@ namespace detail { } template - selector_type* new_selector(T&& val) + typename std::enable_if::type>::value,const_selector_type*>::type + new_selector(T&& val) + { + const_selectors_.emplace_back(jsoncons::make_unique(std::forward(val))); + return const_selectors_.back().get(); + } + + template + typename std::enable_if::type>::value,selector_type*>::type + new_selector(T&& val) { selectors_.emplace_back(jsoncons::make_unique(std::forward(val))); return selectors_.back().get(); diff --git a/include/jsoncons_ext/jsonpath/json_query.hpp b/include/jsoncons_ext/jsonpath/json_query.hpp index cb6393024c..cd43e621fd 100644 --- a/include/jsoncons_ext/jsonpath/json_query.hpp +++ b/include/jsoncons_ext/jsonpath/json_query.hpp @@ -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>(funcs); + auto static_resources = jsoncons::make_unique>(funcs); evaluator_type evaluator; path_expression_type expr = evaluator.compile(*static_resources, path); @@ -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>(funcs, alloc_set.get_allocator()); + auto static_resources = jsoncons::make_unique>(funcs, alloc_set.get_allocator()); evaluator_type evaluator{alloc_set.get_allocator()}; path_expression_type expr = evaluator.compile(*static_resources, path); @@ -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>(funcs); + auto static_resources = jsoncons::make_unique>(funcs); evaluator_type evaluator; path_expression_type expr = evaluator.compile(*static_resources, path); @@ -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>(funcs, alloc_set.get_allocator()); + auto static_resources = jsoncons::make_unique>(funcs, alloc_set.get_allocator()); evaluator_type evaluator{alloc_set.get_allocator()}; path_expression_type expr = evaluator.compile(*static_resources, path); @@ -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>(); + auto static_resources = jsoncons::make_unique>(); evaluator_type evaluator; path_expression_type expr = evaluator.compile(*static_resources, path); diff --git a/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp b/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp index 04c8dfedf3..57996858d9 100644 --- a/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp +++ b/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp @@ -37,27 +37,23 @@ namespace jsonpath { using reference = typename jsonpath_traits::reference; using const_reference = typename jsonpath_traits::const_reference; - using static_resources_type = jsoncons::jsonpath::detail::static_resources; - using const_static_resources_type = jsoncons::jsonpath::detail::static_resources; + using static_resources_type = jsoncons::jsonpath::detail::static_resources; using path_expression_type = jsoncons::jsonpath::detail::path_expression; using const_path_expression_type = jsoncons::jsonpath::detail::path_expression; using path_node_type = basic_path_node; private: allocator_type alloc_; - std::unique_ptr const_static_resources_; - const_path_expression_type const_expr_; std::unique_ptr static_resources_; + const_path_expression_type const_expr_; path_expression_type expr_; public: jsonpath_expression(const allocator_set& alloc_set, - std::unique_ptr&& const_resources, - const_path_expression_type&& const_expr, std::unique_ptr&& 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)) { } @@ -166,22 +162,19 @@ namespace jsonpath { using value_type = typename jsonpath_traits::value_type; using reference = typename jsonpath_traits::reference; using const_reference = typename jsonpath_traits::const_reference; - using static_resources_type = jsoncons::jsonpath::detail::static_resources; - using const_static_resources_type = jsoncons::jsonpath::detail::static_resources; + using static_resources_type = jsoncons::jsonpath::detail::static_resources; using evaluator_type = typename jsoncons::jsonpath::detail::jsonpath_evaluator; using const_evaluator_type = typename jsoncons::jsonpath::detail::jsonpath_evaluator; - auto const_static_resources = jsoncons::make_unique(funcs); + auto static_resources = jsoncons::make_unique(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(funcs); evaluator_type evaluator; auto expr = evaluator.compile(*static_resources, path); return jsonpath_expression(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 @@ -205,24 +198,20 @@ namespace jsonpath { using value_type = typename jsonpath_traits::value_type; using reference = typename jsonpath_traits::reference; using const_reference = typename jsonpath_traits::const_reference; - using static_resources_type = jsoncons::jsonpath::detail::static_resources; - using const_static_resources_type = jsoncons::jsonpath::detail::static_resources; + using static_resources_type = jsoncons::jsonpath::detail::static_resources; using evaluator_type = typename jsoncons::jsonpath::detail::jsonpath_evaluator; using const_evaluator_type = typename jsoncons::jsonpath::detail::jsonpath_evaluator; - auto const_static_resources = jsoncons::make_unique(funcs, + auto static_resources = jsoncons::make_unique(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(funcs, - alloc_set.get_allocator()); evaluator_type evaluator{alloc_set.get_allocator()}; auto expr = evaluator.compile(*static_resources, path); return jsonpath_expression(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 @@ -233,22 +222,19 @@ namespace jsonpath { using value_type = typename jsonpath_traits::value_type; using reference = typename jsonpath_traits::reference; using const_reference = typename jsonpath_traits::const_reference; - using static_resources_type = jsoncons::jsonpath::detail::static_resources; - using const_static_resources_type = jsoncons::jsonpath::detail::static_resources; + using static_resources_type = jsoncons::jsonpath::detail::static_resources; using evaluator_type = typename jsoncons::jsonpath::detail::jsonpath_evaluator; using const_evaluator_type = typename jsoncons::jsonpath::detail::jsonpath_evaluator; - auto const_static_resources = jsoncons::make_unique(funcs); + auto static_resources = jsoncons::make_unique(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(funcs); evaluator_type evaluator{alloc_set.get_allocator()}; auto expr = evaluator.compile(*static_resources, path, ec); return jsonpath_expression(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 diff --git a/include/jsoncons_ext/jsonpath/jsonpath_parser.hpp b/include/jsoncons_ext/jsonpath/jsonpath_parser.hpp index a5a727458f..399bc29b74 100644 --- a/include/jsoncons_ext/jsonpath/jsonpath_parser.hpp +++ b/include/jsoncons_ext/jsonpath/jsonpath_parser.hpp @@ -155,7 +155,7 @@ namespace detail { return column_; } - path_expression_type compile(static_resources& resources, const string_view_type& path) + path_expression_type compile(static_resources& resources, const string_view_type& path) { std::error_code ec; auto result = compile(resources, path, ec); @@ -166,7 +166,7 @@ namespace detail { return result; } - path_expression_type compile(static_resources& resources, + path_expression_type compile(static_resources& resources, const string_view_type& path, std::error_code& ec) { @@ -2151,7 +2151,7 @@ namespace detail { operator_stack_.erase(it.base(),operator_stack_.end()); } - void push_token(jsoncons::jsonpath::detail::static_resources& resources, token_type&& tok, std::error_code& ec) + void push_token(jsoncons::jsonpath::detail::static_resources& resources, token_type&& tok, std::error_code& ec) { //std::cout << tok.to_string() << "\n"; switch (tok.token_kind())