Skip to content

Commit

Permalink
Fixed the bug [#96] Table Independent Variables Not Indexed
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoconni committed Mar 11, 2017
1 parent b62a976 commit 2c9c853
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 19 deletions.
18 changes: 10 additions & 8 deletions src/math/FGFunction.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ using namespace std;

namespace JSBSim {

IDENT(IdSrc,"$Id: FGFunction.cpp,v 1.58 2015/07/12 19:34:08 bcoconni Exp $");
IDENT(IdSrc,"$Id: FGFunction.cpp,v 1.59 2017/03/11 19:31:47 bcoconni Exp $");
IDENT(IdHdr,ID_FUNCTION);

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down Expand Up @@ -266,7 +266,7 @@ FGFunction::FGFunction(FGPropertyManager* propMan, Element* el, const string& pr
} else if (operation == value_string || operation == v_string) {
Parameters.push_back(new FGRealValue(element->GetDataAsNumber()));
} else if (operation == table_string || operation == t_string) {
Parameters.push_back(new FGTable(PropertyManager, element));
Parameters.push_back(new FGTable(PropertyManager, element, Prefix));
// operations
} else if (operation == product_string ||
operation == difference_string ||
Expand Down Expand Up @@ -323,7 +323,7 @@ FGFunction::FGFunction(FGPropertyManager* propMan, Element* el, const string& pr
element = el->GetNextElement();
}

bind(); // Allow any function to save its value
bind(el); // Allow any function to save its value

Debug(0);
}
Expand Down Expand Up @@ -784,7 +784,7 @@ string FGFunction::GetValueAsString(void) const

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void FGFunction::bind(void)
void FGFunction::bind(Element* el)
{
if ( !Name.empty() ) {
string tmp;
Expand All @@ -796,9 +796,10 @@ void FGFunction::bind(void)
Name = replace(Name,"#",Prefix);
tmp = PropertyManager->mkPropertyName(Name, false);
} else {
cerr << "Malformed function name with number: " << Prefix
<< " and property name: " << Name
<< " but no \"#\" sign for substitution." << endl;
cerr << el->ReadFrom()
<< "Malformed function name with number: " << Prefix
<< " and property name: " << Name
<< " but no \"#\" sign for substitution." << endl;
}
} else {
tmp = PropertyManager->mkPropertyName(Prefix + "/" + Name, false);
Expand All @@ -808,7 +809,8 @@ void FGFunction::bind(void)
if (PropertyManager->HasNode(tmp)) {
FGPropertyNode* _property = PropertyManager->GetNode(tmp);
if (_property->isTied()) {
cout << "Property " << tmp << " has already been successfully bound (late)." << endl;
cerr << el->ReadFrom()
<< "Property " << tmp << " has already been successfully bound (late)." << endl;
throw("Failed to bind the property to an existing already tied node.");
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/math/FGFunction.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ INCLUDES
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

#define ID_FUNCTION "$Id: FGFunction.h,v 1.32 2015/07/12 13:03:23 bcoconni Exp $"
#define ID_FUNCTION "$Id: FGFunction.h,v 1.33 2017/03/11 19:31:47 bcoconni Exp $"

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
Expand Down Expand Up @@ -812,7 +812,7 @@ class FGFunction : public FGParameter
FGPropertyNode_ptr pCopyTo; // Property node for CopyTo property string

unsigned int GetBinary(double) const;
void bind(void);
void bind(Element*);
void Debug(int from);
};

Expand Down
43 changes: 38 additions & 5 deletions src/math/FGTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ using namespace std;

namespace JSBSim {

IDENT(IdSrc,"$Id: FGTable.cpp,v 1.32 2016/05/22 09:08:05 bcoconni Exp $");
IDENT(IdSrc,"$Id: FGTable.cpp,v 1.33 2017/03/11 19:31:48 bcoconni Exp $");
IDENT(IdHdr,ID_TABLE);

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down Expand Up @@ -112,7 +112,9 @@ FGTable::FGTable(const FGTable& t) : PropertyManager(t.PropertyManager)

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FGTable::FGTable(FGPropertyManager* propMan, Element* el) : PropertyManager(propMan)
FGTable::FGTable(FGPropertyManager* propMan, Element* el,
const std::string& prefix)
: PropertyManager(propMan), Prefix(prefix)
{
unsigned int i;

Expand Down Expand Up @@ -174,6 +176,11 @@ FGTable::FGTable(FGPropertyManager* propMan, Element* el) : PropertyManager(prop

while (axisElement) {
property_string = axisElement->GetDataLine();
if (property_string.find("#") != string::npos) {
if (is_number(Prefix)) {
property_string = replace(property_string,"#",Prefix);
}
}
// The property string passed into GetNode() must have no spaces or tabs.
node = PropertyManager->GetNode(property_string);

Expand Down Expand Up @@ -347,7 +354,7 @@ FGTable::FGTable(FGPropertyManager* propMan, Element* el) : PropertyManager(prop
}
}

bind();
bind(el);

if (debug_lvl & 1) Print();
}
Expand Down Expand Up @@ -632,11 +639,37 @@ void FGTable::Print(void)

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void FGTable::bind(void)
void FGTable::bind(Element* el)
{
typedef double (FGTable::*PMF)(void) const;
if ( !Name.empty() && !internal) {
string tmp = PropertyManager->mkPropertyName(Name, false); // Allow upper
string tmp;
if (Prefix.empty())
tmp = PropertyManager->mkPropertyName(Name, false); // Allow upper
else {
if (is_number(Prefix)) {
if (Name.find("#") != string::npos) { // if "#" is found
Name = replace(Name,"#",Prefix);
tmp = PropertyManager->mkPropertyName(Name, false); // Allow upper
} else {
cerr << el->ReadFrom()
<< "Malformed table name with number: " << Prefix
<< " and property name: " << Name
<< " but no \"#\" sign for substitution." << endl;
}
} else {
tmp = PropertyManager->mkPropertyName(Prefix + "/" + Name, false);
}
}

if (PropertyManager->HasNode(tmp)) {
FGPropertyNode* _property = PropertyManager->GetNode(tmp);
if (_property->isTied()) {
cerr << el->ReadFrom()
<< "Property " << tmp << " has already been successfully bound (late)." << endl;
throw("Failed to bind the property to an existing already tied node.");
}
}
PropertyManager->Tie( tmp, this, (PMF)&FGTable::GetValue);
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/math/FGTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ INCLUDES
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

#define ID_TABLE "$Id$"
#define ID_TABLE "$Id: FGTable.h,v 1.16 2017/03/11 19:31:48 bcoconni Exp $"

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
Expand Down Expand Up @@ -233,7 +233,7 @@ combustion_efficiency = Lookup_Combustion_Efficiency->GetValue(equivalence_ratio
@endcode
@author Jon S. Berndt
@version $Id$
@version $Id: FGTable.h,v 1.16 2017/03/11 19:31:48 bcoconni Exp $
*/

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand All @@ -251,7 +251,7 @@ class FGTable : public FGParameter
FGTable(const FGTable& table);

/// The constructor for a table
FGTable (FGPropertyManager* propMan, Element* el);
FGTable (FGPropertyManager* propMan, Element* el, const std::string& prefix="");
FGTable (int );
FGTable (int, int);
double GetValue(void) const;
Expand Down Expand Up @@ -311,8 +311,9 @@ class FGTable : public FGParameter
mutable int lastRowIndex, lastColumnIndex, lastTableIndex;
double** Allocate(void);
FGPropertyManager* const PropertyManager;
std::string Prefix;
std::string Name;
void bind(void);
void bind(Element*);

unsigned int FindNumColumns(const std::string&);
void Debug(int from);
Expand Down

0 comments on commit 2c9c853

Please sign in to comment.