JSBSim Flight Dynamics Model  1.0 (02 March 2017)
An Open Source Flight Dynamics and Control Software Library in C++
Element Class Reference
+ Inheritance diagram for Element:
+ Collaboration diagram for Element:

Public Member Functions

 Element (const std::string &nm)
 Constructor. More...
 
 ~Element (void)
 Destructor.
 
void AddAttribute (const std::string &name, const std::string &value)
 Stores an attribute belonging to this element. More...
 
void AddChildElement (Element *el)
 Adds a child element to the list of children stored for this element. More...
 
void AddData (std::string d)
 Stores data belonging to this element. More...
 
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. More...
 
FGColumnVector3 FindElementTripletConvertTo (const std::string &target_units)
 Composes a 3-element column vector for the supplied location or orientation. More...
 
std::string FindElementValue (const std::string &el="")
 Searches for the named element and returns the string data belonging to it. More...
 
double FindElementValueAsNumber (const std::string &el="")
 Searches for the named element and returns the data belonging to it as a number. More...
 
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. More...
 
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. More...
 
ElementFindNextElement (const std::string &el="")
 Searches for the next element as specified. More...
 
std::string GetAttributeValue (const std::string &key)
 Retrieves an attribute. More...
 
double GetAttributeValueAsNumber (const std::string &key)
 Retrieves an attribute value as a double precision real number. More...
 
double GetDataAsNumber (void)
 Converts the element data to a number. More...
 
std::string GetDataLine (unsigned int i=0)
 Gets a line of data belonging to an element. More...
 
ElementGetElement (unsigned int el=0)
 Returns a pointer to the element requested by index. More...
 
const std::string & GetFileName (void) const
 Returns the name of the file in which the element has been read. More...
 
int GetLineNumber (void) const
 Returns the line number at which the element has been defined. More...
 
const std::string & GetName (void) const
 Retrieves the element name. More...
 
ElementGetNextElement (void)
 Returns a pointer to the next element in the list. More...
 
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. More...
 
bool HasAttribute (const std::string &key)
 Determines if an element has the supplied attribute. More...
 
void MergeAttributes (Element *el)
 Merges the attributes of the current element with another element. More...
 
void Print (unsigned int level=0)
 Prints the element. More...
 
std::string ReadFrom (void) const
 Return a string that contains a description of the location where the current XML element was read from. More...
 
bool SetAttributeValue (const std::string &key, const std::string &value)
 Modifies an attribute. More...
 
void SetFileName (const std::string &name)
 Set the name of the file in which the element has been read. More...
 
void SetLineNumber (int line)
 Set the line number at which the element has been read. More...
 
void SetParent (Element *p)
 This function sets the value of the parent class attribute to the supplied Element pointer. More...
 

Detailed Description

Definition at line 150 of file FGXMLElement.h.

Constructor & Destructor Documentation

◆ Element()

Element ( const std::string &  nm)

Constructor.

Parameters
nmthe name of this element (if given)

Definition at line 58 of file FGXMLElement.cpp.

59 {
60  name = nm;
61  parent = 0L;
62  element_index = 0;
63  line_number = -1;
64 
65  if (!converterIsInitialized) {
66  converterIsInitialized = true;
67  // convert ["from"]["to"] = factor, so: from * factor = to
68  // Length
69  convert["M"]["FT"] = 3.2808399;
70  convert["FT"]["M"] = 1.0/convert["M"]["FT"];
71  convert["CM"]["FT"] = 0.032808399;
72  convert["FT"]["CM"] = 1.0/convert["CM"]["FT"];
73  convert["KM"]["FT"] = 3280.8399;
74  convert["FT"]["KM"] = 1.0/convert["KM"]["FT"];
75  convert["FT"]["IN"] = 12.0;
76  convert["IN"]["FT"] = 1.0/convert["FT"]["IN"];
77  convert["IN"]["M"] = convert["IN"]["FT"] * convert["FT"]["M"];
78  convert["M"]["IN"] = convert["M"]["FT"] * convert["FT"]["IN"];
79  // Area
80  convert["M2"]["FT2"] = convert["M"]["FT"]*convert["M"]["FT"];
81  convert["FT2"]["M2"] = 1.0/convert["M2"]["FT2"];
82  convert["CM2"]["FT2"] = convert["CM"]["FT"]*convert["CM"]["FT"];
83  convert["FT2"]["CM2"] = 1.0/convert["CM2"]["FT2"];
84  convert["M2"]["IN2"] = convert["M"]["IN"]*convert["M"]["IN"];
85  convert["IN2"]["M2"] = 1.0/convert["M2"]["IN2"];
86  convert["FT2"]["IN2"] = 144.0;
87  convert["IN2"]["FT2"] = 1.0/convert["FT2"]["IN2"];
88  // Volume
89  convert["IN3"]["CC"] = 16.387064;
90  convert["CC"]["IN3"] = 1.0/convert["IN3"]["CC"];
91  convert["FT3"]["IN3"] = 1728.0;
92  convert["IN3"]["FT3"] = 1.0/convert["FT3"]["IN3"];
93  convert["M3"]["FT3"] = 35.3146667;
94  convert["FT3"]["M3"] = 1.0/convert["M3"]["FT3"];
95  convert["LTR"]["IN3"] = 61.0237441;
96  convert["IN3"]["LTR"] = 1.0/convert["LTR"]["IN3"];
97  // Mass & Weight
98  convert["LBS"]["KG"] = 0.45359237;
99  convert["KG"]["LBS"] = 1.0/convert["LBS"]["KG"];
100  convert["SLUG"]["KG"] = 14.59390;
101  convert["KG"]["SLUG"] = 1.0/convert["SLUG"]["KG"];
102  // Moments of Inertia
103  convert["SLUG*FT2"]["KG*M2"] = 1.35594;
104  convert["KG*M2"]["SLUG*FT2"] = 1.0/convert["SLUG*FT2"]["KG*M2"];
105  // Angles
106  convert["RAD"]["DEG"] = 180.0/M_PI;
107  convert["DEG"]["RAD"] = 1.0/convert["RAD"]["DEG"];
108  // Angular rates
109  convert["RAD/SEC"]["DEG/SEC"] = convert["RAD"]["DEG"];
110  convert["DEG/SEC"]["RAD/SEC"] = 1.0/convert["RAD/SEC"]["DEG/SEC"];
111  // Spring force
112  convert["LBS/FT"]["N/M"] = 14.5939;
113  convert["N/M"]["LBS/FT"] = 1.0/convert["LBS/FT"]["N/M"];
114  // Damping force
115  convert["LBS/FT/SEC"]["N/M/SEC"] = 14.5939;
116  convert["N/M/SEC"]["LBS/FT/SEC"] = 1.0/convert["LBS/FT/SEC"]["N/M/SEC"];
117  // Damping force (Square Law)
118  convert["LBS/FT2/SEC2"]["N/M2/SEC2"] = 47.880259;
119  convert["N/M2/SEC2"]["LBS/FT2/SEC2"] = 1.0/convert["LBS/FT2/SEC2"]["N/M2/SEC2"];
120  // Power
121  convert["WATTS"]["HP"] = 0.001341022;
122  convert["HP"]["WATTS"] = 1.0/convert["WATTS"]["HP"];
123  // Force
124  convert["N"]["LBS"] = 0.22482;
125  convert["LBS"]["N"] = 1.0/convert["N"]["LBS"];
126  // Velocity
127  convert["KTS"]["FT/SEC"] = 1.68781;
128  convert["FT/SEC"]["KTS"] = 1.0/convert["KTS"]["FT/SEC"];
129  convert["M/S"]["FT/S"] = 3.2808399;
130  convert["M/SEC"]["FT/SEC"] = 3.2808399;
131  convert["FT/S"]["M/S"] = 1.0/convert["M/S"]["FT/S"];
132  convert["M/SEC"]["FT/SEC"] = 3.2808399;
133  convert["FT/SEC"]["M/SEC"] = 1.0/convert["M/SEC"]["FT/SEC"];
134  convert["KM/SEC"]["FT/SEC"] = 3280.8399;
135  convert["FT/SEC"]["KM/SEC"] = 1.0/convert["KM/SEC"]["FT/SEC"];
136  // Torque
137  convert["FT*LBS"]["N*M"] = 1.35581795;
138  convert["N*M"]["FT*LBS"] = 1/convert["FT*LBS"]["N*M"];
139  // Valve
140  convert["M4*SEC/KG"]["FT4*SEC/SLUG"] = convert["M"]["FT"]*convert["M"]["FT"]*
141  convert["M"]["FT"]*convert["M"]["FT"]/convert["KG"]["SLUG"];
142  convert["FT4*SEC/SLUG"]["M4*SEC/KG"] =
143  1.0/convert["M4*SEC/KG"]["FT4*SEC/SLUG"];
144  // Pressure
145  convert["INHG"]["PSF"] = 70.7180803;
146  convert["PSF"]["INHG"] = 1.0/convert["INHG"]["PSF"];
147  convert["ATM"]["INHG"] = 29.9246899;
148  convert["INHG"]["ATM"] = 1.0/convert["ATM"]["INHG"];
149  convert["PSI"]["INHG"] = 2.03625437;
150  convert["INHG"]["PSI"] = 1.0/convert["PSI"]["INHG"];
151  convert["INHG"]["PA"] = 3386.0; // inches Mercury to pascals
152  convert["PA"]["INHG"] = 1.0/convert["INHG"]["PA"];
153  convert["LBS/FT2"]["N/M2"] = 14.5939/convert["FT"]["M"];
154  convert["N/M2"]["LBS/FT2"] = 1.0/convert["LBS/FT2"]["N/M2"];
155  convert["LBS/FT2"]["PA"] = convert["LBS/FT2"]["N/M2"];
156  convert["PA"]["LBS/FT2"] = 1.0/convert["LBS/FT2"]["PA"];
157  // Mass flow
158  convert["KG/MIN"]["LBS/MIN"] = convert["KG"]["LBS"];
159  convert ["N/SEC"]["LBS/SEC"] = 0.224808943;
160  convert ["LBS/SEC"]["N/SEC"] = 1.0/convert ["N/SEC"]["LBS/SEC"];
161  // Fuel Consumption
162  convert["LBS/HP*HR"]["KG/KW*HR"] = 0.6083;
163  convert["KG/KW*HR"]["LBS/HP*HR"] = 1.0/convert["LBS/HP*HR"]["KG/KW*HR"];
164  // Density
165  convert["KG/L"]["LBS/GAL"] = 8.3454045;
166  convert["LBS/GAL"]["KG/L"] = 1.0/convert["KG/L"]["LBS/GAL"];
167 
168  // Length
169  convert["M"]["M"] = 1.00;
170  convert["KM"]["KM"] = 1.00;
171  convert["FT"]["FT"] = 1.00;
172  convert["IN"]["IN"] = 1.00;
173  // Area
174  convert["M2"]["M2"] = 1.00;
175  convert["FT2"]["FT2"] = 1.00;
176  // Volume
177  convert["IN3"]["IN3"] = 1.00;
178  convert["CC"]["CC"] = 1.0;
179  convert["M3"]["M3"] = 1.0;
180  convert["FT3"]["FT3"] = 1.0;
181  convert["LTR"]["LTR"] = 1.0;
182  // Mass & Weight
183  convert["KG"]["KG"] = 1.00;
184  convert["LBS"]["LBS"] = 1.00;
185  // Moments of Inertia
186  convert["KG*M2"]["KG*M2"] = 1.00;
187  convert["SLUG*FT2"]["SLUG*FT2"] = 1.00;
188  // Angles
189  convert["DEG"]["DEG"] = 1.00;
190  convert["RAD"]["RAD"] = 1.00;
191  // Angular rates
192  convert["DEG/SEC"]["DEG/SEC"] = 1.00;
193  convert["RAD/SEC"]["RAD/SEC"] = 1.00;
194  // Spring force
195  convert["LBS/FT"]["LBS/FT"] = 1.00;
196  convert["N/M"]["N/M"] = 1.00;
197  // Damping force
198  convert["LBS/FT/SEC"]["LBS/FT/SEC"] = 1.00;
199  convert["N/M/SEC"]["N/M/SEC"] = 1.00;
200  // Damping force (Square law)
201  convert["LBS/FT2/SEC2"]["LBS/FT2/SEC2"] = 1.00;
202  convert["N/M2/SEC2"]["N/M2/SEC2"] = 1.00;
203  // Power
204  convert["HP"]["HP"] = 1.00;
205  convert["WATTS"]["WATTS"] = 1.00;
206  // Force
207  convert["N"]["N"] = 1.00;
208  // Velocity
209  convert["FT/SEC"]["FT/SEC"] = 1.00;
210  convert["KTS"]["KTS"] = 1.00;
211  convert["M/S"]["M/S"] = 1.0;
212  convert["M/SEC"]["M/SEC"] = 1.0;
213  convert["KM/SEC"]["KM/SEC"] = 1.0;
214  // Torque
215  convert["FT*LBS"]["FT*LBS"] = 1.00;
216  convert["N*M"]["N*M"] = 1.00;
217  // Valve
218  convert["M4*SEC/KG"]["M4*SEC/KG"] = 1.0;
219  convert["FT4*SEC/SLUG"]["FT4*SEC/SLUG"] = 1.0;
220  // Pressure
221  convert["PSI"]["PSI"] = 1.00;
222  convert["PSF"]["PSF"] = 1.00;
223  convert["INHG"]["INHG"] = 1.00;
224  convert["ATM"]["ATM"] = 1.0;
225  convert["PA"]["PA"] = 1.0;
226  convert["N/M2"]["N/M2"] = 1.00;
227  convert["LBS/FT2"]["LBS/FT2"] = 1.00;
228  // Mass flow
229  convert["LBS/SEC"]["LBS/SEC"] = 1.00;
230  convert["KG/MIN"]["KG/MIN"] = 1.0;
231  convert["LBS/MIN"]["LBS/MIN"] = 1.0;
232  convert["N/SEC"]["N/SEC"] = 1.0;
233  // Fuel Consumption
234  convert["LBS/HP*HR"]["LBS/HP*HR"] = 1.0;
235  convert["KG/KW*HR"]["KG/KW*HR"] = 1.0;
236  // Density
237  convert["KG/L"]["KG/L"] = 1.0;
238  convert["LBS/GAL"]["LBS/GAL"] = 1.0;
239  }
240 }

Member Function Documentation

◆ AddAttribute()

void AddAttribute ( const std::string &  name,
const std::string &  value 
)

Stores an attribute belonging to this element.

Parameters
nameThe string name of the attribute.
valueThe string value of the attribute.

Definition at line 666 of file FGXMLElement.cpp.

667 {
668  attributes[name] = value;
669 }
+ Here is the caller graph for this function:

◆ AddChildElement()

void AddChildElement ( Element el)
inline

Adds a child element to the list of children stored for this element.

Parameters
elChild element to add.

Definition at line 341 of file FGXMLElement.h.

341 {children.push_back(el);}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AddData()

void AddData ( std::string  d)

Stores data belonging to this element.

Parameters
dthe data to store.

Definition at line 673 of file FGXMLElement.cpp.

674 {
675  string::size_type string_start = d.find_first_not_of(" \t");
676  if (string_start != string::npos && string_start > 0) {
677  d.erase(0,string_start);
678  }
679  data_lines.push_back(d);
680 }
+ Here is the caller graph for this function:

◆ FindElement()

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

Searches for a specified element.

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 372 of file FGXMLElement.cpp.

373 {
374  if (el.empty() && children.size() >= 1) {
375  element_index = 1;
376  return children[0];
377  }
378  for (unsigned int i=0; i<children.size(); i++) {
379  if (el == children[i]->GetName()) {
380  element_index = i+1;
381  return children[i];
382  }
383  }
384  element_index = 0;
385  return 0L;
386 }
const std::string & GetName(void) const
Retrieves the element name.
Definition: FGXMLElement.h:186
+ Here is the caller graph for this function:

