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
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
jmespath::interpreter::Interpreter Class Reference

The Interpreter class evaluates the AST structure on a Json context. More...

#include <interpreter.h>

Inheritance diagram for jmespath::interpreter::Interpreter:
jmespath::interpreter::AbstractVisitor

Public Member Functions

 Interpreter ()
 Constructs an Interpreter object. More...
 
template<typename JsonT >
std::enable_if_t< std::is_same
< std::decay_t< JsonT >, Json >
::value, void > 
setContext (JsonT &&value)
 Sets the context of the evaluation. More...
 
const JsoncurrentContext () const
 Returns the current evaluation context. More...
 
ContextValuecurrentContextValue ()
 Returns the current evaluation context which can either hold a value or a const reference. More...
 
virtual void evaluateProjection (const ast::ExpressionNode *expression)
 Evaluates the projection of the given expression on the current context. More...
 
void visit (const ast::AbstractNode *node) override
 Evaluate the given node on the current context value. More...
 
void visit (const ast::ExpressionNode *node) override
 Evaluate the given node on the current context value. More...
 
void visit (const ast::IdentifierNode *node) override
 Evaluate the given node on the current context value. More...
 
void visit (const ast::RawStringNode *node) override
 Evaluate the given node on the current context value. More...
 
void visit (const ast::LiteralNode *node) override
 Evaluate the given node on the current context value. More...
 
void visit (const ast::SubexpressionNode *node) override
 Evaluate the given node on the current context value. More...
 
void visit (const ast::IndexExpressionNode *node) override
 Evaluate the given node on the current context value. More...
 
void visit (const ast::ArrayItemNode *node) override
 Evaluate the given node on the current context value. More...
 
void visit (const ast::FlattenOperatorNode *) override
 Evaluate the given node on the current context value. More...
 
void visit (const ast::BracketSpecifierNode *node) override
 Evaluate the given node on the current context value. More...
 
void visit (const ast::SliceExpressionNode *node) override
 Evaluate the given node on the current context value. More...
 
void visit (const ast::ListWildcardNode *) override
 Evaluate the given node on the current context value. More...
 
void visit (const ast::HashWildcardNode *node) override
 Evaluate the given node on the current context value. More...
 
void visit (const ast::MultiselectListNode *node) override
 Evaluate the given node on the current context value. More...
 
void visit (const ast::MultiselectHashNode *node) override
 Evaluate the given node on the current context value. More...
 
void visit (const ast::NotExpressionNode *node) override
 Evaluate the given node on the current context value. More...
 
void visit (const ast::ComparatorExpressionNode *node) override
 Evaluate the given node on the current context value. More...
 
void visit (const ast::OrExpressionNode *node) override
 Evaluate the given node on the current context value. More...
 
void visit (const ast::AndExpressionNode *node) override
 Evaluate the given node on the current context value. More...
 
void visit (const ast::ParenExpressionNode *node) override
 Evaluate the given node on the current context value. More...
 
void visit (const ast::PipeExpressionNode *node) override
 Evaluate the given node on the current context value. More...
 
void visit (const ast::CurrentNode *) override
 Evaluate the given node on the current context value. More...
 
void visit (const ast::FilterExpressionNode *node) override
 Evaluate the given node on the current context value. More...
 
void visit (const ast::FunctionExpressionNode *node) override
 Evaluate the given node on the current context value. More...
 
void visit (const ast::ExpressionArgumentNode *) override
 Evaluate the given node on the current context value. More...
 
- Public Member Functions inherited from jmespath::interpreter::AbstractVisitor
virtual ~AbstractVisitor ()
 Destroys the AbstractVisitor object. More...
 

Private Types

using FunctionArgument = boost::variant< boost::blank, ContextValue, ast::ExpressionNode >
 Type of the arguments in FunctionArgumentList. More...
 
using FunctionArgumentList = std::vector< FunctionArgument >
 List of FunctionArgument objects. More...
 
using Function = std::function< void(FunctionArgumentList &)>
 Function wrapper type to which JMESPath built in function implementations should conform to. More...
 
using JsonComparator = std::function< bool(const Json &, const Json &)>
 The type of comparator functions used for comparing Json values. More...
 
using ArgumentArityValidator = std::function< bool(const size_t &)>
 Function argument arity validator predicate. More...
 
using FunctionDescriptor = std::tuple< ArgumentArityValidator, bool, Function >
 Describes a built in function implementation. More...
 
using FunctionExpressionArgumentList = std::vector< ast::FunctionExpressionNode::ArgumentType >
 List of unevaluated function arguments. More...
 

Private Member Functions

