Skip to content

Commit a00129a

Browse files
committed
Removed destructors with std::unique_ptr<>
1 parent 0d0610b commit a00129a

4 files changed

Lines changed: 28 additions & 57 deletions

File tree

src/models/propulsion/FGTurbine.cpp

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ FGTurbine::FGTurbine(FGFDMExec* exec, Element *el, int engine_number, struct Inp
6363
Type = etTurbine;
6464

6565
MilThrust = MaxThrust = 10000.0;
66-
TSFC = new FGRealValue(0.8);
67-
ATSFC = new FGRealValue(1.7);
66+
TSFC = std::make_unique<FGRealValue>(0.8);
67+
ATSFC = std::make_unique<FGRealValue>(1.7);
6868
IdleN1 = 30.0;
6969
IdleN2 = 60.0;
7070
MaxN1 = MaxN2 = 100.0;
@@ -84,19 +84,8 @@ FGTurbine::FGTurbine(FGFDMExec* exec, Element *el, int engine_number, struct Inp
8484

8585
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8686

87-
FGTurbine::~FGTurbine()
88-
{
89-
delete TSFC;
90-
delete ATSFC;
91-
92-
Debug(1);
93-
}
94-
95-
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96-
9787
void FGTurbine::ResetToIC(void)
9888
{
99-
10089
FGEngine::ResetToIC();
10190

10291
N1 = N2 = InjN1increment = InjN2increment = 0.0;
@@ -497,22 +486,20 @@ bool FGTurbine::Load(FGFDMExec* exec, Element *el)
497486

498487
JSBSim::Element* tsfcElement = el->FindElement("tsfc");
499488
if (tsfcElement) {
500-
delete TSFC;
501489
string value = tsfcElement->GetDataLine();
502490
if (is_number(value))
503-
TSFC = new FGRealValue(atof(value.c_str()));
491+
TSFC = std::make_unique<FGRealValue>(atof(value.c_str()));
504492
else
505-
TSFC = new FGFunction(FDMExec, tsfcElement, to_string((int)EngineNumber));
493+
TSFC = std::make_unique<FGFunction>(FDMExec, tsfcElement, to_string((int)EngineNumber));
506494
}
507495

508496
JSBSim::Element* atsfcElement = el->FindElement("atsfc");
509497
if (atsfcElement) {
510-
delete ATSFC;
511498
string value = atsfcElement->GetDataLine();
512499
if (is_number(value))
513-
ATSFC = new FGRealValue(atof(value.c_str()));
500+
ATSFC = std::make_unique<FGRealValue>(atof(value.c_str()));
514501
else
515-
ATSFC = new FGFunction(FDMExec, atsfcElement, to_string((int)EngineNumber));
502+
ATSFC = std::make_unique<FGFunction>(FDMExec, atsfcElement, to_string((int)EngineNumber));
516503
}
517504

518505
// Pre-calculations and initializations
@@ -578,36 +565,36 @@ void FGTurbine::bindmodel(FGPropertyManager* PropertyManager)
578565
property_name = base_property_name + "/n2";
579566
PropertyManager->Tie( property_name.c_str(), &N2);
580567
property_name = base_property_name + "/injection_cmd";
581-
PropertyManager->Tie( property_name.c_str(), (FGTurbine*)this,
568+
PropertyManager->Tie( property_name.c_str(), this,
582569
&FGTurbine::GetInjection, &FGTurbine::SetInjection);
583570
property_name = base_property_name + "/seized";
584571
PropertyManager->Tie( property_name.c_str(), &Seized);
585572
property_name = base_property_name + "/stalled";
586573
PropertyManager->Tie( property_name.c_str(), &Stalled);
587574
property_name = base_property_name + "/bleed-factor";
588-
PropertyManager->Tie( property_name.c_str(), (FGTurbine*)this, &FGTurbine::GetBleedDemand, &FGTurbine::SetBleedDemand);
575+
PropertyManager->Tie( property_name.c_str(), this, &FGTurbine::GetBleedDemand, &FGTurbine::SetBleedDemand);
589576
property_name = base_property_name + "/MaxN1";
590-
PropertyManager->Tie( property_name.c_str(), (FGTurbine*)this,
577+
PropertyManager->Tie( property_name.c_str(), this,
591578
&FGTurbine::GetMaxN1, &FGTurbine::SetMaxN1);
592579
property_name = base_property_name + "/MaxN2";
593-
PropertyManager->Tie( property_name.c_str(), (FGTurbine*)this,
580+
PropertyManager->Tie( property_name.c_str(), this,
594581
&FGTurbine::GetMaxN2, &FGTurbine::SetMaxN2);
595582
property_name = base_property_name + "/InjectionTimer";
596-
PropertyManager->Tie( property_name.c_str(), (FGTurbine*)this,
583+
PropertyManager->Tie( property_name.c_str(), this,
597584
&FGTurbine::GetInjectionTimer, &FGTurbine::SetInjectionTimer);
598585
property_name = base_property_name + "/InjWaterNorm";
599-
PropertyManager->Tie( property_name.c_str(), (FGTurbine*)this,
586+
PropertyManager->Tie( property_name.c_str(), this,
600587
&FGTurbine::GetInjWaterNorm, &FGTurbine::SetInjWaterNorm);
601588
property_name = base_property_name + "/InjN1increment";
602-
PropertyManager->Tie( property_name.c_str(), (FGTurbine*)this,
589+
PropertyManager->Tie( property_name.c_str(), this,
603590
&FGTurbine::GetInjN1increment, &FGTurbine::SetInjN1increment);
604591
property_name = base_property_name + "/InjN2increment";
605-
PropertyManager->Tie( property_name.c_str(), (FGTurbine*)this,
592+
PropertyManager->Tie( property_name.c_str(), this,
606593
&FGTurbine::GetInjN2increment, &FGTurbine::SetInjN2increment);
607594
property_name = base_property_name + "/tsfc";
608-
PropertyManager->Tie(property_name.c_str(), (FGParameter*)TSFC, &FGParameter::GetValue);
595+
PropertyManager->Tie(property_name.c_str(), TSFC.get(), &FGParameter::GetValue);
609596
property_name = base_property_name + "/atsfc";
610-
PropertyManager->Tie(property_name.c_str(), (FGParameter*)ATSFC, &FGParameter::GetValue);
597+
PropertyManager->Tie(property_name.c_str(), ATSFC.get(), &FGParameter::GetValue);
611598
}
612599

613600
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -658,8 +645,8 @@ void FGTurbine::Debug(int from)
658645
cout << " MilThrust: " << MilThrust << endl;
659646
cout << " MaxThrust: " << MaxThrust << endl;
660647
cout << " BypassRatio: " << BypassRatio << endl;
661-
cout << " TSFC: " << TSFC << endl;
662-
cout << " ATSFC: " << ATSFC << endl;
648+
cout << " TSFC: " << TSFC->GetValue() << endl;
649+
cout << " ATSFC: " << ATSFC->GetValue() << endl;
663650
cout << " IdleN1: " << IdleN1 << endl;
664651
cout << " IdleN2: " << IdleN2 << endl;
665652
cout << " MaxN1: " << MaxN1 << endl;

src/models/propulsion/FGTurbine.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,6 @@ class FGTurbine : public FGEngine
178178
@param el pointer to the XML element representing the turbine engine
179179
@param engine_number engine number */
180180
FGTurbine(FGFDMExec* Executive, Element *el, int engine_number, struct Inputs& input);
181-
/// Destructor
182-
~FGTurbine();
183181

184182
enum phaseType { tpOff, tpRun, tpSpinUp, tpStart, tpStall, tpSeize, tpTrim };
185183

@@ -248,8 +246,8 @@ class FGTurbine : public FGEngine
248246
double MilThrust; ///< Maximum Unaugmented Thrust, static @ S.L. (lbf)
249247
double MaxThrust; ///< Maximum Augmented Thrust, static @ S.L. (lbf)
250248
double BypassRatio; ///< Bypass Ratio
251-
FGParameter* TSFC; ///< Thrust Specific Fuel Consumption (lbm/hr/lbf)
252-
FGParameter* ATSFC; ///< Augmented TSFC (lbm/hr/lbf)
249+
std::unique_ptr<FGParameter> TSFC; ///< Thrust Specific Fuel Consumption (lbm/hr/lbf)
250+
std::unique_ptr<FGParameter> ATSFC; ///< Augmented TSFC (lbm/hr/lbf)
253251
double IdleN1; ///< Idle N1
254252
double IdleN2; ///< Idle N2
255253
double IgnitionN1; ///< Ignition N1

src/models/propulsion/FGTurboProp.cpp

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ CLASS IMPLEMENTATION
6060
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
6161

6262
FGTurboProp::FGTurboProp(FGFDMExec* exec, Element *el, int engine_number, struct Inputs& input)
63-
: FGEngine(engine_number, input),
64-
ITT_N1(NULL), EnginePowerRPM_N1(NULL), EnginePowerVC(NULL),
65-
CombustionEfficiency_N1(NULL)
63+
: FGEngine(engine_number, input)
6664
{
6765
SetDefaults();
6866
Load(exec, el);
@@ -71,16 +69,6 @@ FGTurboProp::FGTurboProp(FGFDMExec* exec, Element *el, int engine_number, struct
7169

7270
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7371

74-
FGTurboProp::~FGTurboProp()
75-
{
76-
delete ITT_N1;
77-
delete EnginePowerRPM_N1;
78-
delete CombustionEfficiency_N1;
79-
Debug(1);
80-
}
81-
82-
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83-
8472
bool FGTurboProp::Load(FGFDMExec* exec, Element *el)
8573
{
8674
MaxStartingTime = 999999; //very big timeout -> infinite
@@ -153,11 +141,11 @@ bool FGTurboProp::Load(FGFDMExec* exec, Element *el)
153141
<<"Note: Using the EnginePowerVC without enclosed <function> tag is deprecated"
154142
<< endl;
155143
} else if (name == "EnginePowerRPM_N1") {
156-
EnginePowerRPM_N1 = new FGTable(PropertyManager, table_element);
144+
EnginePowerRPM_N1 = std::make_unique<FGTable>(PropertyManager, table_element);
157145
} else if (name == "ITT_N1") {
158-
ITT_N1 = new FGTable(PropertyManager, table_element);
146+
ITT_N1 = std::make_unique<FGTable>(PropertyManager, table_element);
159147
} else if (name == "CombustionEfficiency_N1") {
160-
CombustionEfficiency_N1 = new FGTable(PropertyManager, table_element);
148+
CombustionEfficiency_N1 = std::make_unique<FGTable>(PropertyManager, table_element);
161149
} else {
162150
cerr << el->ReadFrom() << "Unknown table type: " << name
163151
<< " in turboprop definition." << endl;
@@ -174,7 +162,7 @@ bool FGTurboProp::Load(FGFDMExec* exec, Element *el)
174162
// default table based on '9.333 - (N1)/12.0' approximation
175163
// gives 430%Fuel at 60%N1
176164
if (! CombustionEfficiency_N1) {
177-
CombustionEfficiency_N1 = new FGTable(6);
165+
CombustionEfficiency_N1 = std::make_unique<FGTable>(6);
178166
*CombustionEfficiency_N1 << 60.0 << 12.0/52.0;
179167
*CombustionEfficiency_N1 << 82.0 << 12.0/30.0;
180168
*CombustionEfficiency_N1 << 96.0 << 12.0/16.0;

src/models/propulsion/FGTurboProp.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ class FGTurboProp : public FGEngine
9797
@param el pointer to the XML element representing the turbine engine
9898
@param engine_number engine number*/
9999
FGTurboProp(FGFDMExec* Executive, Element *el, int engine_number, struct Inputs& input);
100-
/// Destructor
101-
~FGTurboProp();
102100

103101
enum phaseType { tpOff, tpRun, tpSpinUp, tpStart, tpTrim };
104102

@@ -191,10 +189,10 @@ class FGTurboProp : public FGEngine
191189
void bindmodel(FGPropertyManager* pm);
192190
void Debug(int from);
193191

194-
FGTable* ITT_N1; // ITT temperature depending on throttle command
195-
FGTable* EnginePowerRPM_N1;
192+
std::unique_ptr<FGTable> ITT_N1; // ITT temperature depending on throttle command
193+
std::unique_ptr<FGTable> EnginePowerRPM_N1;
196194
std::shared_ptr<FGParameter> EnginePowerVC;
197-
FGTable* CombustionEfficiency_N1;
195+
std::unique_ptr<FGTable> CombustionEfficiency_N1;
198196
};
199197
}
200198
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

0 commit comments

Comments
 (0)