9 : attributeRegistry(attributeRegistry)
10 , expression(expression)
11 , compiled(getExpression(expression))
14 if (
auto name =
compiled.getTarget(); name.has_value() ) {
15 if ( name.value() == BPMNOS::Keyword::Undefined ) {
16 throw std::runtime_error(
"Expression: illegal assignment '" + expression +
"'");
23 for (
auto& name : compiled.getVariables() ) {
24 if ( name != BPMNOS::Keyword::Undefined ) {
25 auto attribute = attributeRegistry[ name ];
26 inputs.insert(attribute);
27 variables.push_back(attribute);
30 for (
auto& name : compiled.getCollections() ) {
31 if ( name == BPMNOS::Keyword::Undefined ) {
32 throw std::runtime_error(
"Expression: illegal expression '" + expression +
"'");
34 auto attribute = attributeRegistry[ name ];
35 inputs.insert(attribute);
36 collections.push_back(attribute);
40LIMEX::Expression<double> Expression::getExpression(
const std::string& input)
const {
44 catch (
const std::exception& error ) {
45 throw std::runtime_error(
"Expression: illegal expression '" + input +
"'.\n" + error.what());
50 auto& variableNames =
compiled.getVariables();
51 assert(
compiled.getRoot().operands.size() == 1 );
52 assert(
compiled.getRoot().type == LIMEX::Type::group );
58 auto& node = std::get< LIMEX::Node<double> >(root.operands[0]);
60 if ( node.type == LIMEX::Type::assign ) {
61 assert( node.operands.size() == 1 );
63 !std::holds_alternative< LIMEX::Node<double> >(node.operands[0]) ||
64 std::get< LIMEX::Node<double> >(node.operands[0]).type != LIMEX::Type::variable
66 throw std::runtime_error(
"Expression: illegal assignment '" +
expression +
"'");
71 if ( node.type != LIMEX::Type::equal_to && node.type != LIMEX::Type::not_equal_to ) {
72 throw std::runtime_error(
"Expression: illegal expression '" +
expression +
"'");
75 assert( node.operands.size() == 2 );
76 assert( std::holds_alternative< LIMEX::Node<double> >(node.operands[0]) );
77 assert( std::holds_alternative< LIMEX::Node<double> >(node.operands[1]) );
78 auto& lhs = std::get< LIMEX::Node<double> >(node.operands[0]);
79 auto& rhs = std::get< LIMEX::Node<double> >(node.operands[1]);
80 assert( !lhs.operands.empty() );
81 assert( !rhs.operands.empty() );
84 lhs.type != LIMEX::Type::variable ||
86 rhs.type != LIMEX::Type::variable ||
89 throw std::runtime_error(
"Expression: illegal comparison '" +
expression +
"'");
99 assert(
compiled.getRoot().operands.size() == 1 );
100 assert(
compiled.getRoot().type == LIMEX::Type::group );
102 auto& node = std::get< LIMEX::Node<double> >(root.operands[0]);
103 if ( node.type == LIMEX::Type::variable ) {
110template <
typename DataType>
118 return number( (
double)!value.has_value() );
123 return number( (
double)value.has_value() );
127 std::vector< double > variableValues;
130 if ( !value.has_value() ) {
134 variableValues.push_back( (
double)value.value() );
138 std::vector< std::vector< double > > collectionValues;
140 collectionValues.push_back( {} );
142 if ( !collection.has_value() ) {
147 if ( !value.has_value() ) {
151 collectionValues.back().push_back( (
double)value.value() );
155 return number(
compiled.evaluate(variableValues,collectionValues));
CollectionRegistry collectionRegistry
std::optional< BPMNOS::number > getValue(const Attribute *attribute, const Values &status, const Values &data, const Values &globals) const
const AttributeRegistry & attributeRegistry
Expression(const std::string expression, const AttributeRegistry &attributeRegistry, bool newTarget=false)
const Attribute * isAttribute() const
Returns pointer to the attribute if and only if expression contains nothing else.
std::set< const Attribute * > inputs
Vector containing all input attributes and collections used by the expression.
std::optional< const Attribute * > target
const LIMEX::Expression< double > compiled
std::vector< const Attribute * > variables
Vector containing all input attributes used by the expression.
const std::string expression
std::vector< const Attribute * > collections
Vector containing all input collections used by the expression.
std::optional< BPMNOS::number > execute(const BPMNOS::Values &status, const DataType &data, const BPMNOS::Values &globals) const
const std::string Undefined
std::string encodeQuotedStrings(std::string text)
BPMNOS_NUMBER_TYPE number