Index adjustSliceEndpoint (size_t length, Index endpoint, Index step) const
 Adjust the value of the slice endpoint to make sure it's within the array's bounds and points to the correct item. More...
 
bool toBoolean (const Json &json) const
 Converts the json value to a boolean. More...
 
template<typename JsonT >
void evaluateProjection (const ast::ExpressionNode *expression, JsonT &&context)
 Evaluates the projection of the given expression with the evaluation context. More...
 
void evaluateLogicOperator (const ast::BinaryExpressionNode *node, bool shortCircuitValue)
 Evaluates a binary logic operator to the result of the left side expression if it's binary value equals to shortCircuitValue otherwise evaluates it to the result of the result of the right side expression. More...
 
FunctionArgumentList evaluateArguments (const FunctionExpressionArgumentList &arguments, const std::shared_ptr< ContextValue > &contextValue)
 Evaluate the given function expression arguments. More...
 
template<typename T >
T & getArgument (FunctionArgument &argument) const
 Converts the given function argument to the requsted type. More...
 
const JsongetJsonArgument (FunctionArgument &argument) const
 Creates a reference to the Json value held by the argument. More...
 
void abs (FunctionArgumentList &arguments)
 Calculates the absolute value of the first item in the given list of arguments. The first item must be a number Json value. More...
 
void avg (FunctionArgumentList &arguments)
 Calculates the average value of the items in the first item of the given arguments. The first item must be an Json array and every item in the array must be a number Json value. More...
 
void contains (FunctionArgumentList &arguments)
 Checks whether the first item in the given arguments contains the second item. The first item should be either an array or string the second item can be any Json type. More...
 
void ceil (FunctionArgumentList &arguments)
 Rounds up the first item of the given arguments to the next highest integer value. The first item should be a Json number. More...
 
void endsWith (FunctionArgumentList &arguments)
 Checks whether the first item of the given arguments ends with the second item. The first and second item of arguments must be a Json string. More...
 
void floor (FunctionArgumentList &arguments)
 Rounds down the first item of the given arguments to the next lowest integer value. The first item should be a Json number. More...
 
void join (FunctionArgumentList &arguments)
 Joins every item in the array provided as the second item of the given arguments with the first item as a separator. The first item must be a string and the second item must be an array of strings. More...
 
void keys (FunctionArgumentList &arguments)
 Extracts the keys from the object provided as the first item of the given arguments. More...
 
void length (FunctionArgumentList &arguments)
 Returns the length of the first item in the given arguments. The first item must be either an array a string or an object. More...
 
void map (FunctionArgumentList &arguments)
 Applies the expression provided as the first item in the given arguments to every item in the array provided as the second item in arguments. More...
 
template<typename JsonT >
void map (const ast::ExpressionNode *node, JsonT &&array)
 Applies the expression provided in node to every item in the array. More...
 
void merge (FunctionArgumentList &arguments)
 Accepts zero or more objects in the given arguments, and returns a single object with subsequent objects merged. Each subsequent object’s key/value pairs are added to the preceding object. More...
 
template<typename JsonT >
void mergeObject (Json *object, JsonT &&sourceObject)
 Merges the items of the sourceObject into object. More...
 
void notNull (FunctionArgumentList &arguments)
 Accepts one or more items in arguments, and will evaluate them in order until a non null argument is encounted. More...
 
void reverse (FunctionArgumentList &arguments)
 Reverses the order of the first item in arguments. It must either be an array or a string. More...
 
void reverse (Json &&subject)
 Reverses the order of the subject. It must either be an array or a string. More...
 
void sort (FunctionArgumentList &arguments)
 Sorts the first item in the given arguments, which must either be an array of numbers or an array of strings. More...
 
void sort (Json &&array)
 Sorts the array, which must either be an array of numbers or an array of strings. More...
 
void sortBy (FunctionArgumentList &arguments)
 Sorts the first item in the given arguments, which must either be an array of numbers or an array of strings. It uses the expression provided as the second item in arguments as the sort key. More...
 
void sortBy (const ast::ExpressionNode *expression, Json &&array)
 Sorts the array, which must either be an array of numbers or an array of strings. It uses the expression as the sort key. More...
 
void startsWith (FunctionArgumentList &arguments)
 Checks wheather the string provided as the first item in arguments starts with the string provided as the second item in arguments. More...
 
void sum (FunctionArgumentList &arguments)
 Calculates the sum of the numbers in the array provided as the first item of arguments. More...
 
void toArray (FunctionArgumentList &arguments)
 Converts the first item of the given arguments to a one element array if it's not already an array. More...
 
template<typename JsonT >
void toArray (JsonT &&value)
 Converts the given value to a one element array if it's not already an array. More...
 
