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
leftchildextractor.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 LEFTCHILDEXTRACTOR_H
29 #define LEFTCHILDEXTRACTOR_H
32 
33 namespace jmespath { namespace parser {
34 
41  : public boost::static_visitor<ast::ExpressionNode*>
42 {
43 public:
51  {
52  return boost::apply_visitor(*this, node->value);
53  }
54 
55  template <typename T>
57  {
58  return childNode(&node);
59  }
60 
61  template <typename T, typename
62  std::enable_if<
63  !std::is_base_of<ast::BinaryExpressionNode,
64  T>::value
65  && !std::is_same<ast::NotExpressionNode,
66  T>::value, int>::type = 0>
68  {
69  return nullptr;
70  }
71 
72  template <typename T, typename
73  std::enable_if<
74  !std::is_base_of<ast::BinaryExpressionNode,
75  T>::value
76  && std::is_same<ast::NotExpressionNode,
77  T>::value, int>::type = 0>
79  {
80  return &node->expression;
81  }
82 
83  template <typename T, typename
84  std::enable_if<
85  std::is_base_of<ast::BinaryExpressionNode,
86  T>::value, int>::type = 0>
88  {
89  return &node->leftExpression;
90  }
92 };
93 }} // namespace jmespath::parser
94 #endif // LEFTCHILDEXTRACTOR_H
ast::ExpressionNode * operator()(T &node) const
Returns a pointer to the child expression node of the given node or nullptr if the node doesn't has a...
Definition: leftchildextractor.h:56
ast::ExpressionNode * childNode(T *node) const
Returns a pointer to the child expression node of the given node or nullptr if the node doesn't has a...
Definition: leftchildextractor.h:78
ValueType value
The variable which stores the node that this object represents.
Definition: variantnode.h:126
The BinaryExpressionNode class is the base class for all node types which consist of a left and a rig...
Definition: binaryexpressionnode.h:39
The LeftChildExtractor class is a functor that extracts the child expression node from the given node...
Definition: leftchildextractor.h:40
ast::ExpressionNode * childNode(T *) const
Returns a pointer to the child expression node of the given node or nullptr if the node doesn't has a...
Definition: leftchildextractor.h:67
The NotExpressionNode class represents a JMESPath not expression.
Definition: notexpressionnode.h:39
The ExpressionNode class represents a JMESPath expression.
Definition: expressionnode.h:56
ast::ExpressionNode * operator()(ast::ExpressionNode *node) const
Returns a pointer to the child expression node of the given node or nullptr if the node doesn't has a...
Definition: leftchildextractor.h:50