From 21ee69846ad0edf1c08cddf635a8b6280dc07cf6 Mon Sep 17 00:00:00 2001 From: Theo Pannetier Date: Tue, 10 Sep 2024 11:45:51 +0100 Subject: [PATCH] trying out smart pointers --- src/BatchMode.cpp | 12 ++++++------ src/RScore/Cell.cpp | 9 +++++++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/BatchMode.cpp b/src/BatchMode.cpp index d99d76e..1d9a88a 100644 --- a/src/BatchMode.cpp +++ b/src/BatchMode.cpp @@ -4955,7 +4955,7 @@ void setUpSpeciesTrait(vector parameters) { const bool isOutput = parameters[14] == "TRUE"; // Create species trait - SpeciesTrait* trait = new SpeciesTrait( + unique_ptr trait(new SpeciesTrait( traitType, sex, positions, expressionType, initDist, initParams, @@ -4964,7 +4964,7 @@ void setUpSpeciesTrait(vector parameters) { mutationDistribution, mutationParameters, ploidy, isOutput - ); + )); pSpecies->addTrait(traitType, *trait); } @@ -6478,7 +6478,7 @@ void RunBatch(int nSimuls, int nLandscapes) bool params_ok; simParams sim = paramsSim->getSim(); - Landscape* pLandscape = NULL; // pointer to landscape + Landscape* pLandscape = nullptr; // pointer to landscape t0 = (int)time(0); @@ -6503,7 +6503,7 @@ void RunBatch(int nSimuls, int nLandscapes) for (int j = 0; j < nLandscapes; j++) { // create new landscape - if (pLandscape != NULL) delete pLandscape; + if (pLandscape != nullptr) delete pLandscape; pLandscape = new Landscape; bool landOK = true; @@ -6698,10 +6698,10 @@ void RunBatch(int nSimuls, int nLandscapes) ifsTraits.clear(); } - if (pLandscape != NULL) + if (pLandscape != nullptr) { delete pLandscape; - pLandscape = NULL; + pLandscape = nullptr; } } // end of landOK condition diff --git a/src/RScore/Cell.cpp b/src/RScore/Cell.cpp index 85fa78c..7f1e566 100644 --- a/src/RScore/Cell.cpp +++ b/src/RScore/Cell.cpp @@ -182,7 +182,9 @@ unsigned long int Cell::getVisits(void) { return visits; } // Initial species distribution cell functions DistCell::DistCell(int xx, int yy) { - x = xx; y = yy; initialise = false; + x = xx; + y = yy; + initialise = false; } DistCell::~DistCell() { @@ -201,7 +203,10 @@ bool DistCell::toInitialise(locn loc) { bool DistCell::selected(void) { return initialise; } locn DistCell::getLocn(void) { - locn loc; loc.x = x; loc.y = y; return loc; + locn loc; + loc.x = x; + loc.y = y; + return loc; } //---------------------------------------------------------------------------