FlightGear next
Element Class Reference

#include <FGXMLElement.h>

Inherits SGReferenced.

Public Member Functions

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

Detailed Description

Definition at line 143 of file FGXMLElement.h.

Constructor & Destructor Documentation

◆ Element()

JSBSim::Element::Element ( const std::string & nm)

Constructor.

Parameters
nmthe name of this element (if given)

Definition at line 51 of file FGXMLElement.cpp.

◆ ~Element()

JSBSim::Element::~Element ( void )

Destructor.

Definition at line 252 of file FGXMLElement.cpp.

Member Function Documentation

◆ AddAttribute()

void JSBSim::Element::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 720 of file FGXMLElement.cpp.

◆ AddChildElement()

void JSBSim::Element::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.

◆ AddData()

void JSBSim::Element::AddData ( std::string d)

Stores data belonging to this element.

Parameters
dthe data to store.

Definition at line 727 of file FGXMLElement.cpp.

◆ ChangeName()

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

Definition at line 180 of file FGXMLElement.h.

◆ DisperseValue()

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

Definition at line 649 of file FGXMLElement.cpp.

◆ FindElement()

Element * JSBSim::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 389 of file FGXMLElement.cpp.

◆ FindElementTripletConvertTo()

FGColumnVector3 JSBSim::Element::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 589 of file FGXMLElement.cpp.

◆ FindElementValue()

string JSBSim::Element::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 468 of file FGXMLElement.cpp.

◆ FindElementValueAsBoolean()

bool JSBSim::Element::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.

◆ FindElementValueAsNumber()

double JSBSim::Element::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 429 of file FGXMLElement.cpp.

◆ FindElementValueAsNumberConvertFromTo()

double JSBSim::Element::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 547 of file FGXMLElement.cpp.

◆ FindElementValueAsNumberConvertTo()

double JSBSim::Element::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 480 of file FGXMLElement.cpp.

◆ FindNextElement()

Element * JSBSim::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 407 of file FGXMLElement.cpp.

◆ GetAttributeValue()

string JSBSim::Element::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 260 of file FGXMLElement.cpp.

◆ GetAttributeValueAsNumber()

double JSBSim::Element::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 279 of file FGXMLElement.cpp.

◆ GetDataAsNumber()

double JSBSim::Element::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 341 of file FGXMLElement.cpp.

◆ GetDataLine()

string JSBSim::Element::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 333 of file FGXMLElement.cpp.

◆ GetElement()

Element * JSBSim::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 306 of file FGXMLElement.cpp.

◆ GetFileName()

const std::string & JSBSim::Element::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.

◆ GetLineNumber()

int JSBSim::Element::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.

◆ GetName()

const std::string & JSBSim::Element::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.

◆ GetNextElement()

Element * JSBSim::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 320 of file FGXMLElement.cpp.

◆ GetNumDataLines()

unsigned int JSBSim::Element::GetNumDataLines ( void )
inline

Returns the number of lines of data stored.

Definition at line 189 of file FGXMLElement.h.

◆ GetNumElements() [1/2]

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

Returns the number of named child elements for this element.

◆ GetNumElements() [2/2]

unsigned int JSBSim::Element::GetNumElements ( void )
inline

Returns the number of child elements for this element.

Definition at line 192 of file FGXMLElement.h.

◆ GetParent()

Element * JSBSim::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.

◆ HasAttribute()

bool JSBSim::Element::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.

◆ MergeAttributes()

void JSBSim::Element::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 751 of file FGXMLElement.cpp.

◆ Print()

void JSBSim::Element::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 696 of file FGXMLElement.cpp.

◆ ReadFrom()

string JSBSim::Element::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 738 of file FGXMLElement.cpp.

◆ SetAttributeValue()

bool JSBSim::Element::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 268 of file FGXMLElement.cpp.

◆ SetFileName()

void JSBSim::Element::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.

◆ SetLineNumber()

void JSBSim::Element::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.

◆ SetParent()

void JSBSim::Element::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.


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