◆ FindElementTripletConvertTo()

FGColumnVector3 FindElementTripletConvertTo ( const std::string &  target_units)

Composes a 3-element column vector for the supplied location or orientation.

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 540 of file FGXMLElement.cpp.

541 {
542  FGColumnVector3 triplet;
543  Element* item;
544  double value=0.0;
545  string supplied_units = GetAttributeValue("unit");
546 
547  if (!supplied_units.empty()) {
548  if (convert.find(supplied_units) == convert.end()) {
549  cerr << ReadFrom() << "Supplied unit: \""
550  << supplied_units << "\" does not exist (typo?)." << endl;
551  exit(-1);
552  }
553  if (convert[supplied_units].find(target_units) == convert[supplied_units].end()) {
554  cerr << ReadFrom() << "Supplied unit: \""
555  << supplied_units << "\" cannot be converted to " << target_units
556  << endl;
557  exit(-1);
558  }
559  }
560 
561  item = FindElement("x");
562  if (!item) item = FindElement("roll");
563  if (item) {
564  value = item->GetDataAsNumber();
565  if (!supplied_units.empty()) value *= convert[supplied_units][target_units];
566  triplet(1) = DisperseValue(item, value, supplied_units, target_units);
567  } else {
568  triplet(1) = 0.0;
569  }
570 
571 
572  item = FindElement("y");
573  if (!item) item = FindElement("pitch");
574  if (item) {
575  value = item->GetDataAsNumber();
576  if (!supplied_units.empty()) value *= convert[supplied_units][target_units];
577  triplet(2) = DisperseValue(item, value, supplied_units, target_units);
578  } else {
579  triplet(2) = 0.0;
580  }
581 
582  item = FindElement("z");
583  if (!item) item = FindElement("yaw");
584  if (item) {
585  value = item->GetDataAsNumber();
586  if (!supplied_units.empty()) value *= convert[supplied_units][target_units];
587  triplet(3) = DisperseValue(item, value, supplied_units, target_units);
588  } else {
589  triplet(3) = 0.0;
590  }
591 
592  return triplet;
593 }
std::string GetAttributeValue(const std::string &key)
Retrieves an attribute.
Element * FindElement(const std::string &el="")
Searches for a specified element.
std::string ReadFrom(void) const
Return a string that contains a description of the location where the current XML element was read fr...
Element(const std::string &nm)
Constructor.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ FindElementValue()

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