void toString (FunctionArgumentList &arguments)
 Converts the first item of the given arguments to the Json encoded value if it's not already a string. More...
 
template<typename JsonT >
void toString (JsonT &&value)
 Converts the given value to the Json encoded value if it's not already a string. More...
 
void toNumber (FunctionArgumentList &arguments)
 Converts the string provided as the first item in the given arguments to a number. If it's already a number then the original value is returned, all other Json types are converted to null. More...
 
template<typename JsonT >
void toNumber (JsonT &&value)
 Converts the value to a number if it's not already a number, all other Json types are converted to null. More...
 
void type (FunctionArgumentList &arguments)
 Returns the type of the Json value provided as the first item in arguments. More...
 
void values (FunctionArgumentList &arguments)
 Extracts the values from the object provided as the first item of the given arguments. More...
 
template<typename JsonT >
void values (JsonT &&object)
 Extracts the values from the object. More...
 
void max (FunctionArgumentList &arguments, const JsonComparator &comparator)
 Finds the largest item in the array provided as the first item in the arguments, it must either be an array of numbers or an array of strings. More...
 
template<typename JsonT >
void max (const JsonComparator *comparator, JsonT &&array)
 Finds the largest item in the array, it must either be an array of numbers or an array of strings. More...
 
void maxBy (FunctionArgumentList &arguments, const JsonComparator &comparator=std::less< Json >{})
 Finds the largest item in the array provided as the first item in the arguments, which must either be an array of numbers or an array of strings, using the expression provided as the second item in arguments as a key for comparison. More...
 
template<typename JsonT >
void maxBy (const ast::ExpressionNode *expression, const JsonComparator *comparator, JsonT &&array)
 Finds the largest item in the array, which must either be an array of numbers or an array of strings, using the expression as a key for comparison. More...
 
bool isComparableArray (const Json &array) const
 Checks whether array is a homogeneous array which contains comparable types like strings and numbers. More...
 
template<typename JsonT >
void visit (const ast::IdentifierNode *node, JsonT &&context)
 Evaluates the given node on the evaluation context. More...
 
template<typename JsonT >
void visit (const ast::ArrayItemNode *node, JsonT &&context)
 Evaluates the given node on the evaluation context. More...
 
template<typename JsonT >
void visit (const ast::FlattenOperatorNode *node, JsonT &&context)
 Evaluates the given node on the evaluation context. More...
 
template<typename JsonT >
void visit (const ast::SliceExpressionNode *node, JsonT &&context)
 Evaluates the given node on the evaluation context. More...
 
template<typename JsonT >
void visit (const ast::HashWildcardNode *node, JsonT &&context)
 Evaluates the given node on the evaluation context. More...
 
template<typename JsonT >
void visit (const ast::FilterExpressionNode *node, JsonT &&context)
 Evaluates the given node on the evaluation context. More...
 

Private Attributes

ContextValue m_context
 Stores the evaluation context. More...
 
std::unordered_map< String,
FunctionDescriptor
m_functionMap
 Maps the JMESPath built in function names to their implementations. More...
 

Detailed Description

The Interpreter class evaluates the AST structure on a Json context.

See Also
setContext currentContext

Member Typedef Documentation

using jmespath::interpreter::Interpreter::ArgumentArityValidator = std::function<bool(const size_t&)>
private

Function argument arity validator predicate.

Function wrapper type to which JMESPath built in function implementations should conform to.

Type of the arguments in FunctionArgumentList.

List of FunctionArgument objects.

Describes a built in function implementation.

The tuple's first item is the comparator function used for comparing the actual number of arguments with the expected argument count, the second item marks whether the funciton needs a single ContextValue or more, while the third item stores the callable functions wrapper.

List of unevaluated function arguments.

using jmespath::interpreter::Interpreter::JsonComparator = std::function<bool(const Json&, const Json&)>
private

The type of comparator functions used for comparing Json values.

Constructor & Destructor Documentation

jmespath::interpreter::Interpreter::Interpreter ( )

Constructs an Interpreter object.

Member Function Documentation

void jmespath::interpreter::Interpreter::abs ( FunctionArgumentList arguments)
private

Calculates the absolute value of the first item in the given list of arguments. The first item must be a number Json value.

Parameters
[in]argumentsThe list of the function's arguments.
Exceptions
InvalidFunctionArgumentType
Index jmespath::interpreter::Interpreter::adjustSliceEndpoint ( size_t  length,
Index  endpoint,
Index  step 
) const
private

Adjust the value of the slice endpoint to make sure it's within the array's bounds and points to the correct item.

