From: Torsten Dreyer Date: Sat, 20 Nov 2010 10:05:45 +0000 (+0100) Subject: A sum without diff is like foo without bar X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=9d4f0f58248dd6107f5aeab8666993c5895cd0db;p=simgear.git A sum without diff is like foo without bar Add a aka to SGExpression to compute differences --- diff --git a/simgear/structure/SGExpression.cxx b/simgear/structure/SGExpression.cxx index a6776636..78d6daf0 100644 --- a/simgear/structure/SGExpression.cxx +++ b/simgear/structure/SGExpression.cxx @@ -293,6 +293,21 @@ SGReadIExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression) } return output; } + + if (name == "difference" || name == "dif" ) { + if (expression->nChildren() < 1) { + SG_LOG(SG_IO, SG_ALERT, "Cannot read \"" << name << "\" expression."); + return 0; + } + SGDifferenceExpression* output = new SGDifferenceExpression; + if (!SGReadNaryOperands(output, inputRoot, expression)) { + delete output; + SG_LOG(SG_IO, SG_ALERT, "Cannot read \"" << name << "\" expression."); + return 0; + } + return output; + } + if (name == "prod" || name == "product") { if (expression->nChildren() < 1) { SG_LOG(SG_IO, SG_ALERT, "Cannot read \"" << name << "\" expression."); diff --git a/simgear/structure/SGExpression.hxx b/simgear/structure/SGExpression.hxx index 05fc8336..444d40cd 100644 --- a/simgear/structure/SGExpression.hxx +++ b/simgear/structure/SGExpression.hxx @@ -794,6 +794,25 @@ public: using SGNaryExpression::getOperand; }; +template +class SGDifferenceExpression : public SGNaryExpression { +public: + SGDifferenceExpression() + { } + SGDifferenceExpression(SGExpression* expr0, SGExpression* expr1) + : SGNaryExpression(expr0, expr1) + { } + virtual void eval(T& value, const simgear::expression::Binding* b) const + { + value = T(0); + unsigned sz = SGNaryExpression::getNumOperands(); + for (unsigned i = 0; i < sz; ++i) + value -= getOperand(i)->getValue(b); + } + using SGNaryExpression::getValue; + using SGNaryExpression::getOperand; +}; + template class SGProductExpression : public SGNaryExpression { public: