Introduce convenience functions to convert int <-> Actionx OR/AND
This commit is contained in:
@@ -90,6 +90,8 @@ enum class Comparator {
|
|||||||
|
|
||||||
std::string cmp_string;
|
std::string cmp_string;
|
||||||
|
|
||||||
|
static Logical logic_from_int(int);
|
||||||
|
int logic_as_int() const;
|
||||||
bool open_paren() const;
|
bool open_paren() const;
|
||||||
bool close_paren() const;
|
bool close_paren() const;
|
||||||
bool operator==(const Condition& data) const;
|
bool operator==(const Condition& data) const;
|
||||||
|
|||||||
@@ -103,11 +103,6 @@ const std::map<std::string, int> rhsQuantityToIndex = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
using logic_enum = Opm::Action::Condition::Logical;
|
using logic_enum = Opm::Action::Condition::Logical;
|
||||||
const std::map<logic_enum, int> logicalToIndex_13 = {
|
|
||||||
{logic_enum::AND, 1},
|
|
||||||
{logic_enum::OR, 2},
|
|
||||||
{logic_enum::END, 0},
|
|
||||||
};
|
|
||||||
|
|
||||||
const std::map<logic_enum, int> logicalToIndex_17 = {
|
const std::map<logic_enum, int> logicalToIndex_17 = {
|
||||||
{logic_enum::AND, 1},
|
{logic_enum::AND, 1},
|
||||||
@@ -406,18 +401,7 @@ const std::map<cmp_enum, int> cmpToIndex = {
|
|||||||
iAcn[ind + 12] = it_lhs_it->second;
|
iAcn[ind + 12] = it_lhs_it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*item [13] - relates to operator
|
iAcn[ind + 13] = cond.logic_as_int();
|
||||||
OR is 2
|
|
||||||
AND is 1
|
|
||||||
*/
|
|
||||||
const auto it_logic_13 = logicalToIndex_13.find(cond.logic);
|
|
||||||
if (it_logic_13 != logicalToIndex_13.end()) {
|
|
||||||
iAcn[ind + 13] = it_logic_13->second;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
std::cout << "Unknown Boolean operator type for condition: " << cond.lhs.quantity << std::endl;
|
|
||||||
throw std::invalid_argument("Actionx: " + actx.name());
|
|
||||||
}
|
|
||||||
|
|
||||||
/* item[15] is a parameter that indicates whether left_paren or right_paren is used in an expression
|
/* item[15] is a parameter that indicates whether left_paren or right_paren is used in an expression
|
||||||
* = 0 : no open_paren or left_paren, or both open_paren and right_paren
|
* = 0 : no open_paren or left_paren, or both open_paren and right_paren
|
||||||
|
|||||||
@@ -170,6 +170,31 @@ bool Condition::close_paren() const {
|
|||||||
return !this->left_paren && this->right_paren;
|
return !this->left_paren && this->right_paren;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Condition::Logical Condition::logic_from_int(int int_logic) {
|
||||||
|
if (int_logic == 0)
|
||||||
|
return Logical::END;
|
||||||
|
|
||||||
|
if (int_logic == 1)
|
||||||
|
return Logical::AND;
|
||||||
|
|
||||||
|
if (int_logic == 2)
|
||||||
|
return Logical::OR;
|
||||||
|
|
||||||
|
throw std::logic_error("Unknown integer value");
|
||||||
|
}
|
||||||
|
|
||||||
|
int Condition::logic_as_int() const {
|
||||||
|
switch (this->logic) {
|
||||||
|
case Logical::END:
|
||||||
|
return 0;
|
||||||
|
case Logical::AND:
|
||||||
|
return 1;
|
||||||
|
case Logical::OR:
|
||||||
|
return 2;
|
||||||
|
default:
|
||||||
|
throw std::logic_error("What the f...?");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user