Parameters
[in]lengthThe length of the array that should be sliced.
[in]endpointThe current value of the endpoint.
[in]stepThe slice's step variable value.
Returns
Returns the endpoint's new value.
void jmespath::interpreter::Interpreter::avg ( FunctionArgumentList arguments)
private

Calculates the average value of the items in the first item of the given arguments. The first item must be an Json array and every item in the array must be a number Json value.

Parameters
[in]argumentsThe list of the function's arguments.
Exceptions
InvalidFunctionArgumentType
void jmespath::interpreter::Interpreter::ceil ( FunctionArgumentList arguments)
private

Rounds up the first item of the given arguments to the next highest integer value. The first item should be a Json number.

Parameters
[in]argumentsThe list of the function's arguments.
Exceptions
InvalidFunctionArgumentType
void jmespath::interpreter::Interpreter::contains ( FunctionArgumentList arguments)
private

Checks whether the first item in the given arguments contains the second item. The first item should be either an array or string the second item can be any Json type.

Parameters
[in]argumentsThe list of the function's arguments.
Exceptions
InvalidFunctionArgumentType
const Json& jmespath::interpreter::Interpreter::currentContext ( ) const
inline

Returns the current evaluation context.

Returns
Json document used as the context.
ContextValue& jmespath::interpreter::Interpreter::currentContextValue ( )
inline

Returns the current evaluation context which can either hold a value or a const reference.

Returns
ContextValue used as the context.
void jmespath::interpreter::Interpreter::endsWith ( FunctionArgumentList arguments)
private

Checks whether the first item of the given arguments ends with the second item. The first and second item of arguments must be a Json string.

Parameters
[in]argumentsThe list of the function's arguments.
Exceptions
InvalidFunctionArgumentType
Interpreter::FunctionArgumentList jmespath::interpreter::Interpreter::evaluateArguments ( const FunctionExpressionArgumentList arguments,
const std::shared_ptr< ContextValue > &  contextValue 
)
private

Evaluate the given function expression arguments.

Evalutate an ast::ExpressionNode on the current context to a Json value and evaluate ast::ExpressionArgumentNode to its child ast::ExpressionNode.

Parameters
[in]argumentsList of arguments.
[in]contextValueA context used for evaluating the arguments.
Returns
List of evaluated function arguments, suitable for passing to built in functions.
void jmespath::interpreter::Interpreter::evaluateLogicOperator ( const ast::BinaryExpressionNode node,
bool  shortCircuitValue 
)
private

Evaluates a binary logic operator to the result of the left side expression if it's binary value equals to shortCircuitValue otherwise evaluates it to the result of the result of the right side expression.

Parameters
[in]nodePointer to the node.
[in]shortCircuitValueSpecifies what should be the boolean value of the left side expression's result to do short circuit evaluation.
void jmespath::interpreter::Interpreter::evaluateProjection ( const ast::ExpressionNode expression)
virtual

Evaluates the projection of the given expression on the current context.

Parameters
[in]expressionThe expression that gets projected.
template<typename JsonT >
void jmespath::interpreter::Interpreter::evaluateProjection ( const ast::ExpressionNode expression,
JsonT &&  context 
)
private

Evaluates the projection of the given expression with the evaluation context.

Parameters
[in]expressionThe expression that gets projected.
[in]contextAn const lvalue reference or an rvalue reference to the evaluation context.
Template Parameters
JsonTThe type of the context.
void jmespath::interpreter::Interpreter::floor ( FunctionArgumentList arguments)
private

Rounds down the first item of the given arguments to the next lowest integer value. The first item should be a Json number.

Parameters
[in]argumentsThe list of the function's arguments.
Exceptions
InvalidFunctionArgumentType
template<typename T >
T & jmespath::interpreter::Interpreter::getArgument ( FunctionArgument argument) const
private

Converts the given function argument to the requsted type.

Parameters
[in]argumentA funciton argument value.
Template Parameters
TThe to which the argument should be converted.
Returns
The value held by the funciton argument.
Exceptions
InvalidFunctionArgumentType
const Json & jmespath::interpreter::Interpreter::getJsonArgument ( FunctionArgument argument) const
private

Creates a reference to the Json value held by the argument.

Parameters
argumentA funciton argument value.
Returns
Rreference to the Json value held by the argument.
Exceptions
InvalidFunctionArgumentType
bool jmespath::interpreter::Interpreter::isComparableArray ( const Json array) const
private

Checks whether array is a homogeneous array which contains comparable types like strings and numbers.

Parameters
[in]arrayThe Json value that should be tested.
Returns
Returns true if array is a comparable array, otherwise returns false.
void jmespath::interpreter::Interpreter::join ( FunctionArgumentList arguments)
private

