Loading...
Searching...
No Matches
ASTNode.hpp
/*
Copyright 2019 Equinor ASA.
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ASTNODE_HPP
#define ASTNODE_HPP
#include <opm/input/eclipse/Schedule/Action/ActionValue.hpp>
#include <cstddef>
#include <string>
#include <string_view>
#include <unordered_set>
#include <vector>
namespace Opm::Action {
class Context;
} // namespace Opm::Action
namespace Opm::Action {
class ASTNode
{
public:
ASTNode();
explicit ASTNode(TokenType type_arg);
explicit ASTNode(double value);
explicit ASTNode(TokenType type_arg,
FuncType func_type_arg,
std::string_view func_arg,
const std::vector<std::string>& arg_list_arg);
TokenType type;
FuncType func_type;
std::string func;
static ASTNode serializationTestObject();
void add_child(ASTNode&& child);
Result eval(const Context& context) const;
void required_summary(std::unordered_set<std::string>& required_summary) const;
bool operator==(const ASTNode& that) const;
std::size_t size() const;
bool empty() const;
template<class Serializer>
void serializeOp(Serializer& serializer)
{
serializer(type);
serializer(func_type);
serializer(func);
serializer(arg_list);
serializer(number);
serializer(children);
}
private:
// Note: data member order here is dictated by initialisation list in
// four-argument constructor.
std::vector<std::string> arg_list{};
double number {0.0};
// Note: a data member of type std::vector<ASTNode> inside class ASTNode
// is well defined in C++17 or later, but may look surprising to the
// uninitiated.
std::vector<ASTNode> children{};
Result evalLogicalOperation(const Context& context) const;
Result evalComparison(const Context& context) const;
Value nodeValue(const Context& context) const;
Value evalListExpression(const Context& context) const;
Value evalScalarExpression(const Context& context) const;
Value evalWellExpression(const Context& context) const;
std::vector<std::string> getWellList(const Context& context) const;
bool argListIsPattern() const;
bool argListIsWellList() const;
};
} // namespace Opm::Action
#endif // ASTNODE_HPP
Opm::Action::Context
Manager of summary vector values.
Definition ActionContext.hpp:42