| 39 | } |
| 40 | |
| 41 | void |
| 42 | Value::set_value(const std::string &val, Statement *owner) |
| 43 | { |
| 44 | _value = val; |
| 45 | |
| 46 | if (_value.find("%{") != std::string::npos) { |
| 47 | HRWSimpleTokenizer tokenizer(_value); |
| 48 | auto tokens = tokenizer.get_tokens(); |
| 49 | |
| 50 | for (const auto &token : tokens) { |
| 51 | Condition *tcond_val = nullptr; |
| 52 | |
| 53 | if (token.substr(0, 2) == "%{") { |
| 54 | std::string cond_token = token.substr(2, token.size() - 3); |
| 55 | |
| 56 | if ((tcond_val = condition_factory(cond_token))) { |
| 57 | Parser parser; |
| 58 | |
| 59 | if (parser.parse_line(cond_token)) { |
| 60 | tcond_val->initialize(parser); |
| 61 | require_resources(tcond_val->get_resource_ids()); |
| 62 | } else { |
| 63 | // TODO: should we produce error here? |
| 64 | Dbg(dbg_ctl, "Error parsing value '%s'", _value.c_str()); |
| 65 | } |
| 66 | } |
| 67 | } else { |
| 68 | tcond_val = new ConditionStringLiteral(token); |
| 69 | } |
| 70 | |
| 71 | if (tcond_val) { |
| 72 | _cond_vals.push_back(tcond_val); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | // If we have an owner (e.g. an Operator) hoist up the resource requirements |
| 77 | if (owner) { |
| 78 | owner->require_resources(get_resource_ids()); |
| 79 | } |
| 80 | } else { |
| 81 | _int_value = strtol(_value.c_str(), nullptr, 10); |
| 82 | _float_value = strtod(_value.c_str(), nullptr); |
| 83 | } |
| 84 | } |