Joins every item in the array provided as the second item of the given arguments with the first item as a separator. The first item must be a string and the second item must be an array of strings.

Parameters
[in]argumentsThe list of the function's arguments.
Exceptions
InvalidFunctionArgumentType
void jmespath::interpreter::Interpreter::keys ( FunctionArgumentList arguments)
private

Extracts the keys from the object provided as the first item of the given arguments.

Parameters
[in]argumentsThe list of the function's arguments.
Exceptions
InvalidFunctionArgumentType
void jmespath::interpreter::Interpreter::length ( FunctionArgumentList arguments)
private

Returns the length of the first item in the given arguments. The first item must be either an array a string or an object.

Parameters
[in]argumentsThe list of the function's arguments.
Exceptions
InvalidFunctionArgumentType
void jmespath::interpreter::Interpreter::map ( FunctionArgumentList arguments)
private

Applies the expression provided as the first item in the given arguments to every item in the array provided as the second item in arguments.

Parameters
[in]argumentsThe list of the function's arguments.
Exceptions
InvalidFunctionArgumentType
template<typename JsonT >
void jmespath::interpreter::Interpreter::map ( const ast::ExpressionNode node,
JsonT &&  array 
)
private

Applies the expression provided in node to every item in the array.

Parameters
[in]nodePointer to the expresson node.
[in]arrayEither an lvalue or rvalue reference to a Json array.
Template Parameters
JsonTThe type of the array.
Exceptions
InvalidFunctionArgumentType
void jmespath::interpreter::Interpreter::max ( FunctionArgumentList arguments,
const JsonComparator comparator 
)
private

Finds the largest item in the array provided as the first item in the arguments, it must either be an array of numbers or an array of strings.

Parameters
[in]argumentsThe list of the function's arguments.
[in]comparatorThe comparator function used for comparing Json values. It should return true if its first argument is less then its second argument.
Exceptions
InvalidFunctionArgumentType
template<typename JsonT >
void jmespath::interpreter::Interpreter::max ( const JsonComparator comparator,
JsonT &&  array 
)
private

Finds the largest item in the array, it must either be an array of numbers or an array of strings.

Parameters
[in]comparatorThe comparator function used for comparing Json values. It should return true if its first argument is less then its second argument.
[in]arrayA Json array.
Template Parameters
JsonTThe type of array.
Exceptions
InvalidFunctionArgumentType
void jmespath::interpreter::Interpreter::maxBy ( FunctionArgumentList arguments,
const JsonComparator comparator = std::less<Json>{} 
)
private

Finds the largest item in the array provided as the first item in the arguments, which must either be an array of numbers or an array of strings, using the expression provided as the second item in arguments as a key for comparison.

Parameters
[in]argumentsThe list of the function's arguments.
[in]comparatorThe comparator function used for comparing Json values. It should return true if its first argument is less then its second argument.
Exceptions
InvalidFunctionArgumentType
template<typename JsonT >
void jmespath::interpreter::Interpreter::maxBy ( const ast::ExpressionNode expression,
const JsonComparator comparator,
JsonT &&  array 
)
private

Finds the largest item in the array, which must either be an array of numbers or an array of strings, using the expression as a key for comparison.

Parameters
[in]expressionThe expression which evaluates to the key that should be used for comparisons.
[in]comparatorThe comparator function used for comparing Json values. It should return true if its first argument is less then its second argument.
[in]arrayA Json array.
Template Parameters
JsonTThe type of the array.
Exceptions
InvalidFunctionArgumentType
void jmespath::interpreter::Interpreter::merge ( FunctionArgumentList arguments)
private

Accepts zero or more objects in the given arguments, and returns a single object with subsequent objects merged. Each subsequent object’s key/value pairs are added to the preceding object.

Parameters
[in]argumentsThe list of the function's arguments.
Exceptions
InvalidFunctionArgumentType
template<typename JsonT >
void jmespath::interpreter::Interpreter::mergeObject ( Json object,
JsonT &&  sourceObject 
)
private

Merges the items of the sourceObject into object.

Parameters
[in,out]objectThe object into which the items of the sourceObject should be added.
[in]sourceObjectither an lvalue or rvalue reference to a Json object.
Template Parameters
JsonTJsonT The type of the sourceObject.
void jmespath::interpreter::Interpreter::notNull ( FunctionArgumentList arguments)
private

Accepts one or more items in arguments, and will evaluate them in order until a non null argument is encounted.

Parameters
[in]argumentsThe list of the function's arguments.
Exceptions
InvalidFunctionArgumentType
void jmespath::interpreter::Interpreter::reverse ( FunctionArgumentList arguments)
private

