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 c5e7eee commit b388069
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
2 changes: 1 addition & 1 deletion include/jsoncons/detail/span.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace detail
{
public:
using element_type = T;
using value_type = typename std::remove_volatile<typename std::remove_const<T>::type>::type;
using value_type = typename std::remove_const<T>::type;
using size_type = std::size_t;
using difference_type = std::ptrdiff_t;
using pointer = T*;
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 @@ -62,7 +62,7 @@ namespace jsonpath {
json_replace(Json& instance, const typename Json::string_view_type& path, T&& new_value,
const custom_functions<Json>& funcs = custom_functions<Json>())
{
using jsonpath_traits_type = jsoncons::jsonpath::jsonpath_traits<Json, Json&>;
using jsonpath_traits_type = jsoncons::jsonpath::legacy_jsonpath_traits<Json, Json&>;

using value_type = typename jsonpath_traits_type::value_type;
using reference = typename jsonpath_traits_type::reference;
Expand All @@ -88,7 +88,7 @@ namespace jsonpath {
Json& instance, const typename Json::string_view_type& path, T&& new_value,
const custom_functions<Json>& funcs = custom_functions<Json>())
{
using jsonpath_traits_type = jsoncons::jsonpath::jsonpath_traits<Json, Json&>;
using jsonpath_traits_type = jsoncons::jsonpath::legacy_jsonpath_traits<Json, Json&>;

using value_type = typename jsonpath_traits_type::value_type;
using reference = typename jsonpath_traits_type::reference;
Expand All @@ -113,7 +113,7 @@ namespace jsonpath {
json_replace(Json& instance, const typename Json::string_view_type& path , BinaryCallback callback,
const custom_functions<Json>& funcs = custom_functions<Json>())
{
using jsonpath_traits_type = jsoncons::jsonpath::jsonpath_traits<Json, Json&>;
using jsonpath_traits_type = jsoncons::jsonpath::legacy_jsonpath_traits<Json, Json&>;

using value_type = typename jsonpath_traits_type::value_type;
using reference = typename jsonpath_traits_type::reference;
Expand All @@ -140,7 +140,7 @@ namespace jsonpath {
Json& instance, const typename Json::string_view_type& path , BinaryCallback callback,
const custom_functions<Json>& funcs = custom_functions<Json>())
{
using jsonpath_traits_type = jsoncons::jsonpath::jsonpath_traits<Json, Json&>;
using jsonpath_traits_type = jsoncons::jsonpath::legacy_jsonpath_traits<Json, Json&>;

using value_type = typename jsonpath_traits_type::value_type;
using reference = typename jsonpath_traits_type::reference;
Expand All @@ -166,7 +166,7 @@ namespace jsonpath {
typename std::enable_if<extension_traits::is_unary_function_object<UnaryCallback,Json>::value,void>::type
json_replace(Json& instance, const typename Json::string_view_type& path , UnaryCallback callback)
{
using jsonpath_traits_type = jsoncons::jsonpath::jsonpath_traits<Json, Json&>;
using jsonpath_traits_type = jsoncons::jsonpath::legacy_jsonpath_traits<Json, Json&>;

using value_type = typename jsonpath_traits_type::value_type;
using reference = typename jsonpath_traits_type::reference;
Expand Down
36 changes: 28 additions & 8 deletions include/jsoncons_ext/jsonpath/jsonpath_expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2484,12 +2484,13 @@ namespace detail {
} // namespace detail

template <class Json, class JsonReference = const Json&>
struct jsonpath_traits
struct legacy_jsonpath_traits
{
using char_type = typename Json::char_type;
using string_type = typename Json::string_type;
using string_view_type = typename Json::string_view_type;
using value_type = typename std::remove_volatile<typename std::remove_const<Json>::type>::type;
using element_type = Json;
using value_type = typename std::remove_cv<Json>::type;
using reference = JsonReference;
using const_reference = const value_type&;
using pointer = typename std::conditional<std::is_const<typename std::remove_reference<reference>::type>::value, typename Json::const_pointer, typename Json::pointer>::type;
Expand All @@ -2501,11 +2502,30 @@ namespace detail {
using path_pointer = const path_node_type*;
};

template <class Json>
struct jsonpath_traits
{
using char_type = typename Json::char_type;
using string_type = typename Json::string_type;
using string_view_type = typename Json::string_view_type;
using element_type = Json;
using value_type = typename std::remove_cv<Json>::type;
using reference = Json&;
using const_reference = const Json&;
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_expression_type = jsoncons::jsonpath::detail::path_expression<value_type,reference>;
using path_pointer = const path_node_type*;
};

template <class Json,class JsonReference = const Json&, class TempAllocator=std::allocator<char>>
class jsonpath_expression
{
public:
using jsonpath_traits_type = jsoncons::jsonpath::jsonpath_traits<Json, JsonReference>;
using jsonpath_traits_type = jsoncons::jsonpath::legacy_jsonpath_traits<Json, JsonReference>;

using allocator_type = typename jsonpath_traits_type::allocator_type;
using evaluator_type = typename jsonpath_traits_type::evaluator_type;
Expand Down Expand Up @@ -2587,7 +2607,7 @@ namespace detail {
class update_expression
{
public:
using jsonpath_traits_type = jsoncons::jsonpath::jsonpath_traits<Json, JsonReference>;
using jsonpath_traits_type = jsoncons::jsonpath::legacy_jsonpath_traits<Json, JsonReference>;

using allocator_type = typename jsonpath_traits_type::allocator_type;
using evaluator_type = typename jsonpath_traits_type::evaluator_type;
Expand Down Expand Up @@ -2690,7 +2710,7 @@ namespace detail {
const typename Json::string_view_type& path,
const custom_functions<Json>& functions = custom_functions<Json>())
{
using jsonpath_traits_type = jsoncons::jsonpath::jsonpath_traits<Json>;
using jsonpath_traits_type = jsoncons::jsonpath::legacy_jsonpath_traits<Json>;

using value_type = typename jsonpath_traits_type::value_type;
using reference = typename jsonpath_traits_type::reference;
Expand All @@ -2711,7 +2731,7 @@ namespace detail {
const typename Json::string_view_type& path,
const custom_functions<Json>& functions, std::error_code& ec)
{
using jsonpath_traits_type = jsoncons::jsonpath::jsonpath_traits<Json>;
using jsonpath_traits_type = jsoncons::jsonpath::legacy_jsonpath_traits<Json>;

using value_type = typename jsonpath_traits_type::value_type;
using reference = typename jsonpath_traits_type::reference;
Expand All @@ -2730,7 +2750,7 @@ namespace detail {
auto make_update_expression(const typename Json::string_view_type& path,
const jsoncons::jsonpath::custom_functions<Json>& funcs = jsoncons::jsonpath::custom_functions<Json>())
{
using jsonpath_traits_type = jsoncons::jsonpath::jsonpath_traits<Json, Json&>;
using jsonpath_traits_type = jsoncons::jsonpath::jsonpath_traits<Json>;

using value_type = typename jsonpath_traits_type::value_type;
using reference = typename jsonpath_traits_type::reference;
Expand All @@ -2748,7 +2768,7 @@ namespace detail {
const typename Json::string_view_type& path,
const jsoncons::jsonpath::custom_functions<Json>& funcs, std::error_code& ec)
{
using jsonpath_traits_type = jsoncons::jsonpath::jsonpath_traits<Json, Json&>;
using jsonpath_traits_type = jsoncons::jsonpath::jsonpath_traits<Json>;

using value_type = typename jsonpath_traits_type::value_type;
using reference = typename jsonpath_traits_type::reference;
Expand Down

0 comments on commit b388069

Please sign in to comment.