diff options
author | Marius Kintel <marius@kintel.net> | 2011-09-08 06:52:21 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2011-09-08 06:52:21 (GMT) |
commit | 6659ad47b0b07b66b62ca79f3929d361733cc67a (patch) | |
tree | e4f0cbd7fa1e4b5dcb69daca43d3a7f33a1ed022 /src | |
parent | 5ce3d4ff8df274bbbb1b5dbd272179ad5765ded1 (diff) |
Updated boolean handling of if/else
Diffstat (limited to 'src')
-rw-r--r-- | src/control.cc | 2 | ||||
-rw-r--r-- | src/value.cc | 24 | ||||
-rw-r--r-- | src/value.h | 2 |
3 files changed, 27 insertions, 1 deletions
diff --git a/src/control.cc b/src/control.cc index c39b74a..492b909 100644 --- a/src/control.cc +++ b/src/control.cc @@ -149,7 +149,7 @@ AbstractNode *ControlModule::evaluate(const Context*, const ModuleInstantiation if (type == IF) { const IfElseModuleInstantiation *ifelse = dynamic_cast<const IfElseModuleInstantiation*>(inst); - if (ifelse->argvalues.size() > 0 && ifelse->argvalues[0].type == Value::BOOL && ifelse->argvalues[0].b) { + if (ifelse->argvalues.size() > 0 && ifelse->argvalues[0].toBool()) { std::vector<AbstractNode *> evaluatednodes = ifelse->evaluateChildren(); node->children.insert(node->children.end(), evaluatednodes.begin(), evaluatednodes.end()); } diff --git a/src/value.cc b/src/value.cc index 34566bd..53fd6dc 100644 --- a/src/value.cc +++ b/src/value.cc @@ -361,6 +361,30 @@ std::string Value::toString() const return stream.str(); } +bool Value::toBool() const +{ + switch (this->type) { + case STRING: + return this->text.size() > 0; + break; + case VECTOR: + return this->vec.size() > 0; + break; + case RANGE: + return true; + break; + case NUMBER: + return this->num != 0; + break; + case BOOL: + return this->b; + break; + default: + return false; + break; + } +} + /*! Append a value to this vector. This must be of type VECTOR. diff --git a/src/value.h b/src/value.h index 2003460..fb6500c 100644 --- a/src/value.h +++ b/src/value.h @@ -61,6 +61,8 @@ public: std::string toString() const; + bool toBool() const; + void append(Value *val); private: |