X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fstructure%2FSGExpression.hxx;h=ffb9dd1ded2408b43797160ab597e6820cb0fa9f;hb=c955e61ba785a7b4699ed0a35f947fb661cab854;hp=2dac8efb1863c105bfd78b045af4289180df6c06;hpb=efec9070e178c9aef98332cb03d967868179ae4a;p=simgear.git diff --git a/simgear/structure/SGExpression.hxx b/simgear/structure/SGExpression.hxx index 2dac8efb..ffb9dd1d 100644 --- a/simgear/structure/SGExpression.hxx +++ b/simgear/structure/SGExpression.hxx @@ -31,6 +31,7 @@ #include #include #include +#include /// Expression tree implementation. @@ -121,6 +122,9 @@ public: T getValue(const simgear::expression::Binding* binding = 0) const { T value; eval(value, binding); return value; } + double getDoubleValue(const simgear::expression::Binding* binding = 0) const + { T value; eval(value, binding); return value; } + virtual bool isConst() const { return false; } virtual SGExpression* simplify(); virtual simgear::expression::Type getType() const @@ -318,7 +322,7 @@ public: { } virtual void eval(T& value, const simgear::expression::Binding* b) const - { value = acos(SGMisc::clip(getOperand()->getValue(b), -1, 1)); } + { value = acos((double)SGMisc::clip(getOperand()->getValue(b), -1, 1)); } using SGUnaryExpression::getOperand; }; @@ -331,7 +335,7 @@ public: { } virtual void eval(T& value, const simgear::expression::Binding* b) const - { value = asin(SGMisc::clip(getOperand()->getValue(b), -1, 1)); } + { value = asin((double)SGMisc::clip(getOperand()->getValue(b), -1, 1)); } using SGUnaryExpression::getOperand; }; @@ -344,7 +348,7 @@ public: { } virtual void eval(T& value, const simgear::expression::Binding* b) const - { value = atan(getOperand()->getValue(b)); } + { value = atan(getOperand()->getDoubleValue(b)); } using SGUnaryExpression::getOperand; }; @@ -357,7 +361,7 @@ public: { } virtual void eval(T& value, const simgear::expression::Binding* b) const - { value = ceil(getOperand()->getValue(b)); } + { value = ceil(getOperand()->getDoubleValue(b)); } using SGUnaryExpression::getOperand; }; @@ -370,7 +374,7 @@ public: { } virtual void eval(T& value, const simgear::expression::Binding* b) const - { value = cos(getOperand()->getValue(b)); } + { value = cos(getOperand()->getDoubleValue(b)); } using SGUnaryExpression::getOperand; }; @@ -383,7 +387,7 @@ public: { } virtual void eval(T& value, const simgear::expression::Binding* b) const - { value = cosh(getOperand()->getValue(b)); } + { value = cosh(getOperand()->getDoubleValue(b)); } using SGUnaryExpression::getOperand; }; @@ -396,7 +400,7 @@ public: { } virtual void eval(T& value, const simgear::expression::Binding* b) const - { value = exp(getOperand()->getValue(b)); } + { value = exp(getOperand()->getDoubleValue(b)); } using SGUnaryExpression::getOperand; }; @@ -409,7 +413,7 @@ public: { } virtual void eval(T& value, const simgear::expression::Binding* b) const - { value = floor(getOperand()->getValue(b)); } + { value = floor(getOperand()->getDoubleValue(b)); } using SGUnaryExpression::getOperand; }; @@ -422,7 +426,7 @@ public: { } virtual void eval(T& value, const simgear::expression::Binding* b) const - { value = log(getOperand()->getValue(b)); } + { value = log(getOperand()->getDoubleValue(b)); } using SGUnaryExpression::getOperand; }; @@ -435,7 +439,7 @@ public: { } virtual void eval(T& value, const simgear::expression::Binding* b) const - { value = log10(getOperand()->getValue(b)); } + { value = log10(getOperand()->getDoubleValue(b)); } using SGUnaryExpression::getOperand; }; @@ -448,7 +452,7 @@ public: { } virtual void eval(T& value, const simgear::expression::Binding* b) const - { value = sin(getOperand()->getValue(b)); } + { value = sin(getOperand()->getDoubleValue(b)); } using SGUnaryExpression::getOperand; }; @@ -461,7 +465,7 @@ public: { } virtual void eval(T& value, const simgear::expression::Binding* b) const - { value = sinh(getOperand()->getValue(b)); } + { value = sinh(getOperand()->getDoubleValue(b)); } using SGUnaryExpression::getOperand; }; @@ -487,7 +491,7 @@ public: { } virtual void eval(T& value, const simgear::expression::Binding* b) const - { value = sqrt(getOperand()->getValue(b)); } + { value = sqrt(getOperand()->getDoubleValue(b)); } using SGUnaryExpression::getOperand; }; @@ -500,7 +504,7 @@ public: { } virtual void eval(T& value, const simgear::expression::Binding* b) const - { value = tan(getOperand()->getValue(b)); } + { value = tan(getOperand()->getDoubleValue(b)); } using SGUnaryExpression::getOperand; }; @@ -513,7 +517,7 @@ public: { } virtual void eval(T& value, const simgear::expression::Binding* b) const - { value = tanh(getOperand()->getValue(b)); } + { value = tanh(getOperand()->getDoubleValue(b)); } using SGUnaryExpression::getOperand; }; @@ -730,7 +734,7 @@ public: : SGBinaryExpression(expr0, expr1) { } virtual void eval(T& value, const simgear::expression::Binding* b) const - { value = atan2(getOperand(0)->getValue(b), getOperand(1)->getValue(b)); } + { value = atan2(getOperand(0)->getDoubleValue(b), getOperand(1)->getDoubleValue(b)); } using SGBinaryExpression::getOperand; }; @@ -770,7 +774,7 @@ public: : SGBinaryExpression(expr0, expr1) { } virtual void eval(T& value, const simgear::expression::Binding* b) const - { value = pow(getOperand(0)->getValue(b), getOperand(1)->getValue(b)); } + { value = pow(getOperand(0)->getDoubleValue(b), getOperand(1)->getDoubleValue(b)); } using SGBinaryExpression::getOperand; }; @@ -793,6 +797,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 = getOperand(0)->getValue(b); + unsigned sz = SGNaryExpression::getNumOperands(); + for (unsigned i = 1; i < sz; ++i) + value -= getOperand(i)->getValue(b); + } + using SGNaryExpression::getValue; + using SGNaryExpression::getOperand; +}; + template class SGProductExpression : public SGNaryExpression { public: @@ -1009,10 +1032,16 @@ namespace simgear class ExpressionParser : public Parser { public: - ParserMap& getParserMap() { return _parserTable; } + ParserMap& getParserMap() + { + return ParserMapSingleton::instance()->_parserTable; + } static void addExpParser(const std::string&, exp_parser); protected: - static ParserMap _parserTable; + struct ParserMapSingleton : public simgear::Singleton + { + ParserMap _parserTable; + }; }; /** @@ -1195,7 +1224,7 @@ namespace simgear void eval(bool& value, const expression::Binding* b) const { value = false; - for (int i = 0; i < getNumOperands(); ++i) { + for (int i = 0; i < (int)getNumOperands(); ++i) { value = value || getOperand(i)->getValue(b); if (value) return; @@ -1209,7 +1238,7 @@ namespace simgear void eval(bool& value, const expression::Binding* b) const { value = true; - for (int i = 0; i < getNumOperands(); ++i) { + for (int i = 0; i < (int)getNumOperands(); ++i) { value = value && getOperand(i)->getValue(b); if (!value) return;