1
0
Fork 0

[JSBSim] <table> independent vars are now late bounded.

The existence of the property that is used for <table> independent vars is now checked during execution rather than when the XML definition is parsed. This relaxes the order in which filters, table and more generally flight controls need to be declared in the XML definition files.
This commit is contained in:
Bertrand Coconnier 2019-08-17 13:58:31 +02:00
parent 47eda6e539
commit 4f5f0f63fd
2 changed files with 43 additions and 60 deletions

View file

@ -8,21 +8,21 @@
------------- Copyright (C) 2001 Jon S. Berndt (jon@jsbsim.org) ------------- ------------- Copyright (C) 2001 Jon S. Berndt (jon@jsbsim.org) -------------
This program is free software; you can redistribute it and/or modify it under This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free Software the terms of the GNU Lesser General Public License as published by the Free
Foundation; either version 2 of the License, or (at your option) any later Software Foundation; either version 2 of the License, or (at your option) any
version. later version.
This program is distributed in the hope that it will be useful, but WITHOUT This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details. details.
You should have received a copy of the GNU Lesser General Public License along with You should have received a copy of the GNU Lesser General Public License along
this program; if not, write to the Free Software Foundation, Inc., 59 Temple with this program; if not, write to the Free Software Foundation, Inc., 59
Place - Suite 330, Boston, MA 02111-1307, USA. Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Further information about the GNU Lesser General Public License can also be found on Further information about the GNU Lesser General Public License can also be
the world wide web at http://www.gnu.org. found on the world wide web at http://www.gnu.org.
FUNCTIONAL DESCRIPTION FUNCTIONAL DESCRIPTION
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -38,10 +38,6 @@ INCLUDES
#include "FGTable.h" #include "FGTable.h"
#include "input_output/FGXMLElement.h" #include "input_output/FGXMLElement.h"
#include "input_output/FGPropertyManager.h"
#include <iostream>
#include <sstream>
#include <cstdlib>
using namespace std; using namespace std;
@ -51,7 +47,8 @@ namespace JSBSim {
CLASS IMPLEMENTATION CLASS IMPLEMENTATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
FGTable::FGTable(int NRows) : nRows(NRows), nCols(1), PropertyManager(0) FGTable::FGTable(int NRows)
: nRows(NRows), nCols(1), PropertyManager(nullptr)
{ {
Type = tt1D; Type = tt1D;
colCounter = 0; colCounter = 0;
@ -65,7 +62,8 @@ FGTable::FGTable(int NRows) : nRows(NRows), nCols(1), PropertyManager(0)
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FGTable::FGTable(int NRows, int NCols) : nRows(NRows), nCols(NCols), PropertyManager(0) FGTable::FGTable(int NRows, int NCols)
: nRows(NRows), nCols(NCols), PropertyManager(nullptr)
{ {
Type = tt2D; Type = tt2D;
colCounter = 1; colCounter = 1;
@ -116,15 +114,8 @@ FGTable::FGTable(FGPropertyManager* propMan, Element* el,
unsigned int i; unsigned int i;
stringstream buf; stringstream buf;
string property_string;
string lookup_axis;
string call_type;
string parent_type;
string brkpt_string; string brkpt_string;
FGPropertyNode* node; Element *tableData = nullptr;
Element *tableData=0;
Element *parent_element=0;
Element *axisElement=0;
string operation_types = "function, product, sum, difference, quotient," string operation_types = "function, product, sum, difference, quotient,"
"pow, abs, sin, cos, asin, acos, tan, atan, table"; "pow, abs, sin, cos, asin, acos, tan, atan, table";
@ -134,10 +125,10 @@ FGTable::FGTable(FGPropertyManager* propMan, Element* el,
internal = false; internal = false;
Name = el->GetAttributeValue("name"); // Allow this table to be named with a property Name = el->GetAttributeValue("name"); // Allow this table to be named with a property
call_type = el->GetAttributeValue("type"); string call_type = el->GetAttributeValue("type");
if (call_type == string("internal")) { if (call_type == string("internal")) {
parent_element = el->GetParent(); Element* parent_element = el->GetParent();
parent_type = parent_element->GetName(); string parent_type = parent_element->GetName();
if (operation_types.find(parent_type) == string::npos) { if (operation_types.find(parent_type) == string::npos) {
internal = true; internal = true;
} else { } else {
@ -155,12 +146,12 @@ FGTable::FGTable(FGPropertyManager* propMan, Element* el,
} }
// Determine and store the lookup properties for this table unless this table // Determine and store the lookup properties for this table unless this table
// is part of a 3D table, in which case its independentVar property indexes will // is part of a 3D table, in which case its independentVar property indexes
// be set by a call from the owning table during creation // will be set by a call from the owning table during creation
dimension = 0; dimension = 0;
axisElement = el->FindElement("independentVar"); Element* axisElement = el->FindElement("independentVar");
if (axisElement) { if (axisElement) {
// The 'internal' attribute of the table element cannot be specified // The 'internal' attribute of the table element cannot be specified
@ -173,24 +164,17 @@ FGTable::FGTable(FGPropertyManager* propMan, Element* el,
internal = false; internal = false;
} }
for (i=0; i<3; i++) lookupProperty[i] = 0;
while (axisElement) { while (axisElement) {
property_string = axisElement->GetDataLine(); string property_string = axisElement->GetDataLine();
if (property_string.find("#") != string::npos) { if (property_string.find("#") != string::npos) {
if (is_number(Prefix)) { if (is_number(Prefix)) {
property_string = replace(property_string,"#",Prefix); property_string = replace(property_string,"#",Prefix);
} }
} }
// The property string passed into GetNode() must have no spaces or tabs.
node = PropertyManager->GetNode(property_string);
if (node == 0) { FGPropertyValue_ptr node = new FGPropertyValue(property_string,
cerr << axisElement->ReadFrom(); PropertyManager);
throw("IndependentVar property, " + property_string + " in Table definition is not defined."); string lookup_axis = axisElement->GetAttributeValue("lookup");
}
lookup_axis = axisElement->GetAttributeValue("lookup");
if (lookup_axis == string("row")) { if (lookup_axis == string("row")) {
lookupProperty[eRow] = node; lookupProperty[eRow] = node;
} else if (lookup_axis == string("column")) { } else if (lookup_axis == string("column")) {
@ -225,7 +209,8 @@ FGTable::FGTable(FGPropertyManager* propMan, Element* el,
} else { } else {
brkpt_string = el->GetAttributeValue("breakPoint"); brkpt_string = el->GetAttributeValue("breakPoint");
if (brkpt_string.empty()) { if (brkpt_string.empty()) {
// no independentVars found, and table is not marked as internal, nor is it a 3D table // no independentVars found, and table is not marked as internal, nor is it
// a 3D table
throw("No independent variable found for table."); throw("No independent variable found for table.");
} }
} }
@ -286,8 +271,8 @@ FGTable::FGTable(FGPropertyManager* propMan, Element* el,
for (i=0; i<nTables; i++) { for (i=0; i<nTables; i++) {
Tables.push_back(new FGTable(PropertyManager, tableData)); Tables.push_back(new FGTable(PropertyManager, tableData));
Data[i+1][1] = tableData->GetAttributeValueAsNumber("breakPoint"); Data[i+1][1] = tableData->GetAttributeValueAsNumber("breakPoint");
Tables[i]->SetRowIndexProperty(lookupProperty[eRow]); Tables[i]->lookupProperty[eRow] = lookupProperty[eRow];
Tables[i]->SetColumnIndexProperty(lookupProperty[eColumn]); Tables[i]->lookupProperty[eColumn] = lookupProperty[eColumn];
tableData = el->FindNextElement("tableData"); tableData = el->FindNextElement("tableData");
} }

View file

@ -7,21 +7,21 @@
------------- Copyright (C) 2001 Jon S. Berndt (jon@jsbsim.org) -------------- ------------- Copyright (C) 2001 Jon S. Berndt (jon@jsbsim.org) --------------
This program is free software; you can redistribute it and/or modify it under This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free Software the terms of the GNU Lesser General Public License as published by the Free
Foundation; either version 2 of the License, or (at your option) any later Software Foundation; either version 2 of the License, or (at your option) any
version. later version.
This program is distributed in the hope that it will be useful, but WITHOUT This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details. details.
You should have received a copy of the GNU Lesser General Public License along with You should have received a copy of the GNU Lesser General Public License along
this program; if not, write to the Free Software Foundation, Inc., 59 Temple with this program; if not, write to the Free Software Foundation, Inc., 59
Place - Suite 330, Boston, MA 02111-1307, USA. Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Further information about the GNU Lesser General Public License can also be found on Further information about the GNU Lesser General Public License can also be
the world wide web at http://www.gnu.org. found on the world wide web at http://www.gnu.org.
HISTORY HISTORY
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -38,11 +38,8 @@ SENTRY
INCLUDES INCLUDES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
#include <iosfwd>
#include <vector>
#include <string>
#include "FGParameter.h" #include "FGParameter.h"
#include "input_output/FGPropertyManager.h" #include "math/FGPropertyValue.h"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS FORWARD DECLARATIONS
@ -278,13 +275,14 @@ public:
FGTable& operator<<(const int n); FGTable& operator<<(const int n);
inline double GetElement(int r, int c) const {return Data[r][c];} inline double GetElement(int r, int c) const {return Data[r][c];}
// inline double GetElement(int r, int c, int t);
double operator()(unsigned int r, unsigned int c) const {return GetElement(r, c);} double operator()(unsigned int r, unsigned int c) const
// double operator()(unsigned int r, unsigned int c, unsigned int t) {GetElement(r, c, t);} { return GetElement(r, c); }
void SetRowIndexProperty(FGPropertyNode *node) {lookupProperty[eRow] = node;} void SetRowIndexProperty(FGPropertyNode *node)
void SetColumnIndexProperty(FGPropertyNode *node) {lookupProperty[eColumn] = node;} { lookupProperty[eRow] = new FGPropertyValue(node); }
void SetColumnIndexProperty(FGPropertyNode *node)
{ lookupProperty[eColumn] = new FGPropertyValue(node); }
unsigned int GetNumRows() const {return nRows;} unsigned int GetNumRows() const {return nRows;}
@ -296,7 +294,7 @@ private:
enum type {tt1D, tt2D, tt3D} Type; enum type {tt1D, tt2D, tt3D} Type;
enum axis {eRow=0, eColumn, eTable}; enum axis {eRow=0, eColumn, eTable};
bool internal; bool internal;
FGPropertyNode_ptr lookupProperty[3]; FGPropertyValue_ptr lookupProperty[3];
double** Data; double** Data;
std::vector <FGTable*> Tables; std::vector <FGTable*> Tables;
unsigned int nRows, nCols, nTables, dimension; unsigned int nRows, nCols, nTables, dimension;