Reverses the order of the first item in arguments. It must either be an array or a string.

Parameters
[in]argumentsThe list of the function's arguments.
Exceptions
InvalidFunctionArgumentType
void jmespath::interpreter::Interpreter::reverse ( Json &&  subject)
private

Reverses the order of the subject. It must either be an array or a string.

Parameters
[in]subjectA Json array or string.
Exceptions
InvalidFunctionArgumentType
template<typename JsonT >
std::enable_if_t<std::is_same<std::decay_t<JsonT>, Json>::value, void> jmespath::interpreter::Interpreter::setContext ( JsonT &&  value)
inline

Sets the context of the evaluation.

Parameters
[in]valueJson document to be used as the context.
void jmespath::interpreter::Interpreter::sort ( FunctionArgumentList arguments)
private

Sorts the first item in the given arguments, which must either be an array of numbers or an array of strings.

Parameters
[in]argumentsThe list of the function's arguments.
Exceptions
InvalidFunctionArgumentType
void jmespath::interpreter::Interpreter::sort ( Json &&  array)
private

Sorts the array, which must either be an array of numbers or an array of strings.

Parameters
[in]arrayA Json array of number or strings.
Exceptions
InvalidFunctionArgumentType
void jmespath::interpreter::Interpreter::sortBy ( FunctionArgumentList arguments)
private

Sorts the first item in the given arguments, which must either be an array of numbers or an array of strings. It uses the expression provided as the second item in arguments as the sort key.

Parameters
[in]argumentsThe list of the function's arguments.
Exceptions
InvalidFunctionArgumentType
void jmespath::interpreter::Interpreter::sortBy ( const ast::ExpressionNode expression,
Json &&  array 
)
private

Sorts the array, which must either be an array of numbers or an array of strings. It uses the expression as the sort key.

Parameters
[in]expressionThe expression which evaluates to the key that should be used for comparisons during sorting.
[in]arrayA Json array of numbers or strings.
Exceptions
InvalidFunctionArgumentType
void jmespath::interpreter::Interpreter::startsWith ( FunctionArgumentList arguments)
private

Checks wheather the string provided as the first item in arguments starts with the string provided as the second item in arguments.

Parameters
[in]argumentsThe list of the function's arguments.
Exceptions
InvalidFunctionArgumentType
void jmespath::interpreter::Interpreter::sum ( FunctionArgumentList arguments)
private

Calculates the sum of the numbers in the array provided as the first item of arguments.

Parameters
[in]argumentsThe list of the function's arguments.
Exceptions
InvalidFunctionArgumentType
void jmespath::interpreter::Interpreter::toArray ( FunctionArgumentList arguments)
private

Converts the first item of the given arguments to a one element array if it's not already an array.

Parameters
[in]argumentsThe list of the function's arguments.
Exceptions
InvalidFunctionArgumentType
template<typename JsonT >
void jmespath::interpreter::Interpreter::toArray ( JsonT &&  value)
private

Converts the given value to a one element array if it's not already an array.

Parameters
[in]valueA Json value.
Template Parameters
JsonTThe type of the value.
bool jmespath::interpreter::Interpreter::toBoolean ( const Json json) const
private

Converts the json value to a boolean.

Parameters
[in]jsonThe Json value that needs to be converted.
Returns
Returns false if json is a false like value (false, 0, empty list, empty object, empty string, null), otherwise returns true.
void jmespath::interpreter::Interpreter::toNumber ( FunctionArgumentList arguments)
private

Converts the string provided as the first item in the given arguments to a number. If it's already a number then the original value is returned, all other Json types are converted to null.

Parameters
[in]argumentsThe list of the function's arguments.
Exceptions
InvalidFunctionArgumentType
template<typename JsonT >
void jmespath::interpreter::Interpreter::toNumber ( JsonT &&  value)
private

Converts the value to a number if it's not already a number, all other Json types are converted to null.

Parameters
[in]valueA Json value.
Template Parameters
JsonTThe type of the value.
void jmespath::interpreter::Interpreter::toString ( FunctionArgumentList arguments)
private

Converts the first item of the given arguments to the Json encoded value if it's not already a string.

Parameters
[in]argumentsThe list of the function's arguments.
Exceptions
InvalidFunctionArgumentType
template<typename JsonT >
void jmespath::interpreter::Interpreter::toString ( JsonT &&  value)
private

Converts the given value to the Json encoded value if it's not already a string.

Parameters
[in]valueA Json value.
Template Parameters
JsonTThe type of the value.
void jmespath::interpreter::Interpreter::type ( FunctionArgumentList arguments)
private

Returns the type of the Json value provided as the first item in arguments.

