make UDQASTNode constructible from variables

also make it default constructible, add accessors
and equality operator
This commit is contained in:
Arne Morten Kvarving
2019-12-12 11:12:46 +01:00
parent 9c991241c0
commit 6720e6a6cb
2 changed files with 82 additions and 1 deletions

View File

@@ -35,13 +35,19 @@ namespace Opm {
class UDQASTNode {
public:
UDQASTNode();
explicit UDQASTNode(UDQTokenType type_arg);
explicit UDQASTNode(double scalar_value);
UDQASTNode(UDQTokenType type_arg, const std::string& func_name, const UDQASTNode& arg);
UDQASTNode(UDQTokenType type_arg, const std::string& func_name, const UDQASTNode& left, const UDQASTNode& right);
UDQASTNode(UDQTokenType type_arg, const std::string& func_name);
UDQASTNode(UDQTokenType type_arg, const std::string& string_value, const std::vector<std::string>& selector);
UDQASTNode(UDQVarType varType, UDQTokenType typ,
const std::string& stringVal,
double scalarVal,
const std::vector<std::string>& selectors,
const std::shared_ptr<UDQASTNode>& left_arg,
const std::shared_ptr<UDQASTNode>& right_arg);
UDQSet eval(UDQVarType eval_target, const UDQContext& context) const;
@@ -53,6 +59,16 @@ public:
void set_right(const UDQASTNode& arg);
UDQASTNode* get_left() const;
UDQASTNode* get_right() const;
bool operator==(const UDQASTNode& data) const;
const std::string& stringValue() const;
UDQTokenType getType() const;
double scalarValue() const;
const std::vector<std::string>& getSelectors() const;
const std::shared_ptr<UDQASTNode>& getLeft() const;
const std::shared_ptr<UDQASTNode>& getRight() const;
private:
UDQTokenType type;
void func_tokens(std::set<UDQTokenType>& tokens) const;

View File

@@ -25,6 +25,9 @@
namespace Opm {
UDQASTNode::UDQASTNode() :
UDQASTNode(UDQTokenType::error)
{}
UDQASTNode::UDQASTNode(UDQTokenType type_arg) :
@@ -101,6 +104,22 @@ UDQASTNode::UDQASTNode(UDQTokenType type_arg,
}
UDQASTNode::UDQASTNode(UDQVarType varType, UDQTokenType typ,
const std::string& stringVal,
double scalarVal,
const std::vector<std::string>& selectors,
const std::shared_ptr<UDQASTNode>& left_arg,
const std::shared_ptr<UDQASTNode>& right_arg) :
var_type(varType),
type(typ),
string_value(stringVal),
selector(selectors),
scalar_value(scalarVal),
left(left_arg),
right(right_arg)
{}
UDQASTNode::UDQASTNode(UDQTokenType type_arg,
const std::string& string_value_arg,
const std::vector<std::string>& selector_arg) :
@@ -274,4 +293,50 @@ void UDQASTNode::set_right(const UDQASTNode& arg) {
this->update_type(arg);
}
bool UDQASTNode::operator==(const UDQASTNode& data) const {
if ((this->getLeft() && !data.getLeft()) ||
(!this->getLeft() && data.getLeft()))
return false;
if (this->getLeft() && !(*this->getLeft() == *data.getLeft()))
return false;
if ((this->getRight() && !data.getRight()) ||
(!this->getRight() && data.getRight()))
return false;
if (this->getRight() && !(*this->getRight() == *data.getRight()))
return false;
return type == data.type &&
var_type == data.var_type &&
string_value == data.string_value &&
scalar_value == data.scalar_value &&
selector == data.selector;
}
const std::string& UDQASTNode::stringValue() const {
return string_value;
}
double UDQASTNode::scalarValue() const {
return scalar_value;
}
const std::vector<std::string>& UDQASTNode::getSelectors() const {
return selector;
}
const std::shared_ptr<UDQASTNode>& UDQASTNode::getLeft() const {
return left;
}
const std::shared_ptr<UDQASTNode>& UDQASTNode::getRight() const {
return right;
}
UDQTokenType UDQASTNode::getType() const {
return type;
}
}