]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/input_output/FGXMLElement.h
PAtch by Andreas Gaeb to eliminate NaN's in the location code
[flightgear.git] / src / FDM / JSBSim / input_output / FGXMLElement.h
index 55aa6b1f72a3549c6c7ecfc6d37ef2e82cb48375..21af97275d2251a8af575465723b0ab2e57ddcd5 100755 (executable)
@@ -4,7 +4,7 @@
  Author:       Jon S. Berndt
  Date started: 9/28/04
 
- ------------- Copyright (C) 2004  Jon S. Berndt (jsb@hal-pc.org) -------------
+ ------------- Copyright (C) 2004  Jon S. Berndt (jon@jsbsim.org) -------------
 
  This program is free software; you can redistribute it and/or modify it under
  the terms of the GNU Lesser General Public License as published by the Free Software
@@ -34,30 +34,17 @@ SENTRY
 INCLUDES
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
-#ifdef FGFS
-#  include <simgear/compiler.h>
-#  ifdef SG_HAVE_STD_INCLUDES
-#    include <string>
-#    include <vector>
-#    include <map>
-#  else
-#    include <vector.h>
-#    include <string>
-#    include <map.h>
-#  endif
-#else
-#  include <string>
-#  include <map>
-#  include <vector>
-#endif
+#include <string>
+#include <map>
+#include <vector>
 
-#include <math/FGColumnVector3.h>
+#include "math/FGColumnVector3.h"
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 DEFINITIONS
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
-#define ID_XMLELEMENT "$Id$"
+#define ID_XMLELEMENT "$Id: FGXMLElement.h,v 1.16 2009/10/24 22:59:30 jberndt Exp $"
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 FORWARD DECLARATIONS
@@ -95,6 +82,10 @@ CLASS DOCUMENTATION
     - convert["N"]["LBS"] = 0.22482;
     - convert["LBS"]["N"] = 1.0/convert["N"]["LBS"];
     - convert["KTS"]["FT/SEC"] = ktstofps;
+    - convert["KG/MIN"]["LBS/MIN"] = convert["KG"]["LBS"];
+    - convert["LBS/HP*HR"]["KG/KW*HR"] = 0.6083;
+    - convert["KG/KW*HR"]["LBS/HP*HR"] = 1/convert["LBS/HP*HR"]["KG/KW*HR"];
+    - convert["KG/L"]["LBS/GAL"] = 8.3454045;
 
     - convert["M"]["M"] = 1.00;
     - convert["FT"]["FT"] = 1.00;
@@ -118,6 +109,12 @@ CLASS DOCUMENTATION
     - convert["WATTS"]["WATTS"] = 1.00;
     - convert["KTS"]["KTS"] = 1.0;
     - convert["FT/SEC"]["FT/SEC"] = 1.0;
+    - convert["KG/MIN"]["KG/MIN"] = 1.0;
+    - convert["LBS/MIN"]["LBS/MIN"] = 1.0;
+    - convert["LBS/HP*HR"]["LBS/HP*HR"] = 1.0;
+    - convert["KG/KW*HR"]["KG/KW*HR"] = 1.0;
+    - convert["KG/L"]["KG/L"] = 1.0;
+    - convert["LBS/GAL"]["LBS/GAL"] = 1.0;
 
     Where:
     - N = newtons
@@ -128,13 +125,18 @@ CLASS DOCUMENTATION
     - FT = feet
     - FT2 = feet squared
     - SEC = seconds
+    - MIN = minutes
     - SLUG = slug
     - DEG = degrees
     - RAD = radians
     - WATTS = watts
+    - HP = horsepower
+    - HR = hour
+    - L = liter
+    - GAL = gallon (U.S. liquid) 
 
     @author Jon S. Berndt
-    @version $Id$
+    @version $Id: FGXMLElement.h,v 1.16 2009/10/24 22:59:30 jberndt Exp $
 */
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -146,7 +148,7 @@ public:
   /** Constructor
       @param nm the name of this element (if given)
       */
-  Element(std::string nm);
+  Element(const std::string& nm);
   /// Destructor
   ~Element(void);
 
@@ -154,17 +156,17 @@ public:
       @param key specifies the attribute key to retrieve the value of.
       @return the key value (as a string), or the empty string if no such
               attribute exists. */
