Skip to content

Commit

Permalink
path_node w string_view
Browse files Browse the repository at this point in the history
  • Loading branch information
danielaparker committed Nov 8, 2023
1 parent d801a7c commit b0727bd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
8 changes: 4 additions & 4 deletions include/jsoncons_ext/jsonpath/expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2196,16 +2196,16 @@ namespace detail {
};

template <class Json,class JsonReference>
class path_stem_value_receiver : public node_receiver<Json,JsonReference>
class path_component_value_receiver : public node_receiver<Json,JsonReference>
{
public:
using reference = JsonReference;
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 path_stem_value_pair_type = path_component_value_pair<Json,JsonReference>;
using path_component_value_pair_type = path_component_value_pair<Json,JsonReference>;

std::vector<path_stem_value_pair_type> nodes;
std::vector<path_component_value_pair_type> nodes;

void add(const path_node_type& tail_nodes,
reference value) override
Expand All @@ -2223,7 +2223,7 @@ namespace detail {
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<typename Json::char_type>;
using path_stem_value_pair_type = path_component_value_pair<Json,JsonReference>;
using path_component_value_pair_type = path_component_value_pair<Json,JsonReference>;

allocator_type alloc_;
std::vector<std::unique_ptr<Json>> temp_json_values_;
Expand Down
18 changes: 15 additions & 3 deletions include/jsoncons_ext/jsonpath/json_location.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,17 @@ namespace jsonpath {
return name_;
}

std::size_t size() const
{
std::size_t len = 1;

for (auto p = parent_; p != nullptr; p = p->parent_)
{
++len;
}
return len;
}

std::size_t index() const
{
return index_;
Expand Down Expand Up @@ -322,15 +333,16 @@ namespace jsonpath {
json_location(const path_node_type& node, const allocator_type& alloc = allocator_type())
: alloc_(alloc)
{
std::size_t len = node.size();
nodes_.resize(len);

const path_node_type* p = std::addressof(node);
do
{
nodes_.push_back(p);
nodes_[--len] = p;
p = p->parent_;
}
while (p != nullptr);

std::reverse(nodes_.begin(), nodes_.end());
}

iterator begin()
Expand Down

0 comments on commit b0727bd

Please sign in to comment.