JSBSim Flight Dynamics Model 1.0 (23 February 2013)
An Open Source Flight Dynamics and Control Software Library in C++

Element Class Reference

Encapsulates an XML element. More...

#include <FGXMLElement.h>

Collaboration diagram for Element:

List of all members.

Public Member Functions

 Element (const std::string &nm)
 Constructor.
 ~Element (void)
 Destructor.
void AddAttribute (const std::string &name, const std::string &value)
 Stores an attribute belonging to this element.
void AddChildElement (Element *el)
 Adds a child element to the list of children stored for this element.
void AddData (std::string d)
 Stores data belonging to this element.
double DisperseValue (Element *e, double val, const std::string supplied_units="", const std::string target_units="")
ElementFindElement (const std::string &el="")
 Searches for a specified element.
FGColumnVector3 FindElementTripletConvertTo (const std::string &target_units)
 Composes a 3-element column vector for the supplied location or orientation.
std::string FindElementValue (const std::string &el="")
 Searches for the named element and returns the string data belonging to it.
double FindElementValueAsNumber (const std::string &el="")
 Searches for the named element and returns the data belonging to it as a number.
double FindElementValueAsNumberConvertFromTo (const std::string &el, const std::string &supplied_units, const std::string &target_units)
 Searches for the named element and converts and returns the data belonging to it.
double FindElementValueAsNumberConvertTo (const std::string &el, const std::string &target_units)
 Searches for the named element and converts and returns the data belonging to it.
ElementFindNextElement (const std::string &el="")
 Searches for the next element as specified.
std::string GetAttributeValue (const std::string &key)
 Retrieves an attribute.
double GetAttributeValueAsNumber (const std::string &key)
 Retrieves an attribute value as a double precision real number.
double GetDataAsNumber (void)
 Converts the element data to a number.
std::string GetDataLine (unsigned int i=0)
 Gets a line of data belonging to an element.
ElementGetElement (unsigned int el=0)
 Returns a pointer to the element requested by index.
const std::string & GetName (void) const
 Retrieves the element name.
ElementGetNextElement (void)
 Returns a pointer to the next element in the list.
unsigned int GetNumDataLines (void)
 Returns the number of lines of data stored.
unsigned int GetNumElements (void)
 Returns the number of child elements for this element.
unsigned int GetNumElements (const std::string &element_name)
 Returns the number of named child elements for this element.
ElementGetParent (void)
 Returns a pointer to the parent of an element.
bool HasAttribute (const std::string &key)
 Determines if an element has the supplied attribute.
void Print (unsigned int level=0)
 Prints the element.
void SetParent (Element *p)
 This function sets the value of the parent class attribute to the supplied Element pointer.

Detailed Description

This class handles the creation, storage, and manipulation of XML elements. This class also can convert supplied values as follows:

convert ["from"]["to"] = factor, so: from * factor = to

  • convert["M"]["FT"] = 3.2808399;
  • convert["FT"]["M"] = 1.0/convert["M"]["FT"];
  • convert["M2"]["FT2"] = convert["M"]["FT"]*convert["M"]["FT"];
  • convert["FT2"]["M2"] = 1.0/convert["M2"]["FT2"];
  • convert["FT"]["IN"] = 12.0;
  • convert["IN"]["FT"] = 1.0/convert["FT"]["IN"];
  • convert["LBS"]["KG"] = 0.45359237;
  • convert["KG"]["LBS"] = 1.0/convert["LBS"]["KG"];
  • convert["SLUG*FT2"]["KG*M2"] = 1.35594;
  • convert["KG*M2"]["SLUG*FT2"] = 1.0/convert["SLUG*FT2"]["KG*M2"];
  • convert["RAD"]["DEG"] = 360.0/(2.0*3.1415926);
  • convert["DEG"]["RAD"] = 1.0/convert["RAD"]["DEG"];
  • convert["LBS/FT"]["N/M"] = 14.5939;
  • convert["LBS/FT/SEC"]["N/M/SEC"] = 14.5939;
  • convert["N/M"]["LBS/FT"] = 1.0/convert["LBS/FT"]["N/M"];
  • convert["N/M/SEC"]["LBS/FT/SEC"] = 1.0/convert["LBS/FT/SEC"]["N/M/SEC"];
  • convert["WATTS"]["HP"] = 0.001341022;
  • convert["HP"]["WATTS"] = 1.0/convert["WATTS"]["HP"];
  • convert["N"]["LBS"] = 0.22482;
  • convert["LBS"]["N"] = 1.0/convert["N"]["LBS"];
  • convert["KTS"]["FT/SEC"] = ktstofps;
  • convert["KG/MIN"]["LBS/MIN"] = convert["KG"]["LBS"];
  • convert["LBS/HP*HR"]["KG/KW*HR"] = 0.6083;
  • convert["KG/KW*HR"]["LBS/HP*HR"] = 1/convert["LBS/HP*HR"]["KG/KW*HR"];
  • convert["KG/L"]["LBS/GAL"] = 8.3454045;
  • convert["M"]["M"] = 1.00;
  • convert["FT"]["FT"] = 1.00;
  • convert["IN"]["IN"] = 1.00;
  • convert["DEG"]["DEG"] = 1.00;
  • convert["RAD"]["RAD"] = 1.00;
  • convert["M2"]["M2"] = 1.00;
  • convert["FT2"]["FT2"] = 1.00;
  • convert["KG*M2"]["KG*M2"] = 1.00;
  • convert["SLUG*FT2"]["SLUG*FT2"] = 1.00;
  • convert["KG"]["KG"] = 1.00;
  • convert["LBS"]["LBS"] = 1.00;
  • convert["LBS/FT"]["LBS/FT"] = 1.00;
  • convert["N/M"]["N/M"] = 1.00;
  • convert["LBS/FT/SEC"]["LBS/FT/SEC"] = 1.00;
  • convert["N/M/SEC"]["N/M/SEC"] = 1.00;
  • convert["PSI"]["PSI"] = 1.00;
  • convert["INHG"]["INHG"] = 1.00;
  • convert["HP"]["HP"] = 1.00;
  • convert["N"]["N"] = 1.00;
  • convert["WATTS"]["WATTS"] = 1.00;
  • convert["KTS"]["KTS"] = 1.0;
  • convert["FT/SEC"]["FT/SEC"] = 1.0;
  • convert["KG/MIN"]["KG/MIN"] = 1.0;
  • convert["LBS/MIN"]["LBS/MIN"] = 1.0;
  • convert["LBS/HP*HR"]["LBS/HP*HR"] = 1.0;
  • convert["KG/KW*HR"]["KG/KW*HR"] = 1.0;
  • convert["KG/L"]["KG/L"] = 1.0;
  • convert["LBS/GAL"]["LBS/GAL"] = 1.0;

Where:

  • N = newtons
  • M = meters
  • M2 = meters squared
  • KG = kilograms
  • LBS = pounds force
  • FT = feet
  • FT2 = feet squared
  • SEC = seconds
  • MIN = minutes
  • SLUG = slug
  • DEG = degrees
  • RAD = radians
  • WATTS = watts
  • HP = horsepower
  • HR = hour
  • L = liter
  • GAL = gallon (U.S. liquid)
Author:
Jon S. Berndt
Version:
Id:
FGXMLElement.h,v 1.17 2012/07/26 04:33:46 jberndt Exp

Definition at line 146 of file FGXMLElement.h.


Constructor & Destructor Documentation

Element ( const std::string &  nm)
Parameters:
nmthe name of this element (if given)

Definition at line 56 of file FGXMLElement.cpp.

