]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/models/flight_control/FGSwitch.cpp
Sync. with JSBSim CVS
[flightgear.git] / src / FDM / JSBSim / models / flight_control / FGSwitch.cpp
index 3bd3b661dbe834a09c506c129eaf1a0fccefab47..4e68ea7ffc2a5cefe08df67ca1cc5a6ef8b9e7bf 100644 (file)
@@ -62,10 +62,14 @@ INCLUDES
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
 #include "FGSwitch.h"
+#include <iostream>
+#include <cstdlib>
+
+using namespace std;
 
 namespace JSBSim {
 
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGSwitch.cpp,v 1.19 2009/10/24 22:59:30 jberndt Exp $";
 static const char *IdHdr = ID_SWITCH;
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -97,7 +101,13 @@ FGSwitch::FGSwitch(FGFCS* fcs, Element* element) : FGFCSComponent(fcs, element)
         cerr << "Unrecognized LOGIC token " << logic << " in switch component: " << Name << endl;
       }
       for (unsigned int i=0; i<test_element->GetNumDataLines(); i++) {
-        current_test->conditions.push_back(new FGCondition(test_element->GetDataLine(i), PropertyManager));
+        string input_data = test_element->GetDataLine(i);
+        if (input_data.size() <= 1) {
+          // Make sure there are no bad data lines that consist solely of whitespace
+          cerr << fgred << "  Bad data line in switch component: " << Name << reset << endl;
+          continue;
+        }
+        current_test->conditions.push_back(new FGCondition(input_data, PropertyManager));
       }
 
       condition_element = test_element->GetElement(); // retrieve condition groups
@@ -109,13 +119,13 @@ FGSwitch::FGSwitch(FGFCS* fcs, Element* element) : FGFCSComponent(fcs, element)
       tests.push_back(current_test);
     }
 
-    if (test_element->GetName() != "output") { // this is not an output element
+    if (test_element->GetName() != "output"
+        && test_element->GetName() != "description") { // this is not an output element
       value = test_element->GetAttributeValue("value");
       if (value.empty()) {
         cerr << "No VALUE supplied for switch component: " << Name << endl;
       } else {
-        if (value.find_first_not_of("-.0123456789eE") == string::npos) {
-          // if true (and execution falls into this block), "value" is a number.
+        if (is_number(value)) {
           current_test->OutputVal = atof(value.c_str());
         } else {
           // "value" must be a property if execution passes to here.
@@ -255,7 +265,10 @@ void FGSwitch::Debug(int from)
         }
         cout << endl;
       }
-      if (IsOutput) cout << "      OUTPUT: " << OutputNode->getName() << endl;
+      if (IsOutput) {
+        for (unsigned int i=0; i<OutputNodes.size(); i++)
+          cout << "      OUTPUT: " << OutputNodes[i]->getName() << endl;
+      }
     }
   }
   if (debug_lvl & 2 ) { // Instantiation/Destruction notification