]> git.mxchange.org Git - simgear.git/blobdiff - simgear/structure/SGExpression.cxx
Fix state-machine test linkage with static libs.
[simgear.git] / simgear / structure / SGExpression.cxx
index a6776636a0eba906dc6b070ea4251d1c0e9f012a..df0aa9d747d13b6a0e26d61a9a69f6459b17dd19 100644 (file)
@@ -27,7 +27,6 @@
 #include "Singleton.hxx"
 
 #include <algorithm>
-#include <functional>
 #include <map>
 #include <utility>
 #include <string>
@@ -127,7 +126,7 @@ SGReadValueFromContent(const SGPropertyNode *node, T& value)
 
 template<typename T>
 static SGExpression<T>*
-SGReadIExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression);
+SGReadExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression);
 
 template<typename T>
 static bool
@@ -136,7 +135,7 @@ SGReadNaryOperands(SGNaryExpression<T>* nary,
 {
     for (int i = 0; i < expression->nChildren(); ++i) {
         SGExpression<T>* inputExpression;
-        inputExpression = SGReadIExpression<T>(inputRoot, expression->getChild(i));
+        inputExpression = SGReadExpression<T>(inputRoot, expression->getChild(i));
         if (!inputExpression)
             return false;
         nary->addOperand(inputExpression);
@@ -166,12 +165,13 @@ SGReadNaryOperands(SGNaryExpression<T>* nary,
 
 template<typename T>
 static SGExpression<T>*
-SGReadIExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression)
+SGReadExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression)
 {
     if (!expression)
         return 0;
 
     std::string name = expression->getName();
+
     if (name == "value") {
         T value;
         if (!SGReadValueFromContent(expression, value)) {
@@ -202,7 +202,7 @@ SGReadIExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression)
             return 0;
         }
         SGSharedPtr<SGExpression<T> > inputExpression;
-        inputExpression = SGReadIExpression<T>(inputRoot, expression->getChild(0));
+        inputExpression = SGReadExpression<T>(inputRoot, expression->getChild(0));
         if (!inputExpression) {
             SG_LOG(SG_IO, SG_ALERT, "Cannot read \"" << name << "\" expression.");
             return 0;
@@ -216,7 +216,7 @@ SGReadIExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression)
             return 0;
         }
         SGSharedPtr<SGExpression<T> > inputExpression;
-        inputExpression = SGReadIExpression<T>(inputRoot, expression->getChild(0));
+        inputExpression = SGReadExpression<T>(inputRoot, expression->getChild(0));
         if (!inputExpression) {
             SG_LOG(SG_IO, SG_ALERT, "Cannot read \"" << name << "\" expression.");
             return 0;
@@ -241,7 +241,7 @@ SGReadIExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression)
 
         SGSharedPtr<SGExpression<T> > inputExpression;
         for (int i = 0; !inputExpression && i < expression->nChildren(); ++i)
-            inputExpression = SGReadIExpression<T>(inputRoot, expression->getChild(i));
+            inputExpression = SGReadExpression<T>(inputRoot, expression->getChild(i));
         if (!inputExpression) {
             SG_LOG(SG_IO, SG_ALERT, "Cannot read \"" << name << "\" expression.");
             return 0;
@@ -255,8 +255,8 @@ SGReadIExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression)
             return 0;
         }
         SGSharedPtr<SGExpression<T> > inputExpressions[2] = {
-            SGReadIExpression<T>(inputRoot, expression->getChild(0)),
-            SGReadIExpression<T>(inputRoot, expression->getChild(1))
+            SGReadExpression<T>(inputRoot, expression->getChild(0)),
+            SGReadExpression<T>(inputRoot, expression->getChild(1))
         };
         if (!inputExpressions[0] || !inputExpressions[1]) {
             SG_LOG(SG_IO, SG_ALERT, "Cannot read \"" << name << "\" expression.");
@@ -270,8 +270,8 @@ SGReadIExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression)
             return 0;
         }
         SGSharedPtr<SGExpression<T> > inputExpressions[2] = {
-            SGReadIExpression<T>(inputRoot, expression->getChild(0)),
-            SGReadIExpression<T>(inputRoot, expression->getChild(1))
+            SGReadExpression<T>(inputRoot, expression->getChild(0)),
+            SGReadExpression<T>(inputRoot, expression->getChild(1))
         };
         if (!inputExpressions[0] || !inputExpressions[1]) {
             SG_LOG(SG_IO, SG_ALERT, "Cannot read \"" << name << "\" expression.");
@@ -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.");
@@ -356,7 +371,7 @@ SGReadIExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression)
         }
         
         SGSharedPtr<SGExpression<T> > inputExpression;
