A sum without diff is like foo without bar
Add a <difference> aka <diff> to SGExpression to compute differences
This commit is contained in:
parent
b4f5eaa541
commit
9d4f0f5824
@ -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<T>* output = new SGDifferenceExpression<T>;
|
||||
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.");
|
||||
|
@ -794,6 +794,25 @@ public:
|
||||
using SGNaryExpression<T>::getOperand;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class SGDifferenceExpression : public SGNaryExpression<T> {
|
||||
public:
|
||||
SGDifferenceExpression()
|
||||
{ }
|
||||
SGDifferenceExpression(SGExpression<T>* expr0, SGExpression<T>* expr1)
|
||||
: SGNaryExpression<T>(expr0, expr1)
|
||||
{ }
|
||||
virtual void eval(T& value, const simgear::expression::Binding* b) const
|
||||
{
|
||||
value = T(0);
|
||||
unsigned sz = SGNaryExpression<T>::getNumOperands();
|
||||
for (unsigned i = 0; i < sz; ++i)
|
||||
value -= getOperand(i)->getValue(b);
|
||||
}
|
||||
using SGNaryExpression<T>::getValue;
|
||||
using SGNaryExpression<T>::getOperand;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class SGProductExpression : public SGNaryExpression<T> {
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user