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
nodeinsertpolicy.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 NODEINSERTPOLICY_H
29 #define NODEINSERTPOLICY_H
30 #include "src/ast/allnodes.h"
31 
32 namespace jmespath { namespace parser {
33 
39 {
40 public:
44  using result_type = void;
45 
53  template <typename T, typename
54  std::enable_if<
55  std::is_base_of<ast::BinaryExpressionNode, T>::value
56  && !std::is_same<ast::SubexpressionNode, T>::value, int>::type = 0>
57  void operator()(ast::ExpressionNode& targetNode,
58  T& node) const
59  {
60  node.rightExpression = targetNode;
61  targetNode = node;
62  }
63 
64  template <typename T, typename
65  std::enable_if<
66  std::is_same<ast::NotExpressionNode, T>::value, int>::type = 0>
67  void operator()(ast::ExpressionNode& targetNode,
68  T& node) const
69  {
70  node.expression = targetNode;
71  targetNode = node;
72  }
73 
74  template <typename T, typename
75  std::enable_if<
76  (!std::is_base_of<ast::BinaryExpressionNode, T>::value
77  && !std::is_same<ast::NotExpressionNode, T>::value
78  && std::is_assignable<ast::ExpressionNode, T>::value)
79  || std::is_same<ast::SubexpressionNode, T>::value, int>::type = 0>
80  void operator()(ast::ExpressionNode& targetNode,
81  T& node) const
82  {
83  targetNode = node;
84  }
86 };
87 }} // namespace jmespath::parser
88 #endif // NODEINSERTPOLICY_H
The NodeInsertPolicy class is a functor for inserting a given node into the AST.
Definition: nodeinsertpolicy.h:38
void result_type
The result type of the functor.
Definition: nodeinsertpolicy.h:44
void operator()(ast::ExpressionNode &targetNode, T &node) const
Inserts the given node into the AST at the location of the targetNode.
Definition: nodeinsertpolicy.h:57
The ExpressionNode class represents a JMESPath expression.
Definition: expressionnode.h:56