Searches for the named element and returns the string data belonging to it.

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 428 of file FGXMLElement.cpp.

429 {
430  Element* element = FindElement(el);
431  if (element) {
432  return element->GetDataLine();
433  } else {
434  return "";
435  }
436 }
Element * FindElement(const std::string &el="")
Searches for a specified element.
Element(const std::string &nm)
Constructor.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ FindElementValueAsNumber()

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

Searches for the named element and returns the data belonging to it as a number.

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 412 of file FGXMLElement.cpp.

413 {
414  Element* element = FindElement(el);
415  if (element) {
416  double value = element->GetDataAsNumber();
417  value = DisperseValue(element, value);
418  return value;
419  } else {
420  cerr << ReadFrom() << "Attempting to get non-existent element " << el
421  << endl;
422  exit(-1);
423  }
424 }
Element * FindElement(const std::string &el="")
Searches for a specified element.
std::string ReadFrom(void) const
Return a string that contains a description of the location where the current XML element was read fr...
Element(const std::string &nm)
Constructor.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ FindElementValueAsNumberConvertFromTo()

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.

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 503 of file FGXMLElement.cpp.

506 {
507  Element* element = FindElement(el);
508 
509  if (!element) {
510  cerr << "Attempting to get non-existent element " << el << endl;
511  exit(-1);
512  }
513 
514  if (!supplied_units.empty()) {
515  if (convert.find(supplied_units) == convert.end()) {
516  cerr << element->ReadFrom() << "Supplied unit: \""
517  << supplied_units << "\" does not exist (typo?)." << endl;
518  exit(-1);
519  }
520  if (convert[supplied_units].find(target_units) == convert[supplied_units].end()) {
521  cerr << element->ReadFrom() << "Supplied unit: \""
522  << supplied_units << "\" cannot be converted to " << target_units
523  << endl;
524  exit(-1);
525  }
526  }
527 
528  double value = element->GetDataAsNumber();
529  if (!supplied_units.empty()) {
530  value *= convert[supplied_units][target_units];
531  }
532 
533  value = DisperseValue(element, value, supplied_units, target_units);
534 
535  return value;
536 }
Element * FindElement(const std::string &el="")
Searches for a specified element.
Element(const std::string &nm)
Constructor.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ FindElementValueAsNumberConvertTo()

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.

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 440 of file FGXMLElement.cpp.

441 {
442  Element* element = FindElement(el);
443 
444  if (!element) {
445  cerr << ReadFrom() << "Attempting to get non-existent element " << el
446  << endl;
447  exit(-1);
448  }
449 
450  string supplied_units = element->GetAttributeValue("unit");
451 
452  if (!supplied_units.empty()) {
453  if (convert.find(supplied_units) == convert.end()) {
454  cerr << element->ReadFrom() << "Supplied unit: \""
455  << supplied_units << "\" does not exist (typo?)." << endl;
456  exit(-1);
457  }
458  if (convert[supplied_units].find(target_units) == convert[supplied_units].end()) {
459  cerr << element->ReadFrom() << "Supplied unit: \""
460  << supplied_units << "\" cannot be converted to " << target_units
461  << endl;
462  exit(-1);
463  }
464  }
465 
466  double value = element->GetDataAsNumber();
467 
468  // Sanity check for angular values
469  if ((supplied_units == "RAD") && (fabs(value) > 2 * M_PI)) {
470  cerr << element->ReadFrom() << element->GetName() << " value "
471  << value << " RAD is outside the range [ -2*M_PI RAD ; +2*M_PI RAD ]"
472  << endl;
473  }
474  if ((supplied_units == "DEG") && (fabs(value) > 360.0)) {
475  cerr << element->ReadFrom() << element->GetName() << " value "
476  << value << " DEG is outside the range [ -360 DEG ; +360 DEG ]"
477  << endl;
478  }
479 
480 
481  if (!supplied_units.empty()) {
482  value *= convert[supplied_units][target_units];
483  }
484 
485  if ((target_units == "RAD") && (fabs(value) > 2 * M_PI)) {
486  cerr << element->ReadFrom() << element->GetName() << " value "
487  << value << " RAD is outside the range [ -2*M_PI RAD ; +2*M_PI RAD ]"
488  << endl;
489  }
490  if ((target_units == "DEG") && (fabs(value) > 360.0)) {
491  cerr << element->ReadFrom() << element->GetName() << " value "
492  << value << " DEG is outside the range [ -360 DEG ; +360 DEG ]"
493  << endl;
494  }
495 
496  value = DisperseValue(element, value, supplied_units, target_units);
497 
498  return value;
499 }
Element * FindElement(const std::string &el="")
Searches for a specified element.
std::string ReadFrom(void) const
Return a string that contains a description of the location where the current XML element was read fr...
Element(const std::string &nm)
Constructor.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ FindNextElement()

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

Searches for the next element as specified.

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 390 of file FGXMLElement.cpp.

391 {
392  if (el.empty()) {
393  if (element_index < children.size()) {
394  return children[element_index++];
395  } else {
396  element_index = 0;
397  return 0L;
398  }
399  }
400  for (unsigned int i=element_index; i<children.size(); i++) {
401  if (el == children[i]->GetName()) {
402  element_index = i+1;
403  return children[i];
404  }
405  }
406  element_index = 0;
407  return 0L;
408 }
const std::string & GetName(void) const
Retrieves the element name.
Definition: FGXMLElement.h:186
+ Here is the caller graph for this function:

◆ GetAttributeValue()

string GetAttributeValue ( const std::string &  key)

Retrieves an attribute.

Parameters
keyspecifies the attribute key to retrieve the value of.
Returns
the key value (as a string), or the empty string if no such attribute exists.

Definition at line 252 of file FGXMLElement.cpp.

253 {
254  if (HasAttribute(attr)) return attributes[attr];
255  else return ("");
256 }
bool HasAttribute(const std::string &key)
Determines if an element has the supplied attribute.
Definition: FGXMLElement.h:162
+ Here is the caller graph for this function:

◆ GetAttributeValueAsNumber()

double GetAttributeValueAsNumber ( const std::string &  key)

Retrieves an attribute value as a double precision real number.

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 271 of file FGXMLElement.cpp.

