Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove manual allocations for set of areas, simplify code #2588

Merged
merged 11 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions src/solver/variable/include/antares/solver/variable/setofareas.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ class SetsOfAreas
/*!
** \brief Default Constructor
*/
SetsOfAreas();
SetsOfAreas() = default;
//! Destructor
~SetsOfAreas();
~SetsOfAreas() = default;
//@}

void initializeFromStudy(Data::Study& study);
Expand Down Expand Up @@ -198,15 +198,11 @@ class SetsOfAreas

public:
//! Area list
typedef std::vector<NextType*> SetOfAreasVector;
typedef std::vector<std::unique_ptr<NextType>> SetOfAreasVector;
//! Area list
SetOfAreasVector pSetsOfAreas;
//! Reference to the origina set
std::vector<const Data::Sets::SetAreasType*> pOriginalSets;
//! An iterator for the begining of the list
typename SetOfAreasVector::iterator pBegin;
//! An iterator to the end of the list
typename SetOfAreasVector::iterator pEnd;
//! The study
const Data::Study* pStudy;

Expand Down
31 changes: 5 additions & 26 deletions src/solver/variable/include/antares/solver/variable/setofareas.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,6 @@ namespace Solver
{
namespace Variable
{
template<class NextT>
inline SetsOfAreas<NextT>::SetsOfAreas()
{
// Do nothing
}

template<class NextT>
inline SetsOfAreas<NextT>::~SetsOfAreas()
{
// Releasing the memory occupied by the areas
for (typename SetOfAreasVector::iterator i = pBegin; i != pEnd; ++i)
{
delete *i;
}
}

template<class NextT>
void SetsOfAreas<NextT>::initializeFromStudy(Data::Study& study)
{
Expand Down Expand Up @@ -74,8 +58,7 @@ void SetsOfAreas<NextT>::initializeFromStudy(Data::Study& study)
continue;
}

// Instancing a new set of variables of the area
NextType* n = new NextType();
auto n = std::make_unique<NextT>();

// Initialize the variables
// From the study
Expand All @@ -90,19 +73,15 @@ void SetsOfAreas<NextT>::initializeFromStudy(Data::Study& study)
// is variable's column(s) printed in output (set of areas) reports ?
n->getPrintStatusFromStudy(study);

// Adding the variables for the area in the list
pSetsOfAreas.push_back(n);
pSetsOfAreas.push_back(std::move(n));

auto* originalSet = &sets[setIndex];
assert(originalSet != NULL);
assert(!originalSet->empty());
pOriginalSets.push_back(originalSet);

pNames.push_back(setname);
}

// Initializing iterators
pBegin = pSetsOfAreas.begin();
pEnd = pSetsOfAreas.end();
}

template<class NextT>
Expand Down Expand Up @@ -255,12 +234,12 @@ void SetsOfAreas<NextT>::buildDigest(SurveyResults& results, int digestLevel, in
results.data.area = nullptr;
results.data.rowIndex = 0;

for (auto i = pBegin; i != pEnd; ++i)
for (auto& set: pSetsOfAreas)
{
results.data.columnIndex = 0;
results.data.rowCaptions[results.data.rowIndex].clear()
<< "@ " << pNames[results.data.rowIndex];
(*i)->buildDigest(results, digestLevel, dataLevel);
set->buildDigest(results, digestLevel, dataLevel);
++results.data.rowIndex;
}
}
Expand Down
Loading