jmespath.cpp
C++ implementation of JMESPath, a query language for JSON http://jmespath.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
insertnodeaction.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Author: Róbert Márki <gsmiko@gmail.com>
4 ** Copyright (c) 2016 Róbert Márki
5 **
6 ** This file is part of the jmespath.cpp project which is distributed under
7 ** the MIT License (MIT).
8 **
9 ** Permission is hereby granted, free of charge, to any person obtaining a copy
10 ** of this software and associated documentation files (the "Software"), to
11 ** deal in the Software without restriction, including without limitation the
12 ** rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
13 ** sell copies of the Software, and to permit persons to whom the Software is
14 ** furnished to do so, subject to the following conditions:
15 **
16 ** The above copyright notice and this permission notice shall be included in
17 ** all copies or substantial portions of the Software.
18 **
19 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 ** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 ** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 ** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 ** FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 ** DEALINGS IN THE SOFTWARE.
26 **
27 ****************************************************************************/
28 #ifndef INSERTBINARYEXPRESSIONNODEACTION_H
29 #define INSERTBINARYEXPRESSIONNODEACTION_H
30 #include "src/parser/noderank.h"
32 #include "src/ast/allnodes.h"
33 #include <algorithm>
34 #include <boost/variant/polymorphic_get.hpp>
35 #include <boost/optional.hpp>
36 
37 namespace jmespath { namespace parser {
38 
57 template <typename NodeInserterT,
58  typename NodeInsertConditionT>
60 {
61 public:
65  using result_type = void;
72  template <typename T>
73  void operator()(ast::ExpressionNode& targetNode, T& node) const
74  {
75  using std::placeholders::_1;
76  LeftEdgeIterator begin(targetNode);
77  LeftEdgeIterator end;
78  auto predicate = std::bind(m_insertCondition, _1, std::ref(node));
79  auto it = std::find_if(begin, end, predicate);
80  if (it != end)
81  {
82  m_nodeInserter(*it, node);
83  }
84  }
85 
86 private:
91  NodeInserterT m_nodeInserter;
96  NodeInsertConditionT m_insertCondition;
97 };
98 }} // namespace jmespath::parser
99 #endif // INSERTBINARYEXPRESSIONNODEACTION_H
The LeftEdgeIterator class is a forward iterator which can be used to iterate over the ExpressionNode...
Definition: leftedgeiterator.h:40
void operator()(ast::ExpressionNode &targetNode, T &node) const
Inserts the given node into the AST whose root node is specified with targetNode. ...
Definition: insertnodeaction.h:73
void result_type
The action's result type.
Definition: insertnodeaction.h:65
NodeInserterT m_nodeInserter
Functor for inserting the a node at the position of the target node into the AST. ...
Definition: insertnodeaction.h:91
The InsertNodeAction class is a functor for inserting the given node into the AST whose root node is ...
Definition: insertnodeaction.h:59
NodeInsertConditionT m_insertCondition
Functor for checking whether the passed node can be inserted at the position of the target node...
Definition: insertnodeaction.h:96
The ExpressionNode class represents a JMESPath expression.
Definition: expressionnode.h:56