#include <cmath>
#include <cstdlib>
+#include <iostream>
+
+using namespace std;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGXMLElement.cpp,v 1.31 2010/09/29 02:22:03 jberndt Exp $";
static const char *IdHdr = ID_XMLELEMENT;
bool Element::converterIsInitialized = false;
CLASS IMPLEMENTATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-Element::Element(string nm)
+Element::Element(const string& nm)
{
name = nm;
parent = 0L;
convert["SLUG*FT2"]["KG*M2"] = 1.35594;
convert["KG*M2"]["SLUG*FT2"] = 1.0/convert["SLUG*FT2"]["KG*M2"];
// Angles
- convert["RAD"]["DEG"] = 360.0/(2.0*3.1415926);
+ convert["RAD"]["DEG"] = 180.0/M_PI;
convert["DEG"]["RAD"] = 1.0/convert["RAD"]["DEG"];
+ // Angular rates
+ convert["RAD/SEC"]["DEG/SEC"] = convert["RAD"]["DEG"];
+ convert["DEG/SEC"]["RAD/SEC"] = 1.0/convert["RAD/SEC"]["DEG/SEC"];
// Spring force
convert["LBS/FT"]["N/M"] = 14.5939;
convert["N/M"]["LBS/FT"] = 1.0/convert["LBS/FT"]["N/M"];
convert["KTS"]["FT/SEC"] = 1.68781;
convert["FT/SEC"]["KTS"] = 1.0/convert["KTS"]["FT/SEC"];
convert["M/S"]["FT/S"] = 3.2808399;
+ convert["M/SEC"]["FT/SEC"] = 3.2808399;
convert["FT/S"]["M/S"] = 1.0/convert["M/S"]["FT/S"];
+ convert["M/SEC"]["FT/SEC"] = 3.2808399;
+ convert["FT/SEC"]["M/SEC"] = 1.0/convert["M/SEC"]["FT/SEC"];
// Torque
convert["FT*LBS"]["N*M"] = 1.35581795;
convert["N*M"]["FT*LBS"] = 1/convert["FT*LBS"]["N*M"];
// Fuel Consumption
convert["LBS/HP*HR"]["KG/KW*HR"] = 0.6083;
convert["KG/KW*HR"]["LBS/HP*HR"] = 1.0/convert["LBS/HP*HR"]["KG/KW*HR"];
+ // Density
+ convert["KG/L"]["LBS/GAL"] = 8.3454045;
+ convert["LBS/GAL"]["KG/L"] = 1.0/convert["KG/L"]["LBS/GAL"];
// Length
convert["M"]["M"] = 1.00;
// Angles
convert["DEG"]["DEG"] = 1.00;
convert["RAD"]["RAD"] = 1.00;
+ // Angular rates
+ convert["DEG/SEC"]["DEG/SEC"] = 1.00;
+ convert["RAD/SEC"]["RAD/SEC"] = 1.00;
// Spring force
convert["LBS/FT"]["LBS/FT"] = 1.00;
convert["N/M"]["N/M"] = 1.00;
convert["FT/SEC"]["FT/SEC"] = 1.00;
convert["KTS"]["KTS"] = 1.00;
convert["M/S"]["M/S"] = 1.0;
+ convert["M/SEC"]["M/SEC"] = 1.0;
// Torque
convert["FT*LBS"]["FT*LBS"] = 1.00;
convert["N*M"]["N*M"] = 1.00;
// Fuel Consumption
convert["LBS/HP*HR"]["LBS/HP*HR"] = 1.0;
convert["KG/KW*HR"]["KG/KW*HR"] = 1.0;
+ // Density
+ convert["KG/L"]["KG/L"] = 1.0;
+ convert["LBS/GAL"]["LBS/GAL"] = 1.0;
}
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-string Element::GetAttributeValue(string attr)
+string Element::GetAttributeValue(const string& attr)
{
int select=-1;
for (unsigned int i=0; i<attribute_key.size(); i++) {
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-double Element::GetAttributeValueAsNumber(string attr)
+double Element::GetAttributeValueAsNumber(const string& attr)
{
string attribute = GetAttributeValue(attr);
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-unsigned int Element::GetNumElements(string element_name)
+unsigned int Element::GetNumElements(const string& element_name)
{
unsigned int number_of_elements=0;
Element* el=FindElement(element_name);
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-Element* Element::FindElement(string el)
+Element* Element::FindElement(const string& el)
{
if (el.empty() && children.size() >= 1) {
element_index = 1;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-Element* Element::FindNextElement(string el)
+Element* Element::FindNextElement(const string& el)
{
if (el.empty()) {
if (element_index < children.size()) {
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-double Element::FindElementValueAsNumber(string el)
+double Element::FindElementValueAsNumber(const string& el)
{
Element* element = FindElement(el);
if (element) {
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-string Element::FindElementValue(string el)
+string Element::FindElementValue(const string& el)
{
Element* element = FindElement(el);
if (element) {
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-double Element::FindElementValueAsNumberConvertTo(string el, string target_units)
+double Element::FindElementValueAsNumberConvertTo(const string& el, const string& target_units)
{
Element* element = FindElement(el);
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-double Element::FindElementValueAsNumberConvertFromTo( string el,
- string supplied_units,
- string target_units)
+double Element::FindElementValueAsNumberConvertFromTo( const string& el,
+ const string& supplied_units,
+ const string& target_units)
{
Element* element = FindElement(el);
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-FGColumnVector3 Element::FindElementTripletConvertTo( string target_units)
+FGColumnVector3 Element::FindElementTripletConvertTo( const string& target_units)
{
FGColumnVector3 triplet;
Element* item;
if (!supplied_units.empty()) value *= convert[supplied_units][target_units];
} else {
value = 0.0;
- cerr << "Could not find an X triplet item for this column vector." << endl;
}
triplet(1) = value;
if (!supplied_units.empty()) value *= convert[supplied_units][target_units];
} else {
value = 0.0;
- cerr << "Could not find a Y triplet item for this column vector." << endl;
}
triplet(2) = value;
if (!supplied_units.empty()) value *= convert[supplied_units][target_units];
} else {
value = 0.0;
- cerr << "Could not find a Z triplet item for this column vector." << endl;
}
triplet(3) = value;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-void Element::AddAttribute(string name, string value)
+void Element::AddAttribute(const string& name, const string& value)
{
attribute_key.push_back(name);
attributes[name] = value;
void Element::AddData(string d)
{
- unsigned int string_start = (unsigned int)d.find_first_not_of(" \t");
- if (string_start > 0) {
+ string::size_type string_start = d.find_first_not_of(" \t");
+ if (string_start != string::npos && string_start > 0) {
d.erase(0,string_start);
}
data_lines.push_back(d);