{
  name   = nm;
  parent = 0L;
  element_index = 0;

  if (!converterIsInitialized) {
    converterIsInitialized = true;
    // convert ["from"]["to"] = factor, so: from * factor = to
    // Length
    convert["M"]["FT"] = 3.2808399;
    convert["FT"]["M"] = 1.0/convert["M"]["FT"];
    convert["CM"]["FT"] = 0.032808399;
    convert["FT"]["CM"] = 1.0/convert["CM"]["FT"];
    convert["KM"]["FT"] = 3280.8399;
    convert["FT"]["KM"] = 1.0/convert["KM"]["FT"];
    convert["FT"]["IN"] = 12.0;
    convert["IN"]["FT"] = 1.0/convert["FT"]["IN"];
    convert["IN"]["M"] = convert["IN"]["FT"] * convert["FT"]["M"];
    convert["M"]["IN"] = convert["M"]["FT"] * convert["FT"]["IN"];
    // Area
    convert["M2"]["FT2"] = convert["M"]["FT"]*convert["M"]["FT"];
    convert["FT2"]["M2"] = 1.0/convert["M2"]["FT2"];
    convert["CM2"]["FT2"] = convert["CM"]["FT"]*convert["CM"]["FT"];
    convert["FT2"]["CM2"] = 1.0/convert["CM2"]["FT2"];
    convert["M2"]["IN2"] = convert["M"]["IN"]*convert["M"]["IN"];
    convert["IN2"]["M2"] = 1.0/convert["M2"]["IN2"];
    convert["FT2"]["IN2"] = 144.0;
    convert["IN2"]["FT2"] = 1.0/convert["FT2"]["IN2"];
    // Volume
    convert["IN3"]["CC"] = 16.387064;
    convert["CC"]["IN3"] = 1.0/convert["IN3"]["CC"];
    convert["FT3"]["IN3"] = 1728.0;
    convert["IN3"]["FT3"] = 1.0/convert["FT3"]["IN3"];
    convert["M3"]["FT3"] = 35.3146667;
    convert["FT3"]["M3"] = 1.0/convert["M3"]["FT3"];
    convert["LTR"]["IN3"] = 61.0237441;
    convert["IN3"]["LTR"] = 1.0/convert["LTR"]["IN3"];
    // Mass & Weight
    convert["LBS"]["KG"] = 0.45359237;
    convert["KG"]["LBS"] = 1.0/convert["LBS"]["KG"];
    convert["SLUG"]["KG"] = 14.59390;
    convert["KG"]["SLUG"] = 1.0/convert["SLUG"]["KG"];
    // Moments of Inertia
    convert["SLUG*FT2"]["KG*M2"] = 1.35594;
    convert["KG*M2"]["SLUG*FT2"] = 1.0/convert["SLUG*FT2"]["KG*M2"];
    // Angles
    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"];
    // Damping force
    convert["LBS/FT/SEC"]["N/M/SEC"] = 14.5939;
    convert["N/M/SEC"]["LBS/FT/SEC"] = 1.0/convert["LBS/FT/SEC"]["N/M/SEC"];
    // Damping force (Square Law)
    convert["LBS/FT2/SEC2"]["N/M2/SEC2"] = 47.880259;
    convert["N/M2/SEC2"]["LBS/FT2/SEC2"] = 1.0/convert["LBS/FT2/SEC2"]["N/M2/SEC2"];
    // Power
    convert["WATTS"]["HP"] = 0.001341022;
    convert["HP"]["WATTS"] = 1.0/convert["WATTS"]["HP"];
    // Force
    convert["N"]["LBS"] = 0.22482;
    convert["LBS"]["N"] = 1.0/convert["N"]["LBS"];
    // Velocity
    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"];
    convert["KM/SEC"]["FT/SEC"] = 3280.8399;
    convert["FT/SEC"]["KM/SEC"] = 1.0/convert["KM/SEC"]["FT/SEC"];
    // Torque
    convert["FT*LBS"]["N*M"] = 1.35581795;
    convert["N*M"]["FT*LBS"] = 1/convert["FT*LBS"]["N*M"];
    // Valve
    convert["M4*SEC/KG"]["FT4*SEC/SLUG"] = convert["M"]["FT"]*convert["M"]["FT"]*
      convert["M"]["FT"]*convert["M"]["FT"]/convert["KG"]["SLUG"];
    convert["FT4*SEC/SLUG"]["M4*SEC/KG"] =
      1.0/convert["M4*SEC/KG"]["FT4*SEC/SLUG"];
    // Pressure
    convert["INHG"]["PSF"] = 70.7180803;
    convert["PSF"]["INHG"] = 1.0/convert["INHG"]["PSF"];
    convert["ATM"]["INHG"] = 29.9246899;
    convert["INHG"]["ATM"] = 1.0/convert["ATM"]["INHG"];
    convert["PSI"]["INHG"] = 2.03625437;
    convert["INHG"]["PSI"] = 1.0/convert["PSI"]["INHG"];
    convert["INHG"]["PA"] = 3386.0; // inches Mercury to pascals
    convert["PA"]["INHG"] = 1.0/convert["INHG"]["PA"];
    convert["LBS/FT2"]["N/M2"] = 14.5939/convert["FT"]["M"];
    convert["N/M2"]["LBS/FT2"] = 1.0/convert["LBS/FT2"]["N/M2"];
    convert["LBS/FT2"]["PA"] = convert["LBS/FT2"]["N/M2"];
    convert["PA"]["LBS/FT2"] = 1.0/convert["LBS/FT2"]["PA"];
    // Mass flow
    convert["KG/MIN"]["LBS/MIN"] = convert["KG"]["LBS"];
    // 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;
    convert["KM"]["KM"] = 1.00;
    convert["FT"]["FT"] = 1.00;
    convert["IN"]["IN"] = 1.00;
    // Area
    convert["M2"]["M2"] = 1.00;
    convert["FT2"]["FT2"] = 1.00;
    // Volume
    convert["IN3"]["IN3"] = 1.00;
    convert["CC"]["CC"] = 1.0;
    convert["M3"]["M3"] = 1.0;
    convert["FT3"]["FT3"] = 1.0;
    convert["LTR"]["LTR"] = 1.0;
    // Mass & Weight
    convert["KG"]["KG"] = 1.00;
    convert["LBS"]["LBS"] = 1.00;
    // Moments of Inertia
    convert["KG*M2"]["KG*M2"] = 1.00;
    convert["SLUG*FT2"]["SLUG*FT2"] = 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;
    // Damping force
    convert["LBS/FT/SEC"]["LBS/FT/SEC"] = 1.00;
    convert["N/M/SEC"]["N/M/SEC"] = 1.00;
    // Damping force (Square law)
    convert["LBS/FT2/SEC2"]["LBS/FT2/SEC2"] = 1.00;
    convert["N/M2/SEC2"]["N/M2/SEC2"] = 1.00;
    // Power
    convert["HP"]["HP"] = 1.00;
    convert["WATTS"]["WATTS"] = 1.00;
    // Force
    convert["N"]["N"] = 1.00;
    // Velocity
    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;
    convert["KM/SEC"]["KM/SEC"] = 1.0;
    // Torque
    convert["FT*LBS"]["FT*LBS"] = 1.00;
    convert["N*M"]["N*M"] = 1.00;
    // Valve
    convert["M4*SEC/KG"]["M4*SEC/KG"] = 1.0;
    convert["FT4*SEC/SLUG"]["FT4*SEC/SLUG"] = 1.0;
    // Pressure
    convert["PSI"]["PSI"] = 1.00;
    convert["PSF"]["PSF"] = 1.00;
    convert["INHG"]["INHG"] = 1.00;
    convert["ATM"]["ATM"] = 1.0;
    convert["PA"]["PA"] = 1.0;
    convert["N/M2"]["N/M2"] = 1.00;
    convert["LBS/FT2"]["LBS/FT2"] = 1.00;
    // Mass flow
    convert["LBS/SEC"]["LBS/SEC"] = 1.00;
    convert["KG/MIN"]["KG/MIN"] = 1.0;
    convert["LBS/MIN"]["LBS/MIN"] = 1.0;
    // 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;
  }
  attribute_key.resize(0);
}

Member Function Documentation

void AddAttribute ( const std::string &  name,
const std::string &  value 
)
Parameters:
nameThe string name of the attribute.
valueThe string value of the attribute.

Definition at line 628 of file FGXMLElement.cpp.

{
  attribute_key.push_back(name);
  attributes[name] = value;
}
void AddChildElement ( Element el) [inline]
Parameters:
elChild element to add.

Definition at line 318 of file FGXMLElement.h.

{children.push_back(el);}
void AddData ( std::string  d)
Parameters:
dthe data to store.

Definition at line 636 of file FGXMLElement.cpp.

{
  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);
}
Element * FindElement ( const std::string &  el = "")

Finds the first element that matches the supplied string, or simply the first element if no search string is supplied. This function call resets the internal element counter to the first element.

Parameters:
elthe search string (empty string by default).
Returns:
a pointer to the first element that matches the supplied search string.

Definition at line 359 of file FGXMLElement.cpp.

Referenced by FGActuator::FGActuator(), FGElectric::FGElectric(), FGExternalForce::FGExternalForce(), FGFCSComponent::FGFCSComponent(), FGGasCell::FGGasCell(), FGKinemat::FGKinemat(), FGLGear::FGLGear(), FGNozzle::FGNozzle(), FGPiston::FGPiston(), FGPropeller::FGPropeller(), FGRocket::FGRocket(), FGRotor::FGRotor(), FGSummer::FGSummer(), FGSwitch::FGSwitch(), FGTable::FGTable(), FGTank::FGTank(), FGThruster::FGThruster(), FGTrimAnalysis::Load(), FGPropulsion::Load(), FGOutputType::Load(), FGMassBalance::Load(), FGInitialCondition::Load(), FGGroundReactions::Load(), FGFCS::Load(), FGExternalReactions::Load(), FGBuoyantForces::Load(), FGAircraft::Load(), FGAerodynamics::Load(), FGFDMExec::LoadModel(), and FGScript::LoadScript().