-        inputExpression = SGReadIExpression<T>(inputRoot, inputNode);
+        inputExpression = SGReadExpression<T>(inputRoot, inputNode);
         if (!inputExpression) {
             SG_LOG(SG_IO, SG_ALERT, "Cannot read \"" << name << "\" expression.");
             return 0;
@@ -365,29 +380,13 @@ SGReadIExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression)
         return new SGInterpTableExpression<T>(inputExpression, tab);
     }
     
-    return 0;
-}
-
-
-template<typename T>
-static SGExpression<T>*
-SGReadFExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression)
-{
-    SGExpression<T>* r = SGReadIExpression<T>(inputRoot, expression);
-    if (r)
-        return r;
-
-    if (!expression)
-        return 0;
-
-    std::string name = expression->getName();
     if (name == "acos") {
         if (expression->nChildren() != 1) {
             SG_LOG(SG_IO, SG_ALERT, "Cannot read \"" << name << "\" expression.");
             return 0;
         }
         SGSharedPtr<SGExpression<T> > inputExpression;
-        inputExpression = SGReadFExpression<T>(inputRoot, expression->getChild(0));
+        inputExpression = SGReadExpression<T>(inputRoot, expression->getChild(0));
         if (!inputExpression) {
             SG_LOG(SG_IO, SG_ALERT, "Cannot read \"" << name << "\" expression.");
             return 0;
@@ -401,7 +400,7 @@ SGReadFExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression)
             return 0;
         }
         SGSharedPtr<SGExpression<T> > inputExpression;
-        inputExpression = SGReadFExpression<T>(inputRoot, expression->getChild(0));
+        inputExpression = SGReadExpression<T>(inputRoot, expression->getChild(0));
         if (!inputExpression) {
             SG_LOG(SG_IO, SG_ALERT, "Cannot read \"" << name << "\" expression.");
             return 0;
@@ -415,7 +414,7 @@ SGReadFExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression)
             return 0;
         }
         SGSharedPtr<SGExpression<T> > inputExpression;
-        inputExpression = SGReadFExpression<T>(inputRoot, expression->getChild(0));
+        inputExpression = SGReadExpression<T>(inputRoot, expression->getChild(0));
         if (!inputExpression) {
             SG_LOG(SG_IO, SG_ALERT, "Cannot read \"" << name << "\" expression.");
             return 0;
@@ -429,7 +428,7 @@ SGReadFExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression)
             return 0;
         }
         SGSharedPtr<SGExpression<T> > inputExpression;
-        inputExpression = SGReadFExpression<T>(inputRoot, expression->getChild(0));
+        inputExpression = SGReadExpression<T>(inputRoot, expression->getChild(0));
         if (!inputExpression) {
             SG_LOG(SG_IO, SG_ALERT, "Cannot read \"" << name << "\" expression.");
             return 0;
@@ -443,7 +442,7 @@ SGReadFExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression)
             return 0;
         }
         SGSharedPtr<SGExpression<T> > inputExpression;
-        inputExpression = SGReadFExpression<T>(inputRoot, expression->getChild(0));
+        inputExpression = SGReadExpression<T>(inputRoot, expression->getChild(0));
         if (!inputExpression) {
             SG_LOG(SG_IO, SG_ALERT, "Cannot read \"" << name << "\" expression.");
             return 0;
@@ -457,7 +456,7 @@ SGReadFExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression)
             return 0;
         }
         SGSharedPtr<SGExpression<T> > inputExpression;
-        inputExpression = SGReadFExpression<T>(inputRoot, expression->getChild(0));
+        inputExpression = SGReadExpression<T>(inputRoot, expression->getChild(0));
         if (!inputExpression) {
             SG_LOG(SG_IO, SG_ALERT, "Cannot read \"" << name << "\" expression.");
             return 0;
@@ -471,7 +470,7 @@ SGReadFExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression)
             return 0;
         }
         SGSharedPtr<SGExpression<T> > inputExpression;
