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

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,48 +3110,45 @@ 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";
NumberOfLists = 0; NumberOfLists = 0;
std::string query = "SELECT `listid`, COUNT(`entry`) " std::string query = "SELECT `listid`, COUNT(`entry`) "
"FROM `goallists` GROUP by `listid` " "FROM `goallists` GROUP by `listid` "
"ORDER BY `listid`"; "ORDER BY `listid`";
auto results = database.QueryDatabase(query); auto results = database.QueryDatabase(query);
if (!results.Success()) { if (!results.Success()) {
return false; return false;
} }
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].GoalItemEntries = new int[listSize];
TaskGoalLists[listIndex].Size = listSize;
TaskGoalLists[listIndex].Min = 0;
TaskGoalLists[listIndex].Max = 0;
TaskGoalLists[listIndex].GoalItemEntries = new int[listSize];
listIndex++; listIndex++;
} }
for(int listIndex = 0; listIndex < NumberOfLists; listIndex++) { for(int listIndex = 0; listIndex < NumberOfLists; listIndex++) {

View File

@ -75,7 +75,7 @@ public:
private: private:
TaskGoalList_Struct *TaskGoalLists; std::vector<TaskGoalList_Struct> TaskGoalLists;
int NumberOfLists; int NumberOfLists;
}; };