opm-common
ActionAST.hpp
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 #ifndef ActionAST_HPP
21 #define ActionAST_HPP
22 
23 #include <opm/input/eclipse/Schedule/Action/ActionResult.hpp>
24 
25 #include <memory>
26 #include <string>
27 #include <unordered_set>
28 #include <vector>
29 
30 namespace Opm::Action {
31 
32 class Context;
33 class ASTNode;
34 
35 } // namespace Opm::Action
36 
37 namespace Opm::Action {
38 
44 
45 class AST
46 {
47 public:
52  AST();
53 
61  explicit AST(const std::vector<std::string>& tokens);
62 
64  ~AST();
65 
69  AST(const AST& rhs);
70 
75  AST(AST&& rhs);
76 
82  AST& operator=(const AST& rhs);
83 
90  AST& operator=(AST&& rhs);
91 
94 
103  Result eval(const Context& context) const;
104 
111  bool operator==(const AST& data) const;
112 
118  template<class Serializer>
119  void serializeOp(Serializer& serializer)
120  {
121  serializer(condition);
122  }
123 
130  void required_summary(std::unordered_set<std::string>& required_summary) const;
131 
132 private:
134  std::unique_ptr<ASTNode> condition{};
135 };
136 
137 } // namespace Opm::Action
138 
139 #endif // ActionAST_HPP
Definition: Python.hpp:35
void serializeOp(Serializer &serializer)
Convert between byte array and object representation.
Definition: ActionAST.hpp:119
AST()
Default constructor.
bool operator==(const AST &data) const
Equality predicate.
Definition: ActionAST.cpp:94
Manager of summary vector values.
Definition: ActionContext.hpp:41
static AST serializationTestObject()
Create a serialisation test object.
Definition: ActionAST.cpp:76
~AST()
Destructor.
Expression evaluation tree of a full ACTIONX condition block.
Definition: ActionAST.hpp:45
Result eval(const Context &context) const
Evaluate the expression tree at current dynamic state.
Definition: ActionAST.cpp:85
void required_summary(std::unordered_set< std::string > &required_summary) const
Export all summary vectors needed to evaluate the expression tree.
Definition: ActionAST.cpp:102
AST & operator=(const AST &rhs)
Assignment operator.
Definition: ActionAST.cpp:52
Class for (de-)serializing.
Definition: Serializer.hpp:94
Class Action::Result holds the boolean result of a ACTIONX condition like.
Definition: ActionResult.hpp:68