-        inputExpression = SGReadFExpression<T>(inputRoot, expression->getChild(0));
+        inputExpression = SGReadExpression<T>(inputRoot, expression->getChild(0));
         if (!inputExpression) {
             SG_LOG(SG_IO, SG_ALERT, "Cannot read \"" << name << "\" expression.");
             return 0;
@@ -485,7 +484,7 @@ SGReadFExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression)
             return 0;
         }
         SGSharedPtr<SGExpression<T> > inputExpression;
-        inputExpression = SGReadFExpression<T>(inputRoot, expression->getChild(0));
+        inputExpression = SGReadExpression<T>(inputRoot, expression->getChild(0));
         if (!inputExpression) {
             SG_LOG(SG_IO, SG_ALERT, "Cannot read \"" << name << "\" expression.");
             return 0;
@@ -499,7 +498,7 @@ SGReadFExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression)
             return 0;
         }
         SGSharedPtr<SGExpression<T> > inputExpression;
-        inputExpression = SGReadFExpression<T>(inputRoot, expression->getChild(0));
+        inputExpression = SGReadExpression<T>(inputRoot, expression->getChild(0));
         if (!inputExpression) {
             SG_LOG(SG_IO, SG_ALERT, "Cannot read \"" << name << "\" expression.");
             return 0;
@@ -513,7 +512,7 @@ SGReadFExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression)
             return 0;
         }
         SGSharedPtr<SGExpression<T> > inputExpression;
-        inputExpression = SGReadFExpression<T>(inputRoot, expression->getChild(0));
+        inputExpression = SGReadExpression<T>(inputRoot, expression->getChild(0));
         if (!inputExpression) {
             SG_LOG(SG_IO, SG_ALERT, "Cannot read \"" << name << "\" expression.");
             return 0;
@@ -527,7 +526,7 @@ SGReadFExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression)
             return 0;
         }
         SGSharedPtr<SGExpression<T> > inputExpression;
-        inputExpression = SGReadFExpression<T>(inputRoot, expression->getChild(0));
+        inputExpression = SGReadExpression<T>(inputRoot, expression->getChild(0));
         if (!inputExpression) {
             SG_LOG(SG_IO, SG_ALERT, "Cannot read \"" << name << "\" expression.");
             return 0;
@@ -541,7 +540,7 @@ SGReadFExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression)
             return 0;
         }
         SGSharedPtr<SGExpression<T> > inputExpression;
-        inputExpression = SGReadFExpression<T>(inputRoot, expression->getChild(0));
+        inputExpression = SGReadExpression<T>(inputRoot, expression->getChild(0));
         if (!inputExpression) {
             SG_LOG(SG_IO, SG_ALERT, "Cannot read \"" << name << "\" expression.");
             return 0;
@@ -555,7 +554,7 @@ SGReadFExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression)
             return 0;
         }
         SGSharedPtr<SGExpression<T> > inputExpression;
-        inputExpression = SGReadFExpression<T>(inputRoot, expression->getChild(0));
+        inputExpression = SGReadExpression<T>(inputRoot, expression->getChild(0));
         if (!inputExpression) {
             SG_LOG(SG_IO, SG_ALERT, "Cannot read \"" << name << "\" expression.");
             return 0;
@@ -569,7 +568,7 @@ SGReadFExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression)
             return 0;
         }
         SGSharedPtr<SGExpression<T> > inputExpression;
-        inputExpression = SGReadFExpression<T>(inputRoot, expression->getChild(0));
+        inputExpression = SGReadExpression<T>(inputRoot, expression->getChild(0));
         if (!inputExpression) {
             SG_LOG(SG_IO, SG_ALERT, "Cannot read \"" << name << "\" expression.");
             return 0;
@@ -583,7 +582,7 @@ SGReadFExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression)
             return 0;
         }
         SGSharedPtr<SGExpression<T> > inputExpression;
-        inputExpression = SGReadFExpression<T>(inputRoot, expression->getChild(0));
+        inputExpression = SGReadExpression<T>(inputRoot, expression->getChild(0));
         if (!inputExpression) {
             SG_LOG(SG_IO, SG_ALERT, "Cannot read \"" << name << "\" expression.");
             return 0;
@@ -597,7 +596,7 @@ SGReadFExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression)
             return 0;
         }
         SGSharedPtr<SGExpression<T> > inputExpression;