Parameters
[in]argumentsThe list of the function's arguments.
Exceptions
InvalidFunctionArgumentType
void jmespath::interpreter::Interpreter::values ( FunctionArgumentList arguments)
private

Extracts the values from the object provided as the first item of the given arguments.

Parameters
[in]argumentsThe list of the function's arguments.
Exceptions
InvalidFunctionArgumentType
template<typename JsonT >
void jmespath::interpreter::Interpreter::values ( JsonT &&  object)
private

Extracts the values from the object.

Parameters
[in]objectA Json object.
Template Parameters
JsonTThe type of object.
Exceptions
InvalidFunctionArgumentType
void jmespath::interpreter::Interpreter::visit ( const ast::AbstractNode node)
overridevirtual

Evaluate the given node on the current context value.

Parameters
[in]nodePointer to the node

Implements jmespath::interpreter::AbstractVisitor.

void jmespath::interpreter::Interpreter::visit ( const ast::ExpressionNode node)
overridevirtual

Evaluate the given node on the current context value.

Parameters
[in]nodePointer to the node

Implements jmespath::interpreter::AbstractVisitor.

void jmespath::interpreter::Interpreter::visit ( const ast::IdentifierNode node)
overridevirtual

Evaluate the given node on the current context value.

Parameters
[in]nodePointer to the node

Implements jmespath::interpreter::AbstractVisitor.

void jmespath::interpreter::Interpreter::visit ( const ast::RawStringNode node)
overridevirtual

Evaluate the given node on the current context value.

Parameters
[in]nodePointer to the node

Implements jmespath::interpreter::AbstractVisitor.

void jmespath::interpreter::Interpreter::visit ( const ast::LiteralNode node)
overridevirtual

Evaluate the given node on the current context value.

Parameters
[in]nodePointer to the node

Implements jmespath::interpreter::AbstractVisitor.

void jmespath::interpreter::Interpreter::visit ( const ast::SubexpressionNode node)
overridevirtual

Evaluate the given node on the current context value.

Parameters
[in]nodePointer to the node

Implements jmespath::interpreter::AbstractVisitor.

void jmespath::interpreter::Interpreter::visit ( const ast::IndexExpressionNode node)
overridevirtual

Evaluate the given node on the current context value.

Parameters
[in]nodePointer to the node

Implements jmespath::interpreter::AbstractVisitor.

void jmespath::interpreter::Interpreter::visit ( const ast::ArrayItemNode node)
overridevirtual

Evaluate the given node on the current context value.

Parameters
[in]nodePointer to the node

Implements jmespath::interpreter::AbstractVisitor.

void jmespath::interpreter::Interpreter::visit ( const ast::FlattenOperatorNode node)
overridevirtual

Evaluate the given node on the current context value.

Parameters
[in]nodePointer to the node

Implements jmespath::interpreter::AbstractVisitor.

void jmespath::interpreter::Interpreter::visit ( const ast::BracketSpecifierNode node)
overridevirtual

Evaluate the given node on the current context value.

Parameters
[in]nodePointer to the node

Implements jmespath::interpreter::AbstractVisitor.

void jmespath::interpreter::Interpreter::visit ( const ast::SliceExpressionNode node)
overridevirtual

Evaluate the given node on the current context value.

Parameters
[in]nodePointer to the node

Implements jmespath::interpreter::AbstractVisitor.

void jmespath::interpreter::Interpreter::visit ( const ast::ListWildcardNode )
overridevirtual

Evaluate the given node on the current context value.

Parameters
[in]nodePointer to the node

Implements jmespath::interpreter::AbstractVisitor.

void jmespath::interpreter::Interpreter::visit ( const ast::HashWildcardNode node)
overridevirtual

Evaluate the given node on the current context value.

Parameters
[in]nodePointer to the node

Implements jmespath::interpreter::AbstractVisitor.

void jmespath::interpreter::Interpreter::visit ( const ast::MultiselectListNode node)
overridevirtual

Evaluate the given node on the current context value.

Parameters
[in]nodePointer to the node

Implements jmespath::interpreter::AbstractVisitor.

void jmespath::interpreter::Interpreter::visit ( const ast::MultiselectHashNode node)
overridevirtual

Evaluate the given node on the current context value.

Parameters
[in]nodePointer to the node

Implements jmespath::interpreter::AbstractVisitor.

void jmespath::interpreter::Interpreter::visit ( const ast::NotExpressionNode node)
overridevirtual

Evaluate the given node on the current context value.

Parameters
[in]nodePointer to the node

Implements jmespath::interpreter::AbstractVisitor.

void jmespath::interpreter::Interpreter::visit ( const ast::ComparatorExpressionNode node)
overridevirtual

