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
nodeinsertcondition.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 NODEINSERTCONDITION_H
29 #define NODEINSERTCONDITION_H
30 #include "src/ast/allnodes.h"
31 #include "src/parser/noderank.h"
32 #include <boost/variant/polymorphic_get.hpp>
33 
34 namespace jmespath { namespace parser {
35 
42 {
43 public:
47  using result_type = bool;
48 
57  template <typename T, typename
58  std::enable_if<
59  std::is_base_of<ast::BinaryExpressionNode,
60  T>::value, int>::type = 0>
61  bool operator()(const ast::ExpressionNode& targetNode,
62  const T& node) const
63  {
64  int targetNodeRank = nodeRank(targetNode);
65  int currentNodeRank = nodeRank(node);
66  const ast::BinaryExpressionNode* targetBinaryNode
67  = boost::polymorphic_get<ast::BinaryExpressionNode>(
68  &targetNode.value);
69  return (targetNodeRank < currentNodeRank)
70  || ((targetNodeRank == currentNodeRank)
71  && targetBinaryNode
72  && targetBinaryNode->isProjection()
73  && !targetBinaryNode->stopsProjection());
74  }
75 
76  template <typename T, typename
77  std::enable_if<
78  !std::is_base_of<ast::BinaryExpressionNode,
79  T>::value, int>::type = 0>
80  bool operator()(const ast::ExpressionNode& targetNode,
81  const T& node) const
82  {
83  int targetNodeRank = nodeRank(targetNode);
84  int currentNodeRank = nodeRank(node);
85  return (targetNodeRank < currentNodeRank);
86  }
88 };
89 }} // namespace jmespath::parser
90 #endif // NODEINSERTCONDITION_H
The NodeInsertCondition class is a functor that will either yield a true or false result based on whe...
Definition: nodeinsertcondition.h:41
ValueType value
The variable which stores the node that this object represents.
Definition: variantnode.h:126
int nodeRank(const T &)
Returns the rank of the given node object's type.
Definition: noderank.h:40
The BinaryExpressionNode class is the base class for all node types which consist of a left and a rig...
Definition: binaryexpressionnode.h:39
bool operator()(const ast::ExpressionNode &targetNode, const T &node) const
Returns true or false based on whether the given node should be inserted at the location of the targe...
Definition: nodeinsertcondition.h:61
virtual bool stopsProjection() const =0
Reports whether the node should stop an ongoing projection or not.
virtual bool isProjection() const =0
Reports whether the right hand side expression is projected onto the result of the operation or not...
The ExpressionNode class represents a JMESPath expression.
Definition: expressionnode.h:56
bool result_type
The result type of the functor.
Definition: nodeinsertcondition.h:47