-        inputExpression = SGReadFExpression<T>(inputRoot, expression->getChild(0));
+        inputExpression = SGReadExpression<T>(inputRoot, expression->getChild(0));
         if (!inputExpression) {
             SG_LOG(SG_IO, SG_ALERT, "Cannot read \"" << name << "\" expression.");
             return 0;
@@ -611,7 +610,7 @@ SGReadFExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression)
             return 0;
         }
         SGSharedPtr<SGExpression<T> > inputExpression;
-        inputExpression = SGReadFExpression<T>(inputRoot, expression->getChild(0));
+        inputExpression = SGReadExpression<T>(inputRoot, expression->getChild(0));
         if (!inputExpression) {
             SG_LOG(SG_IO, SG_ALERT, "Cannot read \"" << name << "\" expression.");
             return 0;
@@ -630,8 +629,8 @@ SGReadFExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression)
             return 0;
         }
         SGSharedPtr<SGExpression<T> > inputExpressions[2] = {
-            SGReadFExpression<T>(inputRoot, expression->getChild(0)),
-            SGReadFExpression<T>(inputRoot, expression->getChild(1))
+            SGReadExpression<T>(inputRoot, expression->getChild(0)),
+            SGReadExpression<T>(inputRoot, expression->getChild(1))
         };
         if (!inputExpressions[0] || !inputExpressions[1]) {
             SG_LOG(SG_IO, SG_ALERT, "Cannot read \"" << name << "\" expression.");
@@ -645,8 +644,8 @@ SGReadFExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression)
             return 0;
         }
         SGSharedPtr<SGExpression<T> > inputExpressions[2] = {
-            SGReadFExpression<T>(inputRoot, expression->getChild(0)),
-            SGReadFExpression<T>(inputRoot, expression->getChild(1))
+            SGReadExpression<T>(inputRoot, expression->getChild(0)),
+            SGReadExpression<T>(inputRoot, expression->getChild(1))
         };
         if (!inputExpressions[0] || !inputExpressions[1]) {
             SG_LOG(SG_IO, SG_ALERT, "Cannot read \"" << name << "\" expression.");
@@ -660,8 +659,8 @@ SGReadFExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression)
             return 0;
         }
         SGSharedPtr<SGExpression<T> > inputExpressions[2] = {
-            SGReadFExpression<T>(inputRoot, expression->getChild(0)),
-            SGReadFExpression<T>(inputRoot, expression->getChild(1))
+            SGReadExpression<T>(inputRoot, expression->getChild(0)),
+            SGReadExpression<T>(inputRoot, expression->getChild(1))
         };
         if (!inputExpressions[0] || !inputExpressions[1]) {
             SG_LOG(SG_IO, SG_ALERT, "Cannot read \"" << name << "\" expression.");
@@ -675,8 +674,8 @@ SGReadFExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression)
             return 0;
         }
         SGSharedPtr<SGExpression<T> > inputExpressions[2] = {
-            SGReadIExpression<T>(inputRoot, expression->getChild(0)),
-            SGReadIExpression<T>(inputRoot, expression->getChild(1))
+            SGReadExpression<T>(inputRoot, expression->getChild(0)),
+            SGReadExpression<T>(inputRoot, expression->getChild(1))
         };
         if (!inputExpressions[0] || !inputExpressions[1]) {
             SG_LOG(SG_IO, SG_ALERT, "Cannot read \"" << name << "\" expression.");
@@ -691,17 +690,17 @@ SGReadFExpression(SGPropertyNode *inputRoot, const SGPropertyNode *expression)
 SGExpression<int>*
 SGReadIntExpression(SGPropertyNode *inputRoot,
                     const SGPropertyNode *configNode)
-{ return SGReadIExpression<int>(inputRoot, configNode); }
+{ return SGReadExpression<int>(inputRoot, configNode); }
 
 SGExpression<float>*
 SGReadFloatExpression(SGPropertyNode *inputRoot,
                       const SGPropertyNode *configNode)
-{ return SGReadFExpression<float>(inputRoot, configNode); }
+{ return SGReadExpression<float>(inputRoot, configNode); }
 
 SGExpression<double>*
 SGReadDoubleExpression(SGPropertyNode *inputRoot,
                        const SGPropertyNode *configNode)
-{ return SGReadFExpression<double>(inputRoot, configNode); }
+{ return SGReadExpression<double>(inputRoot, configNode); }
 
 // SGExpression<bool>*
 // SGReadBoolExpression(SGPropertyNode *inputRoot,