-  std::string GetAttributeValue(std::string key);
+  std::string GetAttributeValue(const std::string& key);
 
   /** Retrieves an attribute value as a double precision real number.
       @param key specifies the attribute key to retrieve the value of.
       @return the key value (as a number), or the HUGE_VAL if no such
               attribute exists. */
-  double GetAttributeValueAsNumber(std::string key);
+  double GetAttributeValueAsNumber(const std::string& key);
 
   /** Retrieves the element name.
       @return the element name, or the empty string if no name has been set.*/
-  std::string GetName(void) {return name;}
+  const std::string& GetName(void) const {return name;}
 
   /** Gets a line of data belonging to an element.
       @param i the index of the data line to return (0 by default).
@@ -179,7 +181,7 @@ public:
   unsigned int GetNumElements(void) {return (unsigned int)children.size();}
 
   /// Returns the number of named child elements for this element.
-  unsigned int GetNumElements(std::string);
+  unsigned int GetNumElements(const std::string& element_name);
 
   /** Converts the element data to a number.
       This function attempts to convert the first (and presumably only) line of
@@ -212,12 +214,12 @@ public:
   Element* GetParent(void) {return parent;}
 
   /** Searches for a specified element.
-      Finds the first element that matches the supplied std::string, or simply the first
-      element if no search std::string is supplied. This function call resets the internal
+      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.
-      @param el the search std::string (empty std::string by default).
-      @return a pointer to the first element that matches the supplied search std::string. */
-  Element* FindElement(std::string el="");
+      @param el the search string (empty string by default).
+      @return a pointer to the first element that matches the supplied search string. */
+  Element* FindElement(const std::string& el="");
 
   /** Searches for the next element as specified.
       This function would be called after FindElement() is first called (in order to
@@ -228,7 +230,7 @@ public:
       @param el the name of the next element to find.
       @return the pointer to the found element, or 0 if no appropriate element us
               found.*/
-  Element* FindNextElement(std::string el="");
+  Element* FindNextElement(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
@@ -238,7 +240,7 @@ public:
       default)
       @return the data value for the named element as a string, or the empty
               string if the element cannot be found. */
-  std::string FindElementValue(std::string el="");
+  std::string FindElementValue(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
@@ -248,7 +250,7 @@ public:
       default)
       @return the data value for the named element as a double, or HUGE_VAL if the
               data is missing. */
-  double FindElementValueAsNumber(std::string el="");
+  double FindElementValueAsNumber(const std::string& el="");
 
   /** 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
@@ -265,7 +267,7 @@ public:
              to which the value returned will be converted.
       @return the unit-converted data value for the named element as a double,
               or HUGE_VAL if the data is missing. */
-  double FindElementValueAsNumberConvertTo(std::string el, std::string target_units);
+  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
@@ -284,9 +286,9 @@ public:
              to which the value returned will be converted.
       @return the unit-converted data value for the named element as a double,
               or HUGE_VAL if the data is missing. */
-  double FindElementValueAsNumberConvertFromTo( std::string el,
-                                                std::string supplied_units,
-                                                std::string target_units);
+  double FindElementValueAsNumberConvertFromTo( const std::string& el,
+                                                const std::string& supplied_units,
+                                                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
@@ -297,7 +299,7 @@ public:
       @param target_units the string representing the native units used by JSBSim
              to which the value returned will be converted.
       @return a column vector object built from the LOCATION or ORIENT components. */
-  FGColumnVector3 FindElementTripletConvertTo( std::string target_units);
+  FGColumnVector3 FindElementTripletConvertTo( const std::string& target_units);
 
   /** This function sets the value of the parent class attribute to the supplied
       Element pointer.
@@ -311,7 +313,7 @@ public:
   /** Stores an attribute belonging to this element.
   *   @param name The string name of the attribute.
   *   @param value The string value of the attribute. */
-  void AddAttribute(std::string name, std::string value);
+  void AddAttribute(const std::string& name, const std::string& value);
 
   /** Stores data belonging to this element.
   *   @param d the data to store. */
@@ -331,7 +333,8 @@ private:
   Element *parent;
   unsigned int element_index;
   typedef std::map <std::string, std::map <std::string, double> > tMapConvert;
-  tMapConvert convert;
+  static tMapConvert convert;
+  static bool converterIsInitialized;
 };
 
 } // namespace JSBSim