]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/models/FGGasCell.cpp
Removed useless divisions - As a side effect, it removes the risk of divisions by...
[flightgear.git] / src / FDM / JSBSim / models / FGGasCell.cpp
index f876defd61f25f67a16b440bfa9db25bc7e18630..bdab7217237b3414a49d1a259eadb7844b9d2085 100644 (file)
@@ -35,20 +35,25 @@ HISTORY
 INCLUDES
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
-#include <FGFDMExec.h>
-#include <models/FGAuxiliary.h>
-#include <models/FGAtmosphere.h>
-#include <models/FGInertial.h>
-#include <models/FGMassBalance.h>
+#include "FGFDMExec.h"
+#include "models/FGAuxiliary.h"
+#include "models/FGAtmosphere.h"
+#include "models/FGInertial.h"
+#include "models/FGMassBalance.h"
 #include "FGGasCell.h"
+#include "input_output/FGXMLElement.h"
+#include <iostream>
+#include <cstdlib>
 
 using std::cerr;
 using std::endl;
 using std::cout;
+using std::string;
+using std::max;
 
 namespace JSBSim {
 
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGGasCell.cpp,v 1.13 2010/12/29 22:39:25 andgi Exp $";
 static const char *IdHdr = ID_GASCELL;
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -196,29 +201,25 @@ FGGasCell::FGGasCell(FGFDMExec* exec, Element* el, int num) : FGForce(exec)
   Mass = Contents * M_gas();
 
   // Bind relevant properties
-  char property_name[80];
-  snprintf(property_name, 80, "buoyant_forces/gas-cell[%d]/max_volume-ft3",
-           CellNum);
-  PropertyManager->Tie( property_name, &MaxVolume );
+  string property_name, base_property_name;
+
+  base_property_name = CreateIndexedPropertyName("buoyant_forces/gas-cell", CellNum);
+
+  property_name = base_property_name + "/max_volume-ft3";
+  PropertyManager->Tie( property_name.c_str(), &MaxVolume, false );
   PropertyManager->SetWritable( property_name, false );
-  snprintf(property_name, 80, "buoyant_forces/gas-cell[%d]/temp-R",
-           CellNum);
-  PropertyManager->Tie( property_name, &Temperature );
-  snprintf(property_name, 80, "buoyant_forces/gas-cell[%d]/pressure-psf",
-           CellNum);
-  PropertyManager->Tie( property_name, &Pressure );
-  snprintf(property_name, 80, "buoyant_forces/gas-cell[%d]/volume-ft3",
-           CellNum);
-  PropertyManager->Tie( property_name, &Volume );
-  snprintf(property_name, 80, "buoyant_forces/gas-cell[%d]/buoyancy-lbs",
-           CellNum);
-  PropertyManager->Tie( property_name, &Buoyancy );
-  snprintf(property_name, 80, "buoyant_forces/gas-cell[%d]/contents-mol",
-           CellNum);
-  PropertyManager->Tie( property_name, &Contents );
-  snprintf(property_name, 80, "buoyant_forces/gas-cell[%d]/valve_open",
-           CellNum);
-  PropertyManager->Tie( property_name, &ValveOpen );
+  property_name = base_property_name + "/temp-R";
+  PropertyManager->Tie( property_name.c_str(), &Temperature, false );
+  property_name = base_property_name + "/pressure-psf";
+  PropertyManager->Tie( property_name.c_str(), &Pressure, false );
+  property_name = base_property_name + "/volume-ft3";
+  PropertyManager->Tie( property_name.c_str(), &Volume, false );
+  property_name = base_property_name + "/buoyancy-lbs";
+  PropertyManager->Tie( property_name.c_str(), &Buoyancy, false );
+  property_name = base_property_name + "/contents-mol";
+  PropertyManager->Tie( property_name.c_str(), &Contents, false );
+  property_name = base_property_name + "/valve_open";
+  PropertyManager->Tie( property_name.c_str(), &ValveOpen, false );
 
   Debug(0);
 
@@ -640,38 +641,28 @@ FGBallonet::FGBallonet(FGFDMExec* exec, Element* el, int num, FGGasCell* parent)
   Volume = Contents * R * Temperature / Pressure;
 
   // Bind relevant properties
-  char property_name[80];
-  snprintf(property_name, 80,
-           "buoyant_forces/gas-cell[%d]/ballonet[%d]/max_volume-ft3",
-           Parent->GetIndex(),
-           CellNum);
-  PropertyManager->Tie( property_name, &MaxVolume );
+  string property_name, base_property_name;
+  base_property_name = CreateIndexedPropertyName("buoyant_forces/gas-cell", Parent->GetIndex());
+  base_property_name = CreateIndexedPropertyName(base_property_name + "/ballonet", CellNum);
+
+  property_name = base_property_name + "/max_volume-ft3";
+  PropertyManager->Tie( property_name, &MaxVolume, false );
   PropertyManager->SetWritable( property_name, false );
-  snprintf(property_name, 80,
-           "buoyant_forces/gas-cell[%d]/ballonet[%d]/temp-R",
-           Parent->GetIndex(),
-           CellNum);
-  PropertyManager->Tie( property_name, &Temperature );
-  snprintf(property_name, 80,
-           "buoyant_forces/gas-cell[%d]/ballonet[%d]/pressure-psf",
-           Parent->GetIndex(),
-           CellNum);
-  PropertyManager->Tie( property_name, &Pressure );
-  snprintf(property_name, 80,
-           "buoyant_forces/gas-cell[%d]/ballonet[%d]/volume-ft3",
-           Parent->GetIndex(),
-           CellNum);
-  PropertyManager->Tie( property_name, &Volume );
-  snprintf(property_name, 80,
-           "buoyant_forces/gas-cell[%d]/ballonet[%d]/contents-mol",
-           Parent->GetIndex(),
-           CellNum);
-  PropertyManager->Tie( property_name, &Contents );
-  snprintf(property_name, 80,
-           "buoyant_forces/gas-cell[%d]/ballonet[%d]/valve_open",
-           Parent->GetIndex(),
-           CellNum);
-  PropertyManager->Tie( property_name, &ValveOpen );
+
+  property_name = base_property_name + "/temp-R";
+  PropertyManager->Tie( property_name, &Temperature, false );
+
+  property_name = base_property_name + "/pressure-psf";
+  PropertyManager->Tie( property_name, &Pressure, false );
+
+  property_name = base_property_name + "/volume-ft3";
+  PropertyManager->Tie( property_name, &Volume, false );
+
+  property_name = base_property_name + "/contents-mol";
+  PropertyManager->Tie( property_name, &Contents, false );
+
+  property_name = base_property_name + "/valve_open";
+  PropertyManager->Tie( property_name, &ValveOpen, false );
 
   Debug(0);