summaryrefslogtreecommitdiff
path: root/src/control.cc
diff options
context:
space:
mode:
authorTorsten Paul <Torsten.Paul@gmx.de>2013-11-10 01:42:58 (GMT)
committerTorsten Paul <Torsten.Paul@gmx.de>2013-11-11 00:31:44 (GMT)
commit00a329f0bd4ab940c1063106ee6ba7db7811a090 (patch)
tree26872901c9cbc603e7a62b14975e306b0e146885 /src/control.cc
parente5d535e900ae5bc5923fc76c80fb3b3f9153a80e (diff)
Add support for handling negative step values in ranges (fixes #500).
Diffstat (limited to 'src/control.cc')
-rw-r--r--src/control.cc24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/control.cc b/src/control.cc
index 10aadf0..6b10a28 100644
--- a/src/control.cc
+++ b/src/control.cc
@@ -78,12 +78,14 @@ void ControlModule::for_eval(AbstractNode &node, const ModuleInstantiation &inst
Context c(ctx);
if (it_values.type() == Value::RANGE) {
Value::RangeType range = it_values.toRange();
- range.normalize();
- if (range.nbsteps()<10000) {
- for (double i = range.begin; i <= range.end; i += range.step) {
- c.set_variable(it_name, Value(i));
- for_eval(node, inst, l+1, &c, evalctx);
- }
+ unsigned long steps = range.nbsteps();
+ if (steps >= 10000) {
+ PRINTB("WARNING: Bad range parameter in for statement: too many elements (%lu).", steps);
+ } else {
+ for (Value::RangeType::iterator it = range.begin();it != range.end();it++) {
+ c.set_variable(it_name, Value(*it));
+ for_eval(node, inst, l+1, &c, evalctx);
+ }
}
}
else if (it_values.type() == Value::VECTOR) {
@@ -227,13 +229,13 @@ AbstractNode *ControlModule::instantiate(const Context* /*ctx*/, const ModuleIns
else if (value.type() == Value::RANGE) {
AbstractNode* node = new AbstractNode(inst);
Value::RangeType range = value.toRange();
- range.normalize();
- if (range.nbsteps()>=10000) {
- PRINTB("WARNING: Bad range parameter for children: too many elements (%d).", (int)((range.begin-range.end)/range.step));
+ unsigned long steps = range.nbsteps();
+ if (steps >= 10000) {
+ PRINTB("WARNING: Bad range parameter for children: too many elements (%lu).", steps);
return NULL;
}
- for (double i = range.begin; i <= range.end; i += range.step) {
- AbstractNode* childnode = getChild(Value(i),modulectx); // with error cases
+ for (Value::RangeType::iterator it = range.begin();it != range.end();it++) {
+ AbstractNode* childnode = getChild(Value(*it),modulectx); // with error cases
if (childnode==NULL) continue; // error
node->children.push_back(childnode);
}
contact: Jan Huwald // Impressum