Evaluate the given node on the current context value.

Parameters
[in]nodePointer to the node

Implements jmespath::interpreter::AbstractVisitor.

void jmespath::interpreter::Interpreter::visit ( const ast::OrExpressionNode node)
overridevirtual

Evaluate the given node on the current context value.

Parameters
[in]nodePointer to the node

Implements jmespath::interpreter::AbstractVisitor.

void jmespath::interpreter::Interpreter::visit ( const ast::AndExpressionNode node)
overridevirtual

Evaluate the given node on the current context value.

Parameters
[in]nodePointer to the node

Implements jmespath::interpreter::AbstractVisitor.

void jmespath::interpreter::Interpreter::visit ( const ast::ParenExpressionNode node)
overridevirtual

Evaluate the given node on the current context value.

Parameters
[in]nodePointer to the node

Implements jmespath::interpreter::AbstractVisitor.

void jmespath::interpreter::Interpreter::visit ( const ast::PipeExpressionNode node)
overridevirtual

Evaluate the given node on the current context value.

Parameters
[in]nodePointer to the node

Implements jmespath::interpreter::AbstractVisitor.

void jmespath::interpreter::Interpreter::visit ( const ast::CurrentNode )
overridevirtual

Evaluate the given node on the current context value.

Parameters
[in]nodePointer to the node

Implements jmespath::interpreter::AbstractVisitor.

void jmespath::interpreter::Interpreter::visit ( const ast::FilterExpressionNode node)
overridevirtual

Evaluate the given node on the current context value.

Parameters
[in]nodePointer to the node

Implements jmespath::interpreter::AbstractVisitor.

void jmespath::interpreter::Interpreter::visit ( const ast::FunctionExpressionNode node)
overridevirtual

Evaluate the given node on the current context value.

Parameters
[in]nodePointer to the node

Implements jmespath::interpreter::AbstractVisitor.

void jmespath::interpreter::Interpreter::visit ( const ast::ExpressionArgumentNode )
overridevirtual

Evaluate the given node on the current context value.

Parameters
[in]nodePointer to the node

Implements jmespath::interpreter::AbstractVisitor.

template<typename JsonT >
void jmespath::interpreter::Interpreter::visit ( const ast::IdentifierNode node,
JsonT &&  context 
)
private

Evaluates the given node on the evaluation context.

Parameters
[in]nodePointer to the node.
[in]contextAn const lvalue reference or an rvalue reference to the evaluation context.
Template Parameters
JsonTThe type of the context.
template<typename JsonT >
void jmespath::interpreter::Interpreter::visit ( const ast::ArrayItemNode node,
JsonT &&  context 
)
private

Evaluates the given node on the evaluation context.

Parameters
[in]nodePointer to the node.
[in]contextAn const lvalue reference or an rvalue reference to the evaluation context.
Template Parameters
JsonTThe type of the context.
template<typename JsonT >
void jmespath::interpreter::Interpreter::visit ( const ast::FlattenOperatorNode node,
JsonT &&  context 
)
private

Evaluates the given node on the evaluation context.

Parameters
[in]nodePointer to the node.
[in]contextAn const lvalue reference or an rvalue reference to the evaluation context.
Template Parameters
JsonTThe type of the context.
template<typename JsonT >
void jmespath::interpreter::Interpreter::visit ( const ast::SliceExpressionNode node,
JsonT &&  context 
)
private

Evaluates the given node on the evaluation context.

Parameters
[in]nodePointer to the node.
[in]contextAn const lvalue reference or an rvalue reference to the evaluation context.
Template Parameters
JsonTThe type of the context.
template<typename JsonT >
void jmespath::interpreter::Interpreter::visit ( const ast::HashWildcardNode node,
JsonT &&  context 
)
private

Evaluates the given node on the evaluation context.

Parameters
[in]nodePointer to the node.
[in]contextAn const lvalue reference or an rvalue reference to the evaluation context.
Template Parameters
JsonTThe type of the context.
template<typename JsonT >
void jmespath::interpreter::Interpreter::visit ( const ast::FilterExpressionNode node,
JsonT &&  context 
)
private

Evaluates the given node on the evaluation context.

Parameters
[in]nodePointer to the node.
[in]contextAn const lvalue reference or an rvalue reference to the evaluation context.
Template Parameters
JsonTThe type of the context.

Member Data Documentation

ContextValue jmespath::interpreter::Interpreter::m_context
private

Stores the evaluation context.

std::unordered_map<String, FunctionDescriptor> jmespath::interpreter::Interpreter::m_functionMap
private

Maps the JMESPath built in function names to their implementations.


The documentation for this class was generated from the following files: