summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/control.cc2
-rw-r--r--src/value.cc24
-rw-r--r--src/value.h2
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:
contact: Jan Huwald // Impressum