1
0
Fork 0

Codechange: Use std::unique_ptr for link graph schedule handlers.

This removes manual memory management.
pull/12988/head
Peter Nelson 2024-10-09 00:48:15 +01:00
parent 4a6ac52d8c
commit 4e57757c8f
No known key found for this signature in database
GPG Key ID: 8EF8F0A467DF75ED
2 changed files with 7 additions and 10 deletions

View File

@ -143,12 +143,12 @@ void LinkGraphSchedule::ShiftDates(TimerGameEconomy::Date interval)
*/ */
LinkGraphSchedule::LinkGraphSchedule() LinkGraphSchedule::LinkGraphSchedule()
{ {
this->handlers[0] = new InitHandler; this->handlers[0] = std::make_unique<InitHandler>();
this->handlers[1] = new DemandHandler; this->handlers[1] = std::make_unique<DemandHandler>();
this->handlers[2] = new MCFHandler<MCF1stPass>; this->handlers[2] = std::make_unique<MCFHandler<MCF1stPass>>();
this->handlers[3] = new FlowMapper(false); this->handlers[3] = std::make_unique<FlowMapper>(false);
this->handlers[4] = new MCFHandler<MCF2ndPass>; this->handlers[4] = std::make_unique<MCFHandler<MCF2ndPass>>();
this->handlers[5] = new FlowMapper(true); this->handlers[5] = std::make_unique<FlowMapper>(true);
} }
/** /**
@ -157,9 +157,6 @@ LinkGraphSchedule::LinkGraphSchedule()
LinkGraphSchedule::~LinkGraphSchedule() LinkGraphSchedule::~LinkGraphSchedule()
{ {
this->Clear(); this->Clear();
for (const auto &handler : this->handlers) {
delete handler;
}
} }
/** /**

View File

@ -42,7 +42,7 @@ private:
friend SaveLoadTable GetLinkGraphScheduleDesc(); friend SaveLoadTable GetLinkGraphScheduleDesc();
protected: protected:
ComponentHandler *handlers[6]; ///< Handlers to be run for each job. std::array<std::unique_ptr<ComponentHandler>, 6> handlers{}; ///< Handlers to be run for each job.
GraphList schedule; ///< Queue for new jobs. GraphList schedule; ///< Queue for new jobs.
JobList running; ///< Currently running jobs. JobList running; ///< Currently running jobs.