{
  if (el.empty() && children.size() >= 1) {
    element_index = 1;
    return children[0];
  }
  for (unsigned int i=0; i<children.size(); i++) {
    if (el == children[i]->GetName()) {
      element_index = i+1;
      return children[i];
    }
  }
  element_index = 0;
  return 0L;
}

Here is the caller graph for this function:

FGColumnVector3 FindElementTripletConvertTo ( const std::string &  target_units)

This function processes a LOCATION or ORIENTATION construct, returning a filled-out 3-element column vector containing the X, Y, Z or ROLL, PITCH, YAW elements found in the supplied element. If one of the mentioned components is not found, that component is set to zero and a warning message is printed. All three elements should be supplied.

Parameters:
target_unitsthe string representing the native units used by JSBSim to which the value returned will be converted.
Returns:
a column vector object built from the LOCATION or ORIENT components.

Definition at line 498 of file FGXMLElement.cpp.

References Element::GetDataAsNumber().

Referenced by FGExternalForce::FGExternalForce(), FGGasCell::FGGasCell(), FGLGear::FGLGear(), FGRotor::FGRotor(), FGTank::FGTank(), FGThruster::FGThruster(), FGMassBalance::Load(), and FGAircraft::Load().

{
  FGColumnVector3 triplet;
  Element* item;
  double value=0.0;
  string supplied_units = GetAttributeValue("unit");

  if (!supplied_units.empty()) {
    if (convert.find(supplied_units) == convert.end()) {
      cerr << endl << "Supplied unit: \"" << supplied_units << "\" does not exist (typo?). Add new unit"
           << " conversion in FGXMLElement.cpp." << endl;
      exit(-1);
    }
    if (convert[supplied_units].find(target_units) == convert[supplied_units].end()) {
      cerr << endl << "Supplied unit: \"" << supplied_units << "\" cannot be converted to "
                   << target_units << ". Add new unit conversion in FGXMLElement.cpp or fix typo" << endl;
      exit(-1);
    }
  }

  item = FindElement("x");
  if (!item) item = FindElement("roll");
  if (item) {
    value = item->GetDataAsNumber();
    if (!supplied_units.empty()) value *= convert[supplied_units][target_units];
    triplet(1) = DisperseValue(item, value, supplied_units, target_units);
  } else {
    triplet(1) = 0.0;
  }
  

  item = FindElement("y");
  if (!item) item = FindElement("pitch");
  if (item) {
    value = item->GetDataAsNumber();
    if (!supplied_units.empty()) value *= convert[supplied_units][target_units];
    triplet(2) = DisperseValue(item, value, supplied_units, target_units);
  } else {
    triplet(2) = 0.0;
  }

  item = FindElement("z");
  if (!item) item = FindElement("yaw");
  if (item) {
    value = item->GetDataAsNumber();
    if (!supplied_units.empty()) value *= convert[supplied_units][target_units];
    triplet(3) = DisperseValue(item, value, supplied_units, target_units);
  } else {
    triplet(3) = 0.0;
  }

  return triplet;
}

Here is the call graph for this function:

Here is the caller graph for this function:

string FindElementValue ( const std::string &  el = "")

This function allows the data belonging to a named element to be returned as a string. If no element is found, the empty string is returned. If no argument is supplied, the data string for the first element is returned.

Parameters:
elthe name of the element being searched for (the empty string by default)
Returns:
the data value for the named element as a string, or the empty string if the element cannot be found.

Definition at line 414 of file FGXMLElement.cpp.

References Element::GetDataLine().

Referenced by FGFCSComponent::FGFCSComponent(), FGLGear::FGLGear(), FGRotor::FGRotor(), FGTank::FGTank(), FGOutputType::Load(), and FGScript::LoadScript().

