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
expression.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 EXPRESSION_H
29 #define EXPRESSION_H
30 #include <memory>
31 #include <jmespath/types.h>
32 #include <jmespath/exceptions.h>
33 
34 namespace jmespath {
35 
36 namespace ast {
37 class ExpressionNode;
38 }
48 {
49 public:
53  Expression();
58  Expression(const Expression& other);
64  Expression(Expression&& other);
76  template <typename U, typename
77  std::enable_if<
78  std::is_convertible<U, String>::value>::type* = nullptr>
79  Expression(U&& expression)
80  : m_expressionString(std::forward<U>(expression))
81  {
83  }
90  Expression& operator= (const Expression& other);
104  bool operator== (const Expression& other) const;
110  String toString() const;
117  bool isEmpty() const;
124  const ast::ExpressionNode* astRoot() const;
125 
126 private:
135  {
140  void operator()(ast::ExpressionNode* node) const;
141  };
149  std::unique_ptr<ast::ExpressionNode, ExpressionDeleter> m_astRoot;
157  void parseExpression(const String &expressionString);
158 };
159 
163 namespace literals {
164 
174 inline Expression operator""_jmespath(const char* expression, std::size_t)
175 {
176  return {expression};
177 }
178 } // namespace jmespath::literals
179 } // namespace jmespath
180 #endif // EXPRESSION_H
Expression(U &&expression)
Constructs an Expression object by forwarding argument.
Definition: expression.h:79
Expression & operator=(const Expression &other)
Assigns other to this expression and returns a reference to this expression.
Definition: expression.cpp:50
The Expression class represents a JMESPath expression.
Definition: expression.h:47
bool operator==(const Expression &other) const
Equality compares this expression to the other.
Definition: expression.cpp:98
String m_expressionString
The string representation of the JMESPath expression.
Definition: expression.h:145
String toString() const
Converts the expression to the string representation of the JMESPath expression.
Definition: expression.cpp:70
const ast::ExpressionNode * astRoot() const
Returns a pointer to the root expression in the abstract syntax tree.
Definition: expression.cpp:80
std::basic_string< Char > String
UTF-8 encoded string type.
Definition: types.h:44
void parseExpression(const String &expressionString)
Parses the expressionString and updates the AST.
Definition: expression.cpp:85
Expression()
Constructs an empty Expression object.
Definition: expression.cpp:34
void operator()(ast::ExpressionNode *node) const
operator () Destroys the given node object.
Definition: expression.cpp:108
The ExpressionNode class represents a JMESPath expression.
Definition: expressionnode.h:56
The ExpressionDeleter struct is a custom destruction policy for deleting ast::ExpressionNode objects...
Definition: expression.h:134
bool isEmpty() const
Checks whether this object has been initialized. expression.
Definition: expression.cpp:75
std::unique_ptr< ast::ExpressionNode, ExpressionDeleter > m_astRoot
The root node of the ast.
Definition: expression.h:149