LCOV - code coverage report
Current view: top level - math - FGModelFunctions.cpp (source / functions) Hit Total Coverage
Test: JSBSim-Coverage-Statistics Lines: 47 52 90.4 %
Date: 2010-08-24 Functions: 9 10 90.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 29 54 53.7 %

           Branch data     Line data    Source code
       1                 :            : /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       2                 :            : 
       3                 :            :  Module:       FGModelFunctions.cpp
       4                 :            :  Author:       Jon S. Berndt
       5                 :            :  Date started: August 2010
       6                 :            : 
       7                 :            :  ------- Copyright (C) 2010  Jon S. Berndt (jon@jsbsim.org) ------------------
       8                 :            : 
       9                 :            :  This program is free software; you can redistribute it and/or modify it under
      10                 :            :  the terms of the GNU Lesser General Public License as published by the Free Software
      11                 :            :  Foundation; either version 2 of the License, or (at your option) any later
      12                 :            :  version.
      13                 :            : 
      14                 :            :  This program is distributed in the hope that it will be useful, but WITHOUT
      15                 :            :  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      16                 :            :  FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      17                 :            :  details.
      18                 :            : 
      19                 :            :  You should have received a copy of the GNU Lesser General Public License along with
      20                 :            :  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
      21                 :            :  Place - Suite 330, Boston, MA  02111-1307, USA.
      22                 :            : 
      23                 :            :  Further information about the GNU Lesser General Public License can also be found on
      24                 :            :  the world wide web at http://www.gnu.org.
      25                 :            : 
      26                 :            : FUNCTIONAL DESCRIPTION
      27                 :            : --------------------------------------------------------------------------------
      28                 :            : 
      29                 :            : HISTORY
      30                 :            : --------------------------------------------------------------------------------
      31                 :            : 
      32                 :            : %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      33                 :            : COMMENTS, REFERENCES,  and NOTES
      34                 :            : %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      35                 :            : 
      36                 :            : %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      37                 :            : INCLUDES
      38                 :            : %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
      39                 :            : 
      40                 :            : #include "FGModelFunctions.h"
      41                 :            : #include <string>
      42                 :            : 
      43                 :            : using namespace std;
      44                 :            : 
      45                 :            : namespace JSBSim {
      46                 :            : 
      47                 :            : static const char *IdSrc = "$Id: FGModelFunctions.cpp,v 1.2 2010/08/21 18:04:47 jberndt Exp $";
      48                 :            : static const char *IdHdr = ID_MODELFUNCTIONS;
      49                 :            : 
      50                 :            : /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      51                 :            : CLASS IMPLEMENTATION
      52                 :            : %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
      53                 :            : 
      54                 :         26 : FGModelFunctions::~FGModelFunctions()
      55                 :            : {
      56 [ #  # ][ +  + ]:         30 :   for (unsigned int i=0; i<interface_properties.size(); i++) delete interface_properties[i];
      57                 :         26 :   interface_properties.clear();
      58                 :            : 
      59 [ #  # ][ #  # ]:         26 :   for (unsigned int i=0; i<PreFunctions.size(); i++) delete PreFunctions[i];
         [ #  # ][ -  + ]
      60 [ #  # ][ #  # ]:         28 :   for (unsigned int i=0; i<PostFunctions.size(); i++) delete PostFunctions[i];
         [ +  - ][ +  + ]
      61                 :            : 
      62 [ #  # ][ -  + ]:         26 :   if (debug_lvl & 2) cout << "Destroyed:    FGModelFunctions" << endl;
      63                 :         26 : }
      64                 :            : 
      65                 :            : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      66                 :            : 
      67                 :         21 : bool FGModelFunctions::Load(Element* el, FGPropertyManager* PM, string prefix)
      68                 :            : {
      69                 :            :   // Interface properties are all stored in the interface properties array.
      70                 :         21 :   string interface_property_string = "";
      71                 :            : 
      72                 :         21 :   Element *property_element = el->FindElement("property");
      73 [ +  + ][ +  - ]:         21 :   if (property_element && debug_lvl > 0) cout << endl << "    Declared properties" 
      74                 :          2 :                                               << endl << endl;
      75         [ +  + ]:         25 :   while (property_element) {
      76                 :          8 :     interface_property_string = property_element->GetDataLine();
      77         [ -  + ]:          4 :     if (PM->HasNode(interface_property_string)) {
      78                 :            :       cerr << "      Property " << interface_property_string 
      79                 :          0 :            << " is already defined." << endl;
      80                 :            :     } else {
      81                 :          4 :       double value=0.0;
      82         [ +  + ]:          4 :       if ( ! property_element->GetAttributeValue("value").empty())
      83                 :          3 :         value = property_element->GetAttributeValueAsNumber("value");
      84                 :          4 :       interface_properties.push_back(new double(value));
      85                 :          4 :       PM->Tie(interface_property_string, interface_properties.back());
      86         [ +  - ]:          4 :       if (debug_lvl > 0)
      87                 :            :         cout << "      " << interface_property_string << " (initial value: " 
      88                 :          8 :              << value << ")" << endl << endl;
      89                 :            :     }
      90                 :          4 :     property_element = el->FindNextElement("property");
      91                 :            :   }
      92                 :            :   
      93                 :            :   // End of interface property loading logic
      94                 :            : 
      95                 :         21 :   PreLoad(el, PM, prefix);
      96                 :            : 
      97                 :         21 :   return true; // TODO: Need to make this value mean something.
      98                 :            : }
      99                 :            : 
     100                 :            : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     101                 :            : 
     102                 :         21 : void FGModelFunctions::PreLoad(Element* el, FGPropertyManager* PM, string prefix)
     103                 :            : {
     104                 :            :   // Load model post-functions, if any
     105                 :            : 
     106                 :         21 :   Element *function = el->FindElement("function");
     107                 :            : 
     108         [ +  + ]:         23 :   while (function) {
     109         [ -  + ]:          4 :     if (function->GetAttributeValue("type") == "pre") {
     110                 :          0 :       PreFunctions.push_back(new FGFunction(PM, function, prefix));
     111         [ -  + ]:          2 :     } else if (function->GetAttributeValue("type").empty()) { // Assume pre-function
     112                 :          0 :       string funcname = function->GetAttributeValue("name");
     113                 :          0 :       PreFunctions.push_back(new FGFunction(PM, function, prefix));
     114                 :            :     }
     115                 :          2 :     function = el->FindNextElement("function");
     116                 :            :   }
     117                 :         21 : }
     118                 :            : 
     119                 :            : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     120                 :            : 
     121                 :         17 : void FGModelFunctions::PostLoad(Element* el, FGPropertyManager* PM, string prefix)
     122                 :            : {
     123                 :            :   // Load model post-functions, if any
     124                 :            : 
     125                 :         17 :   Element *function = el->FindElement("function");
     126         [ +  + ]:         19 :   while (function) {
     127         [ +  - ]:          4 :     if (function->GetAttributeValue("type") == "post") {
     128                 :          2 :       PostFunctions.push_back(new FGFunction(PM, function, prefix));
     129                 :            :     }
     130                 :          2 :     function = el->FindNextElement("function");
     131                 :            :   }
     132                 :         17 : }
     133                 :            : 
     134                 :            : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     135                 :            : // Tell the Functions to cache values, so when the function values 
     136                 :            : // are being used in the model, the functions do not get
     137                 :            : // calculated each time, but instead use the values that have already
     138                 :            : // been calculated for this frame.
     139                 :            : 
     140                 :    1193023 : void FGModelFunctions::RunPreFunctions(void)
     141                 :            : {
     142                 :            :   vector <FGFunction*>::iterator it;
     143         [ -  + ]:    1193023 :   for (it = PreFunctions.begin(); it != PreFunctions.end(); it++)
     144                 :          0 :     (*it)->GetValue();
     145                 :    1193023 : }
     146                 :            : 
     147                 :            : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     148                 :            : // Tell the Functions to cache values, so when the function values 
     149                 :            : // are being used in the model, the functions do not get
     150                 :            : // calculated each time, but instead use the values that have already
     151                 :            : // been calculated for this frame.
     152                 :            : 
     153                 :    1193023 : void FGModelFunctions::RunPostFunctions(void)
     154                 :            : {
     155                 :            :   vector <FGFunction*>::iterator it;
     156         [ +  + ]:    1301033 :   for (it = PostFunctions.begin(); it != PostFunctions.end(); it++)
     157                 :     108010 :     (*it)->GetValue();
     158                 :    1193023 : }
     159                 :            : 
     160 [ +  + ][ +  - ]:         12 : }

Generated by: LCOV version 1.9