{
  Element* element = FindElement(el);
  if (element) {
    return element->GetDataLine();
  } else {
    return "";
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

double FindElementValueAsNumber ( const std::string &  el = "")

This function allows the data belonging to a named element to be returned as a double. If no element is found, HUGE_VAL is returned. If no argument is supplied, the data for the first element is returned.

Parameters:
elthe name of the element being searched for (the empty string by default)
Returns:
the data value for the named element as a double, or HUGE_VAL if the data is missing.

Definition at line 399 of file FGXMLElement.cpp.

References Element::GetDataAsNumber().

Referenced by FGActuator::FGActuator(), FGFCSComponent::FGFCSComponent(), FGGasCell::FGGasCell(), FGKinemat::FGKinemat(), FGLGear::FGLGear(), FGPiston::FGPiston(), FGPropeller::FGPropeller(), FGRocket::FGRocket(), FGRotor::FGRotor(), FGSummer::FGSummer(), and FGTank::FGTank().

{
  Element* element = FindElement(el);
  if (element) {
    double value = element->GetDataAsNumber();
    value = DisperseValue(element, value);
    return value;
  } else {
    cerr << "Attempting to get single data value from multiple lines" << endl;
    return 0;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

double FindElementValueAsNumberConvertFromTo ( const std::string &  el,
const std::string &  supplied_units,
const std::string &  target_units 
)

This function allows the data belonging to a named element to be returned as a double. If no element is found, HUGE_VAL is returned. If no argument is supplied, the data for the first element is returned. Additionally, this function converts the value from the units specified in the supplied_units parameter to the units specified in the target_units parameter. JSBSim itself, as specified by the target_units parameter. The currently allowable unit conversions are seen in the source file FGXMLElement.cpp. Also, see above in the main documentation for this class.

Parameters:
elthe name of the element being searched for (the empty string by default)
supplied_unitsthe string representing the units of the value as supplied by the config file.
target_unitsthe string representing the native units used by JSBSim to which the value returned will be converted.
Returns:
the unit-converted data value for the named element as a double, or HUGE_VAL if the data is missing.

Definition at line 462 of file FGXMLElement.cpp.

References Element::GetDataAsNumber().

Referenced by FGAerodynamics::Load().

{
  Element* element = FindElement(el);

  if (!element) {
    cerr << "Attempting to get non-existent element " << el << endl;
    exit(0);
  }

  if (!supplied_units.empty()) {
    if (convert.find(supplied_units) == convert.end()) {
      cerr << endl << "Supplied unit: \"" << supplied_units << "\" does not exist (typo?). Add new unit"
           << " conversion in FGXMLElement.cpp." << endl;
      exit(-1);
    }
    if (convert[supplied_units].find(target_units) == convert[supplied_units].end()) {
      cerr << endl << "Supplied unit: \"" << supplied_units << "\" cannot be converted to "
                   << target_units << ". Add new unit conversion in FGXMLElement.cpp or fix typo" << endl;
      exit(-1);
    }
  }

  double value = element->GetDataAsNumber();
  if (!supplied_units.empty()) {
    value *= convert[supplied_units][target_units];
  }

  value = DisperseValue(element, value, supplied_units, target_units);

  return value;
}

Here is the call graph for this function:

Here is the caller graph for this function:

double FindElementValueAsNumberConvertTo ( const std::string &  el,
const std::string &  target_units 
)

This function allows the data belonging to a named element to be returned as a double. If no element is found, HUGE_VAL is returned. If no argument is supplied, the data for the first element is returned. Additionally, this function converts the value from the units specified in the config file (via the UNITS="" attribute in the element definition) to the native units used by JSBSim itself, as specified by the target_units parameter. The currently allowable unit conversions are seen in the source file FGXMLElement.cpp. Also, see above in the main documentation for this class.

Parameters:
elthe name of the element being searched for (the empty string by default)
target_unitsthe string representing the native units used by JSBSim to which the value returned will be converted.
Returns:
the unit-converted data value for the named element as a double, or HUGE_VAL if the data is missing.

Definition at line 426 of file FGXMLElement.cpp.

References Element::GetAttributeValue(), and Element::GetDataAsNumber().

Referenced by FGElectric::FGElectric(), FGGasCell::FGGasCell(), FGLGear::FGLGear(), FGNozzle::FGNozzle(), FGPiston::FGPiston(), FGPropeller::FGPropeller(), FGRocket::FGRocket(), FGTank::FGTank(), FGPropulsion::Load(), FGMassBalance::Load(), and FGAircraft::Load().

{
  Element* element = FindElement(el);

  if (!element) {
    cerr << "Attempting to get non-existent element " << el << endl;
    exit(0);
  }

  string supplied_units = element->GetAttributeValue("unit");

  if (!supplied_units.empty()) {
    if (convert.find(supplied_units) == convert.end()) {
      cerr << endl << "Supplied unit: \"" << supplied_units << "\" does not exist (typo?). Add new unit"
           << " conversion in FGXMLElement.cpp." << endl;
      exit(-1);
    }
    if (convert[supplied_units].find(target_units) == convert[supplied_units].end()) {
      cerr << endl << "Supplied unit: \"" << supplied_units << "\" cannot be converted to "
                   << target_units << ". Add new unit conversion in FGXMLElement.cpp or fix typo" << endl;
      exit(-1);
    }
  }

  double value = element->GetDataAsNumber();
  if (!supplied_units.empty()) {
    value *= convert[supplied_units][target_units];
  }

  value = DisperseValue(element, value, supplied_units, target_units);

  return value;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Element * FindNextElement ( const std::string &  el = "")

This function would be called after FindElement() is first called (in order to reset the internal counter). If no argument is supplied (or the empty string) a pointer to the very next element is returned. Otherwise, the next occurence of the named element is returned. If the end of the list is reached, 0 is returned.

Parameters:
elthe name of the next element to find.
Returns:
the pointer to the found element, or 0 if no appropriate element us found.

Definition at line 377 of file FGXMLElement.cpp.

Referenced by FGActuator::FGActuator(), FGFCSComponent::FGFCSComponent(), FGGasCell::FGGasCell(), FGKinemat::FGKinemat(), FGLGear::FGLGear(), FGPiston::FGPiston(), FGPropeller::FGPropeller(), FGSwitch::FGSwitch(), FGTable::FGTable(), FGPropulsion::Load(), FGOutputType::Load(), FGMassBalance::Load(), FGInitialCondition::Load(), FGGroundReactions::Load(), FGFCS::Load(), FGExternalReactions::Load(), FGBuoyantForces::Load(), FGAircraft::Load(), FGAerodynamics::Load(), FGFDMExec::LoadModel(), and FGScript::LoadScript().

{
  if (el.empty()) {
    if (element_index < children.size()) {
      return children[element_index++];
    } else {
      element_index = 0;
      return 0L;
    }
  }
  for (unsigned int i=element_index; i<children.size(); i++) {
    if (el == children[i]->GetName()) {
      element_index = i+1;
      return children[i];
    }
  }
  element_index = 0;
  return 0L;
}

Here is the caller graph for this function:

double GetAttributeValueAsNumber ( const std::string &  key)
Parameters:
keyspecifies the attribute key to retrieve the value of.
Returns:
the key value (as a number), or the HUGE_VAL if no such attribute exists.

Definition at line 273 of file FGXMLElement.cpp.

Referenced by FGTable::FGTable(), FGOutputType::Load(), FGInput::Load(), FGInitialCondition::Load(), FGFCS::Load(), and FGScript::LoadScript().

{
  string attribute = GetAttributeValue(attr);

  if (attribute.empty()) return HUGE_VAL;
  else {
    double number=0;
    if (is_number(trim(attribute)))
      number = atof(attribute.c_str());
    else
      throw("Expecting numeric attribute value, but got: " + attribute);
    
    return (number);
  }
}

Here is the caller graph for this function:

double GetDataAsNumber ( void  )

This function attempts to convert the first (and presumably only) line of data "owned" by the element into a real number. If there is not exactly one line of data owned by the element, then HUGE_VAL is returned.

Returns:
the numeric value of the data owned by the element.

Definition at line 326 of file FGXMLElement.cpp.

Referenced by FGFCSComponent::FGFCSComponent(), FGFunction::FGFunction(), FGPropeller::FGPropeller(), FGRotor::FGRotor(), Element::FindElementTripletConvertTo(), Element::FindElementValueAsNumber(), Element::FindElementValueAsNumberConvertFromTo(), Element::FindElementValueAsNumberConvertTo(), and FGInitialCondition::Load().

{
  if (data_lines.size() == 1) {
    double number=0;
    if (is_number(trim(data_lines[0])))
      number = atof(data_lines[0].c_str());
    else
      throw("Expected numeric value, but got: " + data_lines[0]);

    return number;
  } else if (data_lines.size() == 0) {
    return HUGE_VAL;
  } else {
    cerr << "Attempting to get single data value from multiple lines in element " << name << endl;
    return HUGE_VAL;
  }
}

Here is the caller graph for this function:

string GetDataLine ( unsigned int  i = 0)
Parameters:
ithe index of the data line to return (0 by default).
Returns:
a string representing the data line requested, or the empty string if none exists.

Definition at line 318 of file FGXMLElement.cpp.

Referenced by FGActuator::FGActuator(), FGFCSComponent::FGFCSComponent(), FGFunction::FGFunction(), FGTable::FGTable(), Element::FindElementValue(), FGOutputType::Load(), FGFCS::Load(), and FGScript::LoadScript().

{
  if (data_lines.size() > 0) return data_lines[i];
  else return string("");
}

Here is the caller graph for this function:

Element * GetElement ( unsigned int  el = 0)

This function also resets an internal counter to the index, so that subsequent calls to GetNextElement() will return the following elements sequentially, until the last element is reached. At that point, GetNextElement() will return NULL.

Parameters:
elthe index of the requested element (0 by default)
Returns:
a pointer to the Element, or 0 if no valid element exists.

Definition at line 291 of file FGXMLElement.cpp.

Referenced by FGFunction::FGFunction(), and FGFCS::Load().

{
  if (children.size() > el) {
    element_index = el;
    return children[el];
  }
  else {
    element_index = 0;
    return 0L;
  }
}

Here is the caller graph for this function:

const std::string& GetName ( void  ) const [inline]
Returns:
the element name, or the empty string if no name has been set.

Definition at line 174 of file FGXMLElement.h.

Referenced by FGFCSComponent::FGFCSComponent(), FGFunction::FGFunction(), FGTable::FGTable(), FGThruster::FGThruster(), FGPropulsion::Load(), FGInitialCondition::Load(), FGFCS::Load(), and FGScript::LoadScript().

{return name;}

Here is the caller graph for this function:

Element * GetNextElement ( void  )

The function GetElement() must be called first to be sure that this function will return the correct element. The call to GetElement() resets the internal counter to zero. Subsequent calls to GetNextElement() return a pointer to subsequent elements in the list. When the final element is reached, 0 is returned.

Returns:
a pointer to the next Element in the sequence, or 0 if no valid Element is present.

Definition at line 305 of file FGXMLElement.cpp.

Referenced by FGFunction::FGFunction(), and FGFCS::Load().

{
  if (children.size() > element_index+1) {
    element_index++;
    return children[element_index];
  } else {
    element_index = 0;
    return 0L;
  }
}

Here is the caller graph for this function:

Element* GetParent ( void  ) [inline]
Returns:
a pointer to the parent Element, or 0 if this is the top level Element.

Definition at line 219 of file FGXMLElement.h.

Referenced by FGPropeller::FGPropeller(), FGRotor::FGRotor(), FGTable::FGTable(), and FGThruster::FGThruster().

{return parent;}

Here is the caller graph for this function:

bool HasAttribute ( const std::string &  key)
Parameters:
keyspecifies the attribute key to retrieve the value of.
Returns:
true or false.

Definition at line 257 of file FGXMLElement.cpp.

Referenced by FGActuator::FGActuator(), and FGOutputType::Load().

{
  bool status=true;
  int select=-1;

  unsigned int attr_cnt = attribute_key.size();

  for (unsigned int i=0; i<attr_cnt; i++) {
    if (attribute_key[i] == attr) select = i;
  }
  if (select < 0) status=false;
  return status;
}

Here is the caller graph for this function:

void Print ( unsigned int  level = 0)

Prints this element and calls the Print routine for child elements.

Parameters:
dThe tab level. A level corresponds to a single space.

Definition at line 606 of file FGXMLElement.cpp.

{
  unsigned int i, spaces;

  level+=2;
  for (spaces=0; spaces<=level; spaces++) cout << " "; // format output
  cout << "Element Name: " << name;
  for (i=0; i<attributes.size(); i++) {
    cout << "  " << attribute_key[i] << " = " << attributes[attribute_key[i]];
  }
  cout << endl;
  for (i=0; i<data_lines.size(); i++) {
    for (spaces=0; spaces<=level; spaces++) cout << " "; // format output
    cout << data_lines[i] << endl;
  }
  for (i=0; i<children.size(); i++) {
    children[i]->Print(level);
  }
}
void SetParent ( Element p) [inline]
Parameters:
ppointer to the parent Element.

Definition at line 314 of file FGXMLElement.h.

Referenced by FGPropulsion::Load().

{parent = p;}

Here is the caller graph for this function:


The documentation for this class was generated from the following files: