JSBSim Flight Dynamics Model 1.3.0 (09 Apr 2026)
An Open Source Flight Dynamics and Control Software Library in C++
Loading...
Searching...
No Matches
Element Class Reference

Detailed Description

Definition at line 143 of file FGXMLElement.h.

+ Inheritance diagram for Element:
+ Collaboration diagram for Element:

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.
 
void ChangeName (const std::string &_name)
 
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.
 
bool FindElementValueAsBoolean (const std::string &el="")
 Searches for the named element and returns the data belonging to it as a bool.
 
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 & GetFileName (void) const
 Returns the name of the file in which the element has been read.
 
int GetLineNumber (void) const
 Returns the line number at which the element has been defined.
 
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 (const std::string &element_name)
 Returns the number of named child elements for this element.
 
unsigned int GetNumElements (void)
 Returns the number of 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 MergeAttributes (Element *el)
 Merges the attributes of the current element with another element.
 
void Print (unsigned int level=0)
 Prints the element.
 
std::string ReadFrom (void) const
 Return a string that contains a description of the location where the current XML element was read from.
 
bool SetAttributeValue (const std::string &key, const std::string &value)
 Modifies an attribute.
 
void SetFileName (const std::string &name)
 Set the name of the file in which the element has been read.
 
void SetLineNumber (int line)
 Set the line number at which the element has been read.
 
void SetParent (Element *p)
 This function sets the value of the parent class attribute to the supplied Element pointer.
 

Constructor & Destructor Documentation

◆ Element()

Element ( const std::string &  nm)

Constructor.

Parameters
nmthe name of this element (if given)

Definition at line 55 of file FGXMLElement.cpp.

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

◆ ~Element()

~Element ( void  )

Destructor.

Definition at line 260 of file FGXMLElement.cpp.

261{
262 for (unsigned int i = 0; i < children.size(); ++i)
263 children[i]->SetParent(0);
264}
void SetParent(Element *p)
This function sets the value of the parent class attribute to the supplied Element pointer.
+ Here is the call graph for this function:

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

707{
708 attributes[name] = value;
709}
+ 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 345 of file FGXMLElement.h.

345{children.push_back(el);}
+ 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 713 of file FGXMLElement.cpp.

714{
715 string::size_type string_start = d.find_first_not_of(" \t");
716 if (string_start != string::npos && string_start > 0) {
717 d.erase(0,string_start);
718 }
719 data_lines.push_back(d);
720}

◆ ChangeName()

void ChangeName ( const std::string &  _name)
inline

Definition at line 180 of file FGXMLElement.h.

180{ name = _name; }

◆ DisperseValue()

double DisperseValue ( Element e,
double  val,
const std::string &  supplied_units = "",
const std::string &  target_units = "" 
)

Definition at line 641 of file FGXMLElement.cpp.

643{
644 double value=val;
645 bool disperse = false;
646
647 if(char* num = getenv("JSBSIM_DISPERSE"); num != nullptr)
648 disperse = strtol(num, nullptr, 0) == 1; // set dispersions
649
650 if (e->HasAttribute("dispersion") && disperse) {
651 double disp = e->GetAttributeValueAsNumber("dispersion");
652 if (!supplied_units.empty()) disp *= convert[supplied_units][target_units];
653 string attType = e->GetAttributeValue("type");
654 RandomNumberGenerator generator;
655
656 if (attType == "gaussian" || attType == "gaussiansigned") {
657 double grn = generator.GetNormalRandomNumber();
658 if (attType == "gaussian")
659 value = val + disp*grn;
660 else // Assume gaussiansigned
661 value = (val + disp*grn)*FGJSBBase::sign(grn);
662 } else if (attType == "uniform" || attType == "uniformsigned") {
663 double urn = generator.GetUniformRandomNumber();
664 if (attType == "uniform")
665 value = val + disp * urn;
666 else // Assume uniformsigned
667 value = (val + disp * urn)*FGJSBBase::sign(urn);
668 } else {
669 XMLLogException err(this);
670 err << "Unknown dispersion type" << attType << "\n";
671 throw err;
672 }
673
674 }
675 return value;
676}

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

391{
392 if (el.empty() && children.size() >= 1) {
393 element_index = 1;
394 return children[0];
395 }
396 for (unsigned int i=0; i<children.size(); i++) {
397 if (el == children[i]->GetName()) {
398 element_index = i+1;
399 return children[i];
400 }
401 }
402 element_index = 0;
403 return 0L;
404}
const std::string & GetName(void) const
Retrieves the element name.
+ Here is the call graph for this function:
+ 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 583 of file FGXMLElement.cpp.

584{
585 FGColumnVector3 triplet;
586 Element* item;
587 double value=0.0;
588 string supplied_units = GetAttributeValue("unit");
589
590 if (!supplied_units.empty()) {
591 if (convert.find(supplied_units) == convert.end()) {
592 XMLLogException err(this);
593 err << "Supplied unit: \"" << supplied_units
594 << "\" does not exist (typo?).\n";
595 throw err;
596 }
597 if (convert[supplied_units].find(target_units) == convert[supplied_units].end()) {
598 XMLLogException err(this);
599 err << "Supplied unit: \"" << supplied_units
600 << "\" cannot be converted to " << target_units << "\n";
601 throw err;
602 }
603 }
604
605 item = FindElement("x");
606 if (!item) item = FindElement("roll");
607 if (item) {
608 value = item->GetDataAsNumber();
609 if (!supplied_units.empty()) value *= convert[supplied_units][target_units];
610 triplet(1) = DisperseValue(item, value, supplied_units, target_units);
611 } else {
612 triplet(1) = 0.0;
613 }
614
615
616 item = FindElement("y");
617 if (!item) item = FindElement("pitch");
618 if (item) {
619 value = item->GetDataAsNumber();
620 if (!supplied_units.empty()) value *= convert[supplied_units][target_units];
621 triplet(2) = DisperseValue(item, value, supplied_units, target_units);
622 } else {
623 triplet(2) = 0.0;
624 }
625
626 item = FindElement("z");
627 if (!item) item = FindElement("yaw");
628 if (item) {
629 value = item->GetDataAsNumber();
630 if (!supplied_units.empty()) value *= convert[supplied_units][target_units];
631 triplet(3) = DisperseValue(item, value, supplied_units, target_units);
632 } else {
633 triplet(3) = 0.0;
634 }
635
636 return triplet;
637}
Element * FindElement(const std::string &el="")
Searches for a specified element.
Element(const std::string &nm)
Constructor.
std::string GetAttributeValue(const std::string &key)
Retrieves an attribute.
+ 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 469 of file FGXMLElement.cpp.

470{
471 Element* element = FindElement(el);
472 if (element) {
473 return element->GetDataLine();
474 } else {
475 return "";
476 }
477}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ FindElementValueAsBoolean()

bool FindElementValueAsBoolean ( const std::string &  el = "")

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

This function allows the data belonging to a named element to be returned as a bool. If no element is found, false 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 bool, or false if the data is missing. Zero will be false, while any other number will be true.

Definition at line 446 of file FGXMLElement.cpp.

447{
448 Element* element = FindElement(el);
449 if (element) {
450 // check value as an ordinary number
451 double value = element->GetDataAsNumber();
452
453 // now check how it should return data
454 if (value == 0) {
455 return false;
456 } else {
457 return true;
458 }
459 } else {
460 FGXMLLogging log(this, LogLevel::ERROR);
461 log << "Attempting to get non-existent element " << el
462 << " ;returning false\n";
463 return false;
464 }
465}
+ Here is the call 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 430 of file FGXMLElement.cpp.

431{
432 Element* element = FindElement(el);
433 if (element) {
434 double value = element->GetDataAsNumber();
435 value = DisperseValue(element, value);
436 return value;
437 } else {
438 XMLLogException err(this);
439 err << "Attempting to get non-existent element " << el << "\n";
440 throw err;
441 }
442}
+ 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 544 of file FGXMLElement.cpp.

547{
548 Element* element = FindElement(el);
549
550 if (!element) {
551 XMLLogException err(this);
552 err << "Attempting to get non-existent element " << el << "\n";
553 throw err;
554 }
555
556 if (!supplied_units.empty()) {
557 if (convert.find(supplied_units) == convert.end()) {
558 XMLLogException err(element);
559 err << "Supplied unit: \"" << supplied_units
560 << "\" does not exist (typo?).\n";
561 throw err;
562 }
563 if (convert[supplied_units].find(target_units) == convert[supplied_units].end()) {
564 XMLLogException err(element);
565 err << "Supplied unit: \"" << supplied_units
566 << "\" cannot be converted to " << target_units << "\n";
567 throw err;
568 }
569 }
570
571 double value = element->GetDataAsNumber();
572 if (!supplied_units.empty()) {
573 value *= convert[supplied_units][target_units];
574 }
575
576 value = DisperseValue(element, value, supplied_units, target_units);
577
578 return value;
579}
+ 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 481 of file FGXMLElement.cpp.

482{
483 Element* element = FindElement(el);
484
485 if (!element) {
486 XMLLogException err(this);
487 err << "Attempting to get non-existent element " << el << "\n";
488 throw err;
489 }
490
491 string supplied_units = element->GetAttributeValue("unit");
492
493 if (!supplied_units.empty()) {
494 if (convert.find(supplied_units) == convert.end()) {
495 XMLLogException err(element);
496 err << "Supplied unit: \"" << supplied_units << "\" does not exist (typo?).\n";
497 throw err;
498 }
499 if (convert[supplied_units].find(target_units) == convert[supplied_units].end()) {
500 XMLLogException err(element);
501 err << "Supplied unit: \"" << supplied_units
502 << "\" cannot be converted to " << target_units << "\n";
503 throw err;
504 }
505 }
506
507 double value = element->GetDataAsNumber();
508
509 // Sanity check for angular values
510 if ((supplied_units == "RAD") && (fabs(value) > 2 * M_PI)) {
511 FGXMLLogging log(element, LogLevel::ERROR);
512 log << element->GetName() << " value "
513 << value << " RAD is outside the range [ -2*M_PI RAD ; +2*M_PI RAD ]\n";
514 }
515 if ((supplied_units == "DEG") && (fabs(value) > 360.0)) {
516 FGXMLLogging log(element, LogLevel::ERROR);
517 log << element->GetName() << " value "
518 << value << " DEG is outside the range [ -360 DEG ; +360 DEG ]\n";
519 }
520
521
522 if (!supplied_units.empty()) {
523 value *= convert[supplied_units][target_units];
524 }
525
526 if ((target_units == "RAD") && (fabs(value) > 2 * M_PI)) {
527 FGXMLLogging log(element, LogLevel::ERROR);
528 log << element->GetName() << " value "
529 << value << " RAD is outside the range [ -2*M_PI RAD ; +2*M_PI RAD ]\n";
530 }
531 if ((target_units == "DEG") && (fabs(value) > 360.0)) {
532 FGXMLLogging log(element, LogLevel::ERROR);
533 log << element->GetName() << " value "
534 << value << " DEG is outside the range [ -360 DEG ; +360 DEG ]\n";
535 }
536
537 value = DisperseValue(element, value, supplied_units, target_units);
538
539 return value;
540}
+ 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 408 of file FGXMLElement.cpp.

409{
410 if (el.empty()) {
411 if (element_index < children.size()) {
412 return children[element_index++];
413 } else {
414 element_index = 0;
415 return 0L;
416 }
417 }
418 for (unsigned int i=element_index; i<children.size(); i++) {
419 if (el == children[i]->GetName()) {
420 element_index = i+1;
421 return children[i];
422 }
423 }
424 element_index = 0;
425 return 0L;
426}
+ Here is the call graph for this function:
+ 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 268 of file FGXMLElement.cpp.

269{
270 if (HasAttribute(attr)) return attributes[attr];
271 else return ("");
272}
bool HasAttribute(const std::string &key)
Determines if an element has the supplied attribute.
+ Here is the call graph for this function:
+ 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 287 of file FGXMLElement.cpp.

288{
289 string attribute = GetAttributeValue(attr);
290
291 if (attribute.empty()) {
292 XMLLogException err(this);
293 err << "Expecting numeric attribute value, but got no data\n";
294 throw err;
295 }
296 else {
297 double number=0;
298 try {
299 number = atof_locale_c(attribute);
300 } catch (InvalidNumber& e) {
301 XMLLogException err(this);
302 err << e.what() << "\n";
303 throw err;
304 }
305
306 return (number);
307 }
308}
+ Here is the call graph for this function:
+ 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 347 of file FGXMLElement.cpp.

348{
349 if (data_lines.size() == 1) {
350 double number=0;
351 try {
352 number = atof_locale_c(data_lines[0]);
353 } catch (InvalidNumber& e) {
354 XMLLogException err(this);
355 err << e.what() << "\n";
356 throw err;
357 }
358
359 return number;
360 } else if (data_lines.empty()) {
361 XMLLogException err(this);
362 err << "Expected numeric value, but got no data\n";
363 throw err;
364 } else {
365 XMLLogException err(this);
366 err << "Attempting to get single data value in element "
367 << "<" << name << ">\n"
368 << " from multiple lines:\n";
369 for(unsigned int i=0; i<data_lines.size(); ++i)
370 err << data_lines[i] << "\n";
371 throw err;
372 }
373}
+ 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 339 of file FGXMLElement.cpp.

340{
341 if (!data_lines.empty()) return data_lines[i];
342 else return string("");
343}
+ 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 312 of file FGXMLElement.cpp.

313{
314 if (children.size() > el) {
315 element_index = el;
316 return children[el];
317 }
318 else {
319 element_index = 0;
320 return 0L;
321 }
322}
+ 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 235 of file FGXMLElement.h.

235{ return file_name; }
+ Here is the caller 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 230 of file FGXMLElement.h.

230{ return line_number; }
+ Here is the caller graph for this function:

◆ 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 179 of file FGXMLElement.h.

179{return name;}
+ 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 326 of file FGXMLElement.cpp.

327{
328 if (children.size() > element_index+1) {
329 element_index++;
330 return children[element_index];
331 } else {
332 element_index = 0;
333 return 0L;
334 }
335}
+ Here is the caller graph for this function:

◆ GetNumDataLines()

unsigned int GetNumDataLines ( void  )
inline

Returns the number of lines of data stored.

Definition at line 189 of file FGXMLElement.h.

189{return (unsigned int)data_lines.size();}
+ Here is the caller graph for this function:

◆ GetNumElements() [1/2]

unsigned int GetNumElements ( const std::string &  element_name)

Returns the number of named child elements for this element.

Definition at line 377 of file FGXMLElement.cpp.

378{
379 unsigned int number_of_elements=0;
380 Element* el=FindElement(element_name);
381 while (el) {
382 number_of_elements++;
383 el=FindNextElement(element_name);
384 }
385 return number_of_elements;
386}
Element * FindNextElement(const std::string &el="")
Searches for the next element as specified.
+ Here is the call graph for this function:

◆ GetNumElements() [2/2]

unsigned int GetNumElements ( void  )
inline

Returns the number of child elements for this element.

Definition at line 192 of file FGXMLElement.h.

192{return (unsigned int)children.size();}
+ 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 225 of file FGXMLElement.h.

225{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 155 of file FGXMLElement.h.

155{return attributes.find(key) != attributes.end();}
+ 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 737 of file FGXMLElement.cpp.

738{
739 map<string, string>::iterator it;
740
741 for (it=el->attributes.begin(); it != el->attributes.end(); ++it) {
742 if (attributes.find(it->first) == attributes.end())
743 attributes[it->first] = it->second;
744 else {
745 if (FGJSBBase::debug_lvl > 0 && (attributes[it->first] != it->second)) {
746 FGXMLLogging log(el, LogLevel::DEBUG);
747 log << " Attribute '" << it->first << "' is overridden in file "
748 << GetFileName() << ": line " << GetLineNumber() << "\n"
749 << " The value '" << attributes[it->first] << "' will be used instead of '"
750 << it->second << "'.\n";
751 }
752 }
753 }
754}
int GetLineNumber(void) const
Returns the line number at which the element has been defined.
const std::string & GetFileName(void) const
Returns the name of the file in which the element has been read.
+ 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 680 of file FGXMLElement.cpp.

681{
682 level+=2;
683
684 {
685 FGLogging out(LogLevel::STDOUT);
686 for (unsigned int spaces=0; spaces<=level; spaces++) out << " ";
687 out << "Element Name: " << name;
688
689 for (auto const& attr : attributes)
690 out << " " << attr.first << " = " << attr.second;
691
692 out << endl;
693 for (unsigned i=0; i<data_lines.size(); i++) {
694 for (unsigned int spaces=0; spaces<=level; spaces++) out << " ";
695 out << data_lines[i] << endl;
696 }
697 }
698
699 for (unsigned int i=0; i<children.size(); i++) {
700 children[i]->Print(level);
701 }
702}

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

725{
726 ostringstream message;
727
728 message << endl
729 << "In file " << GetFileName() << ": line " << GetLineNumber()
730 << endl;
731
732 return message.str();
733}
+ Here is the call graph for this function:
+ 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 276 of file FGXMLElement.cpp.

277{
278 bool ret = HasAttribute(key);
279 if (ret)
280 attributes[key] = value;
281
282 return ret;
283}
+ Here is the call 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 369 of file FGXMLElement.h.

369{ file_name = name; }

◆ SetLineNumber()

void SetLineNumber ( int  line)
inline

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

Parameters
lineline number.

Definition at line 364 of file FGXMLElement.h.

364{ 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 341 of file FGXMLElement.h.

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

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