ActionAST.hpp
Go to the documentation of this file.
1/*
2 Copyright 2018 Equinor ASA.
3
4 This file is part of the Open Porous Media project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20
21#ifndef ActionAST_HPP
22#define ActionAST_HPP
23
24#include <string>
25#include <vector>
26#include <memory>
27
29
30namespace Opm {
31namespace Action {
32
33class Context;
34class ASTNode;
35
36
37/*
38 The Action::AST class implements a tree with the result of the parsing of the
39 ACTIONX condition. The AST does not contain any context, that is supplied with
40 a Action::Context instace when calling the eval() methoid is called.
41*/
42
43class AST{
44public:
45 AST() = default;
46 explicit AST(const std::vector<std::string>& tokens);
47
49
50 Result eval(const Context& context) const;
51
52 bool operator==(const AST& data) const;
53
54 template<class Serializer>
55 void serializeOp(Serializer& serializer)
56 {
57 serializer(condition);
58 }
59
60private:
61 /*
62 The use of a pointer here is to be able to create this class with only a
63 forward declaration of the ASTNode class. Would have prefered to use a
64 unique_ptr, but that requires writing custom destructors - the use of a
65 shared_ptr does not imply any shared ownership of the ASTNode.
66 */
67 std::shared_ptr<ASTNode> condition;
68};
69}
70}
71#endif
Definition: ASTNode.hpp:13
Definition: ActionAST.hpp:43
static AST serializeObject()
AST(const std::vector< std::string > &tokens)
Result eval(const Context &context) const
bool operator==(const AST &data) const
void serializeOp(Serializer &serializer)
Definition: ActionAST.hpp:55
Definition: ActionContext.hpp:38
Definition: ActionResult.hpp:89
Definition: Serializer.hpp:38
Action
Definition: InputErrorAction.hpp:36
Definition: A.hpp:4
static std::string data()
Definition: exprtk.hpp:40022