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
variantnode.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 VARIANTNODE_H
29 #define VARIANTNODE_H
30 #include "src/ast/abstractnode.h"
32 #include <boost/variant.hpp>
33 
34 namespace jmespath{ namespace ast{
35 
41 template <typename ...VariantT>
42 class VariantNode : public AbstractNode
43 {
44 public:
49  using ValueType = boost::variant<boost::blank, VariantT...>;
54  : AbstractNode()
55  {
56  }
60  VariantNode(const VariantNode&) = default;
66  template <typename T>
67  VariantNode(const T& other)
68  : AbstractNode()
69  {
70  *this = other;
71  }
77  VariantNode<VariantT...>& operator=(const VariantNode& other)
78  {
79  if (this != &other)
80  {
81  value = other.value;
82  }
83  return *this;
84  }
89  template <typename T>
90  VariantNode<VariantT...>& operator=(const T& other)
91  {
92  value = other;
93  return *this;
94  }
101  bool operator==(const VariantNode& other) const
102  {
103  if (this != &other)
104  {
105  return value == other.value;
106  }
107  return true;
108  }
114  bool isNull() const
115  {
116  return value.type() == typeid(boost::blank);
117  }
118 
119  void accept(interpreter::AbstractVisitor *visitor) const override
120  {
121  boost::apply_visitor(VariantVisitorAdaptor(visitor), value);
122  }
127 };
128 }} // namespace jmespath::ast
129 #endif // VARIANTNODE_H
VariantNode()
Constructs an empty VariantNode object.
Definition: variantnode.h:53
ValueType value
The variable which stores the node that this object represents.
Definition: variantnode.h:126
VariantNode(const T &other)
Copy constructs a VariantNode object if T is VariantNode or constructs a VariantNode object with T as...
Definition: variantnode.h:67
VariantNode< VariantT...> & operator=(const T &other)
Assigns the value of the other object to this object's internal variant making it the node that this ...
Definition: variantnode.h:90
The AbstractVisitor class is an interface which defines the member functions required to visit every ...
Definition: abstractvisitor.h:71
The VariantNode class serves as a container node which can represent either one of the node types spe...
Definition: variantnode.h:42
bool isNull() const
Returns whether this object has been initialized.
Definition: variantnode.h:114
VariantNode< VariantT...> & operator=(const VariantNode &other)
Assigns the other object's value to this object.
Definition: variantnode.h:77
bool operator==(const VariantNode &other) const
Equality compares this node to the other.
Definition: variantnode.h:101
The VariantVisitorAdaptor class adapts an AbstractVisitor implementation to the boost::static_visitor...
Definition: variantvisitoradaptor.h:40
void accept(interpreter::AbstractVisitor *visitor) const override
Accepts the given visitor object.
Definition: variantnode.h:119
The AbstractNode class is the common interface class for all AST node types.
Definition: abstractnode.h:45