From baf2969cf18b4b136ce38fed17a16c98937026e9 Mon Sep 17 00:00:00 2001 From: keldorkatarn Date: Sun, 8 Apr 2018 15:07:23 +0200 Subject: [PATCH] Linkgraph: Refactoring to avoid manual deletes. --- src/linkgraph/linkgraphschedule.cpp | 15 ++++++--------- src/linkgraph/linkgraphschedule.h | 2 +- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/linkgraph/linkgraphschedule.cpp b/src/linkgraph/linkgraphschedule.cpp index d0494aac1..e3f92a8b2 100644 --- a/src/linkgraph/linkgraphschedule.cpp +++ b/src/linkgraph/linkgraphschedule.cpp @@ -205,12 +205,12 @@ void LinkGraphSchedule::ShiftDates(int interval) */ LinkGraphSchedule::LinkGraphSchedule() { - this->handlers[0] = new InitHandler; - this->handlers[1] = new DemandHandler; - this->handlers[2] = new MCFHandler; - this->handlers[3] = new FlowMapper(false); - this->handlers[4] = new MCFHandler; - this->handlers[5] = new FlowMapper(true); + this->handlers[0].reset(new InitHandler); + this->handlers[1].reset(new DemandHandler); + this->handlers[2].reset(new MCFHandler); + this->handlers[3].reset(new FlowMapper(false)); + this->handlers[4].reset(new MCFHandler); + this->handlers[5].reset(new FlowMapper(true)); } /** @@ -219,9 +219,6 @@ LinkGraphSchedule::LinkGraphSchedule() LinkGraphSchedule::~LinkGraphSchedule() { this->Clear(); - for (uint i = 0; i < lengthof(this->handlers); ++i) { - delete this->handlers[i]; - } } LinkGraphJobGroup::LinkGraphJobGroup(constructor_token token, std::vector jobs) : diff --git a/src/linkgraph/linkgraphschedule.h b/src/linkgraph/linkgraphschedule.h index 9e58e2798..c637cfa0c 100644 --- a/src/linkgraph/linkgraphschedule.h +++ b/src/linkgraph/linkgraphschedule.h @@ -46,7 +46,7 @@ private: friend const SaveLoad *GetLinkGraphScheduleDesc(); protected: - ComponentHandler *handlers[6]; ///< Handlers to be run for each job. + std::unique_ptr handlers[6]; ///< Handlers to be run for each job. GraphList schedule; ///< Queue for new jobs. JobList running; ///< Currently running jobs. -- 2.11.4.GIT