LCOV - code coverage report
Current view: top level - input_output - FGXMLElement.cpp (source / functions) Hit Total Coverage
Test: JSBSim-Coverage-Statistics Lines: 234 291 80.4 %
Date: 2010-08-24 Functions: 20 24 83.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 58 118 49.2 %

           Branch data     Line data    Source code
       1                 :            : /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       2                 :            : 
       3                 :            :  Author:       Jon Berndt
       4                 :            :  Date started: 09/28/2004
       5                 :            :  Purpose:      XML element class
       6                 :            :  Called by:    FGXMLParse
       7                 :            : 
       8                 :            :  ------------- Copyright (C) 2001  Jon S. Berndt (jon@jsbsim.org) -------------
       9                 :            : 
      10                 :            :  This program is free software; you can redistribute it and/or modify it under
      11                 :            :  the terms of the GNU Lesser General Public License as published by the Free Software
      12                 :            :  Foundation; either version 2 of the License, or (at your option) any later
      13                 :            :  version.
      14                 :            : 
      15                 :            :  This program is distributed in the hope that it will be useful, but WITHOUT
      16                 :            :  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      17                 :            :  FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      18                 :            :  details.
      19                 :            : 
      20                 :            :  You should have received a copy of the GNU Lesser General Public License along with
      21                 :            :  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
      22                 :            :  Place - Suite 330, Boston, MA  02111-1307, USA.
      23                 :            : 
      24                 :            :  Further information about the GNU Lesser General Public License can also be found on
      25                 :            :  the world wide web at http://www.gnu.org.
      26                 :            : 
      27                 :            : %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      28                 :            : INCLUDES
      29                 :            : %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
      30                 :            : 
      31                 :            : #include "FGXMLElement.h"
      32                 :            : 
      33                 :            : #include <cmath>
      34                 :            : #include <cstdlib>
      35                 :            : #include <iostream>
      36                 :            : 
      37                 :            : using namespace std;
      38                 :            : 
      39                 :            : /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      40                 :            : FORWARD DECLARATIONS
      41                 :            : %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
      42                 :            : 
      43                 :            : namespace JSBSim {
      44                 :            : 
      45                 :            : static const char *IdSrc = "$Id: FGXMLElement.cpp,v 1.29 2010/03/18 13:18:31 jberndt Exp $";
      46                 :            : static const char *IdHdr = ID_XMLELEMENT;
      47                 :            : 
      48                 :            : bool Element::converterIsInitialized = false;
      49 [ +  + ][ +  - ]:          4 : map <string, map <string, double> > Element::convert;
      50                 :            : 
      51                 :            : /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      52                 :            : CLASS IMPLEMENTATION
      53                 :            : %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
      54                 :            : 
      55                 :        930 : Element::Element(const string& nm)
      56                 :            : {
      57                 :        930 :   name   = nm;
      58                 :        930 :   parent = 0L;
      59                 :        930 :   element_index = 0;
      60                 :            : 
      61   [ +  +  #  # ]:        930 :   if (!converterIsInitialized) {
      62                 :          1 :     converterIsInitialized = true;
      63                 :            :     // convert ["from"]["to"] = factor, so: from * factor = to
      64                 :            :     // Length
      65                 :          1 :     convert["M"]["FT"] = 3.2808399;
      66                 :          1 :     convert["FT"]["M"] = 1.0/convert["M"]["FT"];
      67                 :          1 :     convert["FT"]["IN"] = 12.0;
      68                 :          1 :     convert["IN"]["FT"] = 1.0/convert["FT"]["IN"];
      69                 :          1 :     convert["IN"]["M"] = convert["IN"]["FT"] * convert["FT"]["M"];
      70                 :          1 :     convert["M"]["IN"] = convert["M"]["FT"] * convert["FT"]["IN"];
      71                 :            :     // Area
      72                 :          1 :     convert["M2"]["FT2"] = convert["M"]["FT"]*convert["M"]["FT"];
      73                 :          1 :     convert["FT2"]["M2"] = 1.0/convert["M2"]["FT2"];
      74                 :          1 :     convert["M2"]["IN2"] = convert["M"]["IN"]*convert["M"]["IN"];
      75                 :          1 :     convert["IN2"]["M2"] = 1.0/convert["M2"]["IN2"];
      76                 :          1 :     convert["FT2"]["IN2"] = 144.0;
      77                 :          1 :     convert["IN2"]["FT2"] = 1.0/convert["FT2"]["IN2"];
      78                 :            :     // Volume
      79                 :          1 :     convert["IN3"]["CC"] = 16.387064;
      80                 :          1 :     convert["CC"]["IN3"] = 1.0/convert["IN3"]["CC"];
      81                 :          1 :     convert["FT3"]["IN3"] = 1728.0;
      82                 :          1 :     convert["IN3"]["FT3"] = 1.0/convert["FT3"]["IN3"];
      83                 :          1 :     convert["M3"]["FT3"] = 35.3146667;
      84                 :          1 :     convert["FT3"]["M3"] = 1.0/convert["M3"]["FT3"];
      85                 :          1 :     convert["LTR"]["IN3"] = 61.0237441;
      86                 :          1 :     convert["IN3"]["LTR"] = 1.0/convert["LTR"]["IN3"];
      87                 :            :     // Mass & Weight
      88                 :          1 :     convert["LBS"]["KG"] = 0.45359237;
      89                 :          1 :     convert["KG"]["LBS"] = 1.0/convert["LBS"]["KG"];
      90                 :          1 :     convert["SLUG"]["KG"] = 14.59390;
      91                 :          1 :     convert["KG"]["SLUG"] = 1.0/convert["SLUG"]["KG"];
      92                 :            :     // Moments of Inertia
      93                 :          1 :     convert["SLUG*FT2"]["KG*M2"] = 1.35594;
      94                 :          1 :     convert["KG*M2"]["SLUG*FT2"] = 1.0/convert["SLUG*FT2"]["KG*M2"];
      95                 :            :     // Angles
      96                 :          1 :     convert["RAD"]["DEG"] = 360.0/(2.0*3.1415926);
      97                 :          1 :     convert["DEG"]["RAD"] = 1.0/convert["RAD"]["DEG"];
      98                 :            :     // Spring force
      99                 :          1 :     convert["LBS/FT"]["N/M"] = 14.5939;
     100                 :          1 :     convert["N/M"]["LBS/FT"] = 1.0/convert["LBS/FT"]["N/M"];
     101                 :            :     // Damping force
     102                 :          1 :     convert["LBS/FT/SEC"]["N/M/SEC"] = 14.5939;
     103                 :          1 :     convert["N/M/SEC"]["LBS/FT/SEC"] = 1.0/convert["LBS/FT/SEC"]["N/M/SEC"];
     104                 :            :     // Damping force (Square Law)
     105                 :          1 :     convert["LBS/FT2/SEC2"]["N/M2/SEC2"] = 47.880259;
     106                 :          1 :     convert["N/M2/SEC2"]["LBS/FT2/SEC2"] = 1.0/convert["LBS/FT2/SEC2"]["N/M2/SEC2"];
     107                 :            :     // Power
     108                 :          1 :     convert["WATTS"]["HP"] = 0.001341022;
     109                 :          1 :     convert["HP"]["WATTS"] = 1.0/convert["WATTS"]["HP"];
     110                 :            :     // Force
     111                 :          1 :     convert["N"]["LBS"] = 0.22482;
     112                 :          1 :     convert["LBS"]["N"] = 1.0/convert["N"]["LBS"];
     113                 :            :     // Velocity
     114                 :          1 :     convert["KTS"]["FT/SEC"] = 1.68781;
     115                 :          1 :     convert["FT/SEC"]["KTS"] = 1.0/convert["KTS"]["FT/SEC"];
     116                 :          1 :     convert["M/S"]["FT/S"] = 3.2808399;
     117                 :          1 :     convert["M/SEC"]["FT/SEC"] = 3.2808399;
     118                 :          1 :     convert["FT/S"]["M/S"] = 1.0/convert["M/S"]["FT/S"];
     119                 :          1 :     convert["M/SEC"]["FT/SEC"] = 3.2808399;
     120                 :          1 :     convert["FT/SEC"]["M/SEC"] = 1.0/convert["M/SEC"]["FT/SEC"];
     121                 :            :     // Torque
     122                 :          1 :     convert["FT*LBS"]["N*M"] = 1.35581795;
     123                 :          1 :     convert["N*M"]["FT*LBS"] = 1/convert["FT*LBS"]["N*M"];
     124                 :            :     // Valve
     125                 :            :     convert["M4*SEC/KG"]["FT4*SEC/SLUG"] = convert["M"]["FT"]*convert["M"]["FT"]*
     126                 :          1 :       convert["M"]["FT"]*convert["M"]["FT"]/convert["KG"]["SLUG"];
     127                 :            :     convert["FT4*SEC/SLUG"]["M4*SEC/KG"] =
     128                 :          1 :       1.0/convert["M4*SEC/KG"]["FT4*SEC/SLUG"];
     129                 :            :     // Pressure
     130                 :          1 :     convert["INHG"]["PSF"] = 70.7180803;
     131                 :          1 :     convert["PSF"]["INHG"] = 1.0/convert["INHG"]["PSF"];
     132                 :          1 :     convert["ATM"]["INHG"] = 29.9246899;
     133                 :          1 :     convert["INHG"]["ATM"] = 1.0/convert["ATM"]["INHG"];
     134                 :          1 :     convert["PSI"]["INHG"] = 2.03625437;
     135                 :          1 :     convert["INHG"]["PSI"] = 1.0/convert["PSI"]["INHG"];
     136                 :          1 :     convert["INHG"]["PA"] = 3386.0; // inches Mercury to pascals
     137                 :          1 :     convert["PA"]["INHG"] = 1.0/convert["INHG"]["PA"];
     138                 :          1 :     convert["LBS/FT2"]["N/M2"] = 14.5939/convert["FT"]["M"];
     139                 :          1 :     convert["N/M2"]["LBS/FT2"] = 1.0/convert["LBS/FT2"]["N/M2"];
     140                 :          1 :     convert["LBS/FT2"]["PA"] = convert["LBS/FT2"]["N/M2"];
     141                 :          1 :     convert["PA"]["LBS/FT2"] = 1.0/convert["LBS/FT2"]["PA"];
     142                 :            :     // Mass flow
     143                 :          1 :     convert["KG/MIN"]["LBS/MIN"] = convert["KG"]["LBS"];
     144                 :            :     // Fuel Consumption
     145                 :          1 :     convert["LBS/HP*HR"]["KG/KW*HR"] = 0.6083;
     146                 :          1 :     convert["KG/KW*HR"]["LBS/HP*HR"] = 1.0/convert["LBS/HP*HR"]["KG/KW*HR"];
     147                 :            :     // Density
     148                 :          1 :     convert["KG/L"]["LBS/GAL"] = 8.3454045;
     149                 :          1 :     convert["LBS/GAL"]["KG/L"] = 1.0/convert["KG/L"]["LBS/GAL"];
     150                 :            : 
     151                 :            :     // Length
     152                 :          1 :     convert["M"]["M"] = 1.00;
     153                 :          1 :     convert["FT"]["FT"] = 1.00;
     154                 :          1 :     convert["IN"]["IN"] = 1.00;
     155                 :            :     // Area
     156                 :          1 :     convert["M2"]["M2"] = 1.00;
     157                 :          1 :     convert["FT2"]["FT2"] = 1.00;
     158                 :            :     // Volume
     159                 :          1 :     convert["IN3"]["IN3"] = 1.00;
     160                 :          1 :     convert["CC"]["CC"] = 1.0;
     161                 :          1 :     convert["M3"]["M3"] = 1.0;
     162                 :          1 :     convert["FT3"]["FT3"] = 1.0;
     163                 :          1 :     convert["LTR"]["LTR"] = 1.0;
     164                 :            :     // Mass & Weight
     165                 :          1 :     convert["KG"]["KG"] = 1.00;
     166                 :          1 :     convert["LBS"]["LBS"] = 1.00;
     167                 :            :     // Moments of Inertia
     168                 :          1 :     convert["KG*M2"]["KG*M2"] = 1.00;
     169                 :          1 :     convert["SLUG*FT2"]["SLUG*FT2"] = 1.00;
     170                 :            :     // Angles
     171                 :          1 :     convert["DEG"]["DEG"] = 1.00;
     172                 :          1 :     convert["RAD"]["RAD"] = 1.00;
     173                 :            :     // Spring force
     174                 :          1 :     convert["LBS/FT"]["LBS/FT"] = 1.00;
     175                 :          1 :     convert["N/M"]["N/M"] = 1.00;
     176                 :            :     // Damping force
     177                 :          1 :     convert["LBS/FT/SEC"]["LBS/FT/SEC"] = 1.00;
     178                 :          1 :     convert["N/M/SEC"]["N/M/SEC"] = 1.00;
     179                 :            :     // Damping force (Square law)
     180                 :          1 :     convert["LBS/FT2/SEC2"]["LBS/FT2/SEC2"] = 1.00;
     181                 :          1 :     convert["N/M2/SEC2"]["N/M2/SEC2"] = 1.00;
     182                 :            :     // Power
     183                 :          1 :     convert["HP"]["HP"] = 1.00;
     184                 :          1 :     convert["WATTS"]["WATTS"] = 1.00;
     185                 :            :     // Force
     186                 :          1 :     convert["N"]["N"] = 1.00;
     187                 :            :     // Velocity
     188                 :          1 :     convert["FT/SEC"]["FT/SEC"] = 1.00;
     189                 :          1 :     convert["KTS"]["KTS"] = 1.00;
     190                 :          1 :     convert["M/S"]["M/S"] = 1.0;
     191                 :          1 :     convert["M/SEC"]["M/SEC"] = 1.0;
     192                 :            :     // Torque
     193                 :          1 :     convert["FT*LBS"]["FT*LBS"] = 1.00;
     194                 :          1 :     convert["N*M"]["N*M"] = 1.00;
     195                 :            :     // Valve
     196                 :          1 :     convert["M4*SEC/KG"]["M4*SEC/KG"] = 1.0;
     197                 :          1 :     convert["FT4*SEC/SLUG"]["FT4*SEC/SLUG"] = 1.0;
     198                 :            :     // Pressure
     199                 :          1 :     convert["PSI"]["PSI"] = 1.00;
     200                 :          1 :     convert["PSF"]["PSF"] = 1.00;
     201                 :          1 :     convert["INHG"]["INHG"] = 1.00;
     202                 :          1 :     convert["ATM"]["ATM"] = 1.0;
     203                 :          1 :     convert["PA"]["PA"] = 1.0;
     204                 :          1 :     convert["N/M2"]["N/M2"] = 1.00;
     205                 :          1 :     convert["LBS/FT2"]["LBS/FT2"] = 1.00;
     206                 :            :     // Mass flow
     207                 :          1 :     convert["LBS/SEC"]["LBS/SEC"] = 1.00;
     208                 :          1 :     convert["KG/MIN"]["KG/MIN"] = 1.0;
     209                 :          1 :     convert["LBS/MIN"]["LBS/MIN"] = 1.0;
     210                 :            :     // Fuel Consumption
     211                 :          1 :     convert["LBS/HP*HR"]["LBS/HP*HR"] = 1.0;
     212                 :          1 :     convert["KG/KW*HR"]["KG/KW*HR"] = 1.0;
     213                 :            :     // Density
     214                 :          1 :     convert["KG/L"]["KG/L"] = 1.0;
     215                 :          1 :     convert["LBS/GAL"]["LBS/GAL"] = 1.0;
     216                 :            :   }
     217                 :        930 : }
     218                 :            : 
     219                 :            : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     220                 :            : 
     221                 :        930 : Element::~Element(void)
     222                 :            : {
     223 [ +  - ][ +  + ]:       1829 :   for (unsigned int i=0; i<children.size(); i++) delete children[i];
         [ #  # ][ #  # ]
     224                 :        930 :   data_lines.clear();
     225                 :        930 :   attributes.clear();
     226                 :        930 :   attribute_key.clear();
     227                 :        930 : }
     228                 :            : 
     229                 :            : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     230                 :            : 
     231                 :        698 : string Element::GetAttributeValue(const string& attr)
     232                 :            : {
     233                 :        698 :   int select=-1;
     234         [ +  + ]:       1639 :   for (unsigned int i=0; i<attribute_key.size(); i++) {
     235         [ +  + ]:        941 :     if (attribute_key[i] == attr) select = i;
     236                 :            :   }
     237         [ +  + ]:        698 :   if (select < 0) return string("");
     238                 :        698 :   else return attributes[attr];
     239                 :            : }
     240                 :            : 
     241                 :            : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     242                 :            : 
     243                 :         40 : double Element::GetAttributeValueAsNumber(const string& attr)
     244                 :            : {
     245                 :         40 :   string attribute = GetAttributeValue(attr);
     246                 :            : 
     247         [ +  + ]:         40 :   if (attribute.empty()) return HUGE_VAL;
     248                 :         40 :   else return (atof(attribute.c_str()));
     249                 :            : }
     250                 :            : 
     251                 :            : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     252                 :            : 
     253                 :         94 : Element* Element::GetElement(unsigned int el)
     254                 :            : {
     255         [ +  + ]:         94 :   if (children.size() > el) {
     256                 :         62 :     element_index = el;
     257                 :         62 :     return children[el];
     258                 :            :   }
     259                 :            :   else {
     260                 :         32 :     element_index = 0;
     261                 :         94 :     return 0L;
     262                 :            :   }
     263                 :            : }
     264                 :            : 
     265                 :            : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     266                 :            : 
     267                 :        148 : Element* Element::GetNextElement(void)
     268                 :            : {
     269         [ +  + ]:        148 :   if (children.size() > element_index+1) {
     270                 :         86 :     element_index++;
     271                 :         86 :     return children[element_index];
     272                 :            :   } else {
     273                 :         62 :     element_index = 0;
     274                 :        148 :     return 0L;
     275                 :            :   }
     276                 :            : }
     277                 :            : 
     278                 :            : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     279                 :            : 
     280                 :        534 : string Element::GetDataLine(unsigned int i)
     281                 :            : {
     282         [ +  - ]:        534 :   if (data_lines.size() > 0) return data_lines[i];
     283                 :          0 :   else return string("");
     284                 :            : }
     285                 :            : 
     286                 :            : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     287                 :            : 
     288                 :        415 : double Element::GetDataAsNumber(void)
     289                 :            : {
     290         [ +  - ]:        415 :   if (data_lines.size() == 1) {
     291                 :        415 :     return atof(data_lines[0].c_str());
     292         [ #  # ]:          0 :   } else if (data_lines.size() == 0) {
     293                 :          0 :     return HUGE_VAL;
     294                 :            :   } else {
     295                 :          0 :     cerr << "Attempting to get single data value from multiple lines in element " << name << endl;
     296                 :        415 :     return HUGE_VAL;
     297                 :            :   }
     298                 :            : }
     299                 :            : 
     300                 :            : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     301                 :            : 
     302                 :          2 : unsigned int Element::GetNumElements(const string& element_name)
     303                 :            : {
     304                 :          2 :   unsigned int number_of_elements=0;
     305                 :          2 :   Element* el=FindElement(element_name);
     306         [ +  + ]:          4 :   while (el) {
     307                 :          2 :     number_of_elements++;
     308                 :          2 :     el=FindNextElement(element_name);
     309                 :            :   }
     310                 :          2 :   return number_of_elements;
     311                 :            : }
     312                 :            : 
     313                 :            : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     314                 :            : 
     315                 :       1249 : Element* Element::FindElement(const string& el)
     316                 :            : {
     317 [ -  + ][ #  # ]:       1249 :   if (el.empty() && children.size() >= 1) {
                 [ -  + ]
     318                 :          0 :     element_index = 1;
     319                 :          0 :     return children[0];
     320                 :            :   }
     321         [ +  + ]:       4193 :   for (unsigned int i=0; i<children.size(); i++) {
     322         [ +  + ]:       3814 :     if (el == children[i]->GetName()) {
     323                 :        870 :       element_index = i+1;
     324                 :        870 :       return children[i];
     325                 :            :     }
     326                 :            :   }
     327                 :        379 :   element_index = 0;
     328                 :       1249 :   return 0L;
     329                 :            : }
     330                 :            : 
     331                 :            : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     332                 :            : 
     333                 :        213 : Element* Element::FindNextElement(const string& el)
     334                 :            : {
     335         [ -  + ]:        213 :   if (el.empty()) {
     336         [ #  # ]:          0 :     if (element_index < children.size()) {
     337                 :          0 :       return children[element_index++];
     338                 :            :     } else {
     339                 :          0 :       element_index = 0;
     340                 :          0 :       return 0L;
     341                 :            :     }
     342                 :            :   }
     343         [ +  + ]:        347 :   for (unsigned int i=element_index; i<children.size(); i++) {
     344         [ +  + ]:        265 :     if (el == children[i]->GetName()) {
     345                 :        131 :       element_index = i+1;
     346                 :        131 :       return children[i];
     347                 :            :     }
     348                 :            :   }
     349                 :         82 :   element_index = 0;
     350                 :        213 :   return 0L;
     351                 :            : }
     352                 :            : 
     353                 :            : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     354                 :            : 
     355                 :         95 : double Element::FindElementValueAsNumber(const string& el)
     356                 :            : {
     357                 :         95 :   Element* element = FindElement(el);
     358         [ +  - ]:         95 :   if (element) {
     359                 :         95 :     return element->GetDataAsNumber();
     360                 :            :   } else {
     361                 :          0 :     cerr << "Attempting to get single data value from multiple lines" << endl;
     362                 :         95 :     return 0;
     363                 :            :   }
     364                 :            : }
     365                 :            : 
     366                 :            : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     367                 :            : 
     368                 :         61 : string Element::FindElementValue(const string& el)
     369                 :            : {
     370                 :         61 :   Element* element = FindElement(el);
     371         [ +  - ]:         61 :   if (element) {
     372                 :         61 :     return element->GetDataLine();
     373                 :            :   } else {
     374                 :          0 :     return "";
     375                 :            :   }
     376                 :            : }
     377                 :            : 
     378                 :            : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     379                 :            : 
     380                 :        119 : double Element::FindElementValueAsNumberConvertTo(const string& el, const string& target_units)
     381                 :            : {
     382                 :        119 :   Element* element = FindElement(el);
     383                 :            : 
     384         [ -  + ]:        119 :   if (!element) {
     385                 :          0 :     cerr << "Attempting to get non-existent element " << el << endl;
     386                 :          0 :     exit(0);
     387                 :            :   }
     388                 :            : 
     389                 :        119 :   string supplied_units = element->GetAttributeValue("unit");
     390                 :            : 
     391         [ +  - ]:        119 :   if (!supplied_units.empty()) {
     392         [ -  + ]:        119 :     if (convert.find(supplied_units) == convert.end()) {
     393                 :            :       cerr << endl << "Supplied unit: \"" << supplied_units << "\" does not exist (typo?). Add new unit"
     394                 :          0 :            << " conversion in FGXMLElement.cpp." << endl;
     395                 :          0 :       exit(-1);
     396                 :            :     }
     397         [ -  + ]:        119 :     if (convert[supplied_units].find(target_units) == convert[supplied_units].end()) {
     398                 :            :       cerr << endl << "Supplied unit: \"" << supplied_units << "\" cannot be converted to "
     399                 :          0 :                    << target_units << ". Add new unit conversion in FGXMLElement.cpp or fix typo" << endl;
     400                 :          0 :       exit(-1);
     401                 :            :     }
     402                 :            :   }
     403                 :            : 
     404                 :        119 :   double value = element->GetDataAsNumber();
     405         [ +  - ]:        119 :   if (!supplied_units.empty()) {
     406                 :        119 :     value *= convert[supplied_units][target_units];
     407                 :            :   }
     408                 :            : 
     409                 :        119 :   return value;
     410                 :            : }
     411                 :            : 
     412                 :            : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     413                 :            : 
     414                 :            : double Element::FindElementValueAsNumberConvertFromTo( const string& el,
     415                 :            :                                                        const string& supplied_units,
     416                 :          0 :                                                        const string& target_units)
     417                 :            : {
     418                 :          0 :   Element* element = FindElement(el);
     419                 :            : 
     420         [ #  # ]:          0 :   if (!element) {
     421                 :          0 :     cerr << "Attempting to get non-existent element " << el << endl;
     422                 :          0 :     exit(0);
     423                 :            :   }
     424                 :            : 
     425         [ #  # ]:          0 :   if (!supplied_units.empty()) {
     426         [ #  # ]:          0 :     if (convert.find(supplied_units) == convert.end()) {
     427                 :            :       cerr << endl << "Supplied unit: \"" << supplied_units << "\" does not exist (typo?). Add new unit"
     428                 :          0 :            << " conversion in FGXMLElement.cpp." << endl;
     429                 :          0 :       exit(-1);
     430                 :            :     }
     431         [ #  # ]:          0 :     if (convert[supplied_units].find(target_units) == convert[supplied_units].end()) {
     432                 :            :       cerr << endl << "Supplied unit: \"" << supplied_units << "\" cannot be converted to "
     433                 :          0 :                    << target_units << ". Add new unit conversion in FGXMLElement.cpp or fix typo" << endl;
     434                 :          0 :       exit(-1);
     435                 :            :     }
     436                 :            :   }
     437                 :            : 
     438                 :          0 :   double value = element->GetDataAsNumber();
     439         [ #  # ]:          0 :   if (!supplied_units.empty()) {
     440                 :          0 :     value *= convert[supplied_units][target_units];
     441                 :            :   }
     442                 :            : 
     443                 :          0 :   return value;
     444                 :            : }
     445                 :            : 
     446                 :            : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     447                 :            : 
     448                 :         56 : FGColumnVector3 Element::FindElementTripletConvertTo( const string& target_units)
     449                 :            : {
     450                 :         56 :   FGColumnVector3 triplet;
     451                 :            :   Element* item;
     452                 :         56 :   double value=0.0;
     453                 :         56 :   string supplied_units = GetAttributeValue("unit");
     454                 :            : 
     455         [ +  - ]:         56 :   if (!supplied_units.empty()) {
     456         [ -  + ]:         56 :     if (convert.find(supplied_units) == convert.end()) {
     457                 :            :       cerr << endl << "Supplied unit: \"" << supplied_units << "\" does not exist (typo?). Add new unit"
     458                 :          0 :            << " conversion in FGXMLElement.cpp." << endl;
     459                 :          0 :       exit(-1);
     460                 :            :     }
     461         [ -  + ]:         56 :     if (convert[supplied_units].find(target_units) == convert[supplied_units].end()) {
     462                 :            :       cerr << endl << "Supplied unit: \"" << supplied_units << "\" cannot be converted to "
     463                 :          0 :                    << target_units << ". Add new unit conversion in FGXMLElement.cpp or fix typo" << endl;
     464                 :          0 :       exit(-1);
     465                 :            :     }
     466                 :            :   }
     467                 :            : 
     468                 :         56 :   item = FindElement("x");
     469         [ -  + ]:         56 :   if (!item) item = FindElement("roll");
     470         [ +  - ]:         56 :   if (item) {
     471                 :         56 :     value = item->GetDataAsNumber();
     472         [ +  - ]:         56 :     if (!supplied_units.empty()) value *= convert[supplied_units][target_units];
     473                 :            :   } else {
     474                 :          0 :     value = 0.0;
     475                 :          0 :     cerr << "Could not find an X triplet item for this column vector." << endl;
     476                 :            :   }
     477                 :        112 :   triplet(1) = value;
     478                 :            : 
     479                 :         56 :   item = FindElement("y");
     480         [ -  + ]:         56 :   if (!item) item = FindElement("pitch");
     481         [ +  - ]:         56 :   if (item) {
     482                 :         56 :     value = item->GetDataAsNumber();
     483         [ +  - ]:         56 :     if (!supplied_units.empty()) value *= convert[supplied_units][target_units];
     484                 :            :   } else {
     485                 :          0 :     value = 0.0;
     486                 :          0 :     cerr << "Could not find a Y triplet item for this column vector." << endl;
     487                 :            :   }
     488                 :        112 :   triplet(2) = value;
     489                 :            : 
     490                 :         56 :   item = FindElement("z");
     491         [ -  + ]:         56 :   if (!item) item = FindElement("yaw");
     492         [ +  - ]:         56 :   if (item) {
     493                 :         56 :     value = item->GetDataAsNumber();
     494         [ +  - ]:         56 :     if (!supplied_units.empty()) value *= convert[supplied_units][target_units];
     495                 :            :   } else {
     496                 :          0 :     value = 0.0;
     497                 :          0 :     cerr << "Could not find a Z triplet item for this column vector." << endl;
     498                 :            :   }
     499                 :        112 :   triplet(3) = value;
     500                 :            : 
     501                 :         56 :   return triplet;
     502                 :            : }
     503                 :            : 
     504                 :            : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     505                 :            : 
     506                 :          0 : void Element::Print(unsigned int level)
     507                 :            : {
     508                 :            :   unsigned int i, spaces;
     509                 :            : 
     510                 :          0 :   level+=2;
     511         [ #  # ]:          0 :   for (spaces=0; spaces<=level; spaces++) cout << " "; // format output
     512                 :          0 :   cout << "Element Name: " << name;
     513         [ #  # ]:          0 :   for (i=0; i<attributes.size(); i++) {
     514                 :          0 :     cout << "  " << attribute_key[i] << " = " << attributes[attribute_key[i]];
     515                 :            :   }
     516                 :            :   cout << endl;
     517         [ #  # ]:          0 :   for (i=0; i<data_lines.size(); i++) {
     518         [ #  # ]:          0 :     for (spaces=0; spaces<=level; spaces++) cout << " "; // format output
     519                 :          0 :     cout << data_lines[i] << endl;
     520                 :            :   }
     521         [ #  # ]:          0 :   for (i=0; i<children.size(); i++) {
     522                 :          0 :     children[i]->Print(level);
     523                 :            :   }
     524                 :          0 : }
     525                 :            : 
     526                 :            : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     527                 :            : 
     528                 :        513 : void Element::AddAttribute(const string& name, const string& value)
     529                 :            : {
     530                 :        513 :   attribute_key.push_back(name);
     531                 :        513 :   attributes[name] = value;
     532                 :        513 : }
     533                 :            : 
     534                 :            : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     535                 :            : 
     536                 :       1686 : void Element::AddData(string d)
     537                 :            : {
     538                 :       1686 :   string::size_type string_start = d.find_first_not_of(" \t");
     539         [ -  + ]:       1686 :   if (string_start != string::npos && string_start > 0) {
     540                 :          0 :     d.erase(0,string_start);
     541                 :            :   }
     542                 :       1686 :   data_lines.push_back(d);
     543                 :       1686 : }
     544                 :            : 
     545                 :            : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     546                 :            : 
     547 [ +  + ][ +  - ]:         12 : } // end namespace JSBSim

Generated by: LCOV version 1.9