272 {
273  string attribute = GetAttributeValue(attr);
274 
275  if (attribute.empty()) {
276  cerr << ReadFrom() << "Expecting numeric attribute value, but got no data"
277  << endl;
278  exit(-1);
279  }
280  else {
281  double number=0;
282  if (is_number(trim(attribute)))
283  number = atof(attribute.c_str());
284  else {
285  cerr << ReadFrom() << "Expecting numeric attribute value, but got: "
286  << attribute << endl;
287  exit(-1);
288  }
289 
290  return (number);
291  }
292 }
std::string GetAttributeValue(const std::string &key)
Retrieves an attribute.
std::string ReadFrom(void) const
Return a string that contains a description of the location where the current XML element was read fr...
+ Here is the caller graph for this function:

◆ GetDataAsNumber()

double GetDataAsNumber ( void  )

Converts the element data to a number.

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 331 of file FGXMLElement.cpp.

332 {
333  if (data_lines.size() == 1) {
334  double number=0;
335  if (is_number(trim(data_lines[0])))
336  number = atof(data_lines[0].c_str());
337  else {
338  cerr << ReadFrom() << "Expected numeric value, but got: " << data_lines[0]
339  << endl;
340  exit(-1);
341  }
342 
343  return number;
344  } else if (data_lines.size() == 0) {
345  cerr << ReadFrom() << "Expected numeric value, but got no data" << endl;
346  exit(-1);
347  } else {
348  cerr << ReadFrom() << "Attempting to get single data value in element "
349  << "<" << name << ">" << endl
350  << " from multiple lines:" << endl;
351  for(unsigned int i=0; i<data_lines.size(); ++i)
352  cerr << data_lines[i] << endl;
353  exit(-1);
354  }
355 }
std::string ReadFrom(void) const
Return a string that contains a description of the location where the current XML element was read fr...
+ Here is the caller graph for this function:

◆ GetDataLine()

string GetDataLine ( unsigned int  i = 0)

Gets a line of data belonging to an element.

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 323 of file FGXMLElement.cpp.

324 {
325  if (data_lines.size() > 0) return data_lines[i];
326  else return string("");
327 }
+ Here is the caller graph for this function:

◆ GetElement()

Element * GetElement ( unsigned int  el = 0)

Returns a pointer to the element requested by index.

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 296 of file FGXMLElement.cpp.

297 {
298  if (children.size() > el) {
299  element_index = el;
300  return children[el];
301  }
302  else {
303  element_index = 0;
304  return 0L;
305  }
306 }
+ Here is the caller graph for this function:

◆ GetFileName()

const std::string& GetFileName ( void  ) const
inline

Returns the name of the file in which the element has been read.

Returns
the file name

Definition at line 241 of file FGXMLElement.h.

241 { return file_name; }
+ Here is the call graph for this function:

◆ GetLineNumber()

int GetLineNumber ( void  ) const
inline

Returns the line number at which the element has been defined.

Returns
the line number

Definition at line 236 of file FGXMLElement.h.

236 { return line_number; }

◆ GetName()

const std::string& GetName ( void  ) const
inline

Retrieves the element name.

Returns
the element name, or the empty string if no name has been set.

Definition at line 186 of file FGXMLElement.h.

186 {return name;}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetNextElement()

Element * GetNextElement ( void  )

Returns a pointer to the next element in the list.

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 310 of file FGXMLElement.cpp.

311 {
312  if (children.size() > element_index+1) {
313  element_index++;
314  return children[element_index];
315  } else {
316  element_index = 0;
317  return 0L;
318  }
319 }
+ Here is the caller graph for this function:

◆ GetParent()

Element* GetParent ( void  )
inline

Returns a pointer to the parent of an element.

Returns
a pointer to the parent Element, or 0 if this is the top level Element.

Definition at line 231 of file FGXMLElement.h.

231 {return parent;}
+ Here is the caller graph for this function:

◆ HasAttribute()

bool HasAttribute ( const std::string &  key)
inline

Determines if an element has the supplied attribute.

Parameters
keyspecifies the attribute key to retrieve the value of.
Returns
true or false.

Definition at line 162 of file FGXMLElement.h.

162 {return attributes.find(key) != attributes.end();}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MergeAttributes()

void MergeAttributes ( Element el)

Merges the attributes of the current element with another element.

The attributes from the current element override the element that is passed as a parameter. In other words if the two elements have an attribute with the same name, the attribute from the current element is kept and the corresponding attribute of the other element is ignored.

Parameters
elelement with which the current element will merge its attributes.

Definition at line 697 of file FGXMLElement.cpp.

698 {
699  map<string, string>::iterator it;
700 
701  for (it=el->attributes.begin(); it != el->attributes.end(); ++it) {
702  if (attributes.find(it->first) == attributes.end())
703  attributes[it->first] = it->second;
704  else {
705  if (FGJSBBase::debug_lvl > 0 && (attributes[it->first] != it->second))
706  cout << el->ReadFrom() << " Attribute '" << it->first << "' is overridden in file "
707  << GetFileName() << ": line " << GetLineNumber() << endl
708  << " The value '" << attributes[it->first] << "' will be used instead of '"
709  << it->second << "'." << endl;
710  }
711  }
712 }
const std::string & GetFileName(void) const
Returns the name of the file in which the element has been read.
Definition: FGXMLElement.h:241
int GetLineNumber(void) const
Returns the line number at which the element has been defined.
Definition: FGXMLElement.h:236
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Print()

void Print ( unsigned int  level = 0)

Prints the element.

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 642 of file FGXMLElement.cpp.

643 {
644  unsigned int i, spaces;
645 
646  level+=2;
647  for (spaces=0; spaces<=level; spaces++) cout << " "; // format output
648  cout << "Element Name: " << name;
649 
650  map<string, string>::iterator it;
651  for (it = attributes.begin(); it != attributes.end(); ++it)
652  cout << " " << it->first << " = " << it->second;
653 
654  cout << endl;
655  for (i=0; i<data_lines.size(); i++) {
656  for (spaces=0; spaces<=level; spaces++) cout << " "; // format output
657  cout << data_lines[i] << endl;
658  }
659  for (i=0; i<children.size(); i++) {
660  children[i]->Print(level);
661  }
662 }
+ Here is the caller graph for this function:

◆ ReadFrom()

string ReadFrom ( void  ) const

Return a string that contains a description of the location where the current XML element was read from.

Returns
a string describing the file name and line number where the element was read.

Definition at line 684 of file FGXMLElement.cpp.

685 {
686  ostringstream message;
687 
688  message << endl
689  << "In file " << GetFileName() << ": line " << GetLineNumber()
690  << endl;
691 
692  return message.str();
693 }
const std::string & GetFileName(void) const
Returns the name of the file in which the element has been read.
Definition: FGXMLElement.h:241
int GetLineNumber(void) const
Returns the line number at which the element has been defined.
Definition: FGXMLElement.h:236
+ Here is the caller graph for this function:

◆ SetAttributeValue()

bool SetAttributeValue ( const std::string &  key,
const std::string &  value 
)

Modifies an attribute.

Parameters
keyspecifies the attribute key to modify the value of.
valuenew key value (as a string).
Returns
false if it did not find any attribute with the requested key, true otherwise.

Definition at line 260 of file FGXMLElement.cpp.

261 {
262  bool ret = HasAttribute(key);
263  if (ret)
264  attributes[key] = value;
265 
266  return ret;
267 }
bool HasAttribute(const std::string &key)
Determines if an element has the supplied attribute.
Definition: FGXMLElement.h:162
+ Here is the caller graph for this function:

◆ SetFileName()

void SetFileName ( const std::string &  name)
inline

Set the name of the file in which the element has been read.

Parameters
namefile name

Definition at line 365 of file FGXMLElement.h.

365 { file_name = name; }
+ Here is the call graph for this function:

◆ SetLineNumber()

void SetLineNumber ( int  line)
inline

Set the line number at which the element has been read.

Parameters
lineline number.

Definition at line 360 of file FGXMLElement.h.

360 { line_number = line; }

◆ SetParent()

void SetParent ( Element p)
inline

This function sets the value of the parent class attribute to the supplied Element pointer.

Parameters
ppointer to the parent Element.

Definition at line 337 of file FGXMLElement.h.

337 {parent = p;}
+ Here is the caller graph for this function:

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