Switch TaskGoalListManager::TaskGoalLists to std::vector

This commit is contained in:
Michael Cook (mackal)
2018-06-11 21:49:32 -04:00
parent 653824ae9e
commit 4fec8a2b75
2 changed files with 23 additions and 27 deletions
+7 -11
View File
@@ -3099,7 +3099,6 @@ void ClientTaskState::ProcessTaskProximities(Client *c, float X, float Y, float
TaskGoalListManager::TaskGoalListManager() { TaskGoalListManager::TaskGoalListManager() {
TaskGoalLists = nullptr;
NumberOfLists = 0; NumberOfLists = 0;
} }
@@ -3111,16 +3110,16 @@ TaskGoalListManager::~TaskGoalListManager() {
safe_delete_array(TaskGoalLists[i].GoalItemEntries); safe_delete_array(TaskGoalLists[i].GoalItemEntries);
} }
safe_delete_array(TaskGoalLists);
} }
bool TaskGoalListManager::LoadLists() { bool TaskGoalListManager::LoadLists()
{
Log(Logs::General, Logs::Tasks, "[GLOBALLOAD] TaskGoalListManager::LoadLists Called"); Log(Logs::General, Logs::Tasks, "[GLOBALLOAD] TaskGoalListManager::LoadLists Called");
for(int i=0; i< NumberOfLists; i++) for (int i = 0; i < NumberOfLists; i++)
safe_delete_array(TaskGoalLists[i].GoalItemEntries); safe_delete_array(TaskGoalLists[i].GoalItemEntries);
safe_delete_array(TaskGoalLists); TaskGoalLists.clear();
const char *ERR_MYSQLERROR = "Error in TaskGoalListManager::LoadLists: %s %s"; const char *ERR_MYSQLERROR = "Error in TaskGoalListManager::LoadLists: %s %s";
@@ -3137,18 +3136,15 @@ bool TaskGoalListManager::LoadLists() {
NumberOfLists = results.RowCount(); NumberOfLists = results.RowCount();
Log(Logs::General, Logs::Tasks, "[GLOBALLOAD] Database returned a count of %i lists", NumberOfLists); Log(Logs::General, Logs::Tasks, "[GLOBALLOAD] Database returned a count of %i lists", NumberOfLists);
TaskGoalLists = new TaskGoalList_Struct[NumberOfLists]; TaskGoalLists.reserve(NumberOfLists);
int listIndex = 0; int listIndex = 0;
for(auto row = results.begin(); row != results.end(); ++row) { for (auto row = results.begin(); row != results.end(); ++row) {
int listID = atoi(row[0]); int listID = atoi(row[0]);
int listSize = atoi(row[1]); int listSize = atoi(row[1]);
TaskGoalLists.push_back({listID, listSize, 0, 0, nullptr});
TaskGoalLists[listIndex].ListID = listID;
TaskGoalLists[listIndex].Size = listSize;
TaskGoalLists[listIndex].Min = 0;
TaskGoalLists[listIndex].Max = 0;
TaskGoalLists[listIndex].GoalItemEntries = new int[listSize]; TaskGoalLists[listIndex].GoalItemEntries = new int[listSize];
listIndex++; listIndex++;
+1 -1
View File
@@ -75,7 +75,7 @@ public:
private: private:
TaskGoalList_Struct *TaskGoalLists; std::vector<TaskGoalList_Struct> TaskGoalLists;
int NumberOfLists; int NumberOfLists;
}; };