int Dlg_AchievementsReporter::AddAchievementToListBox(const Achievement* pAch) { for (auto& i : repcol_arr) { // I'd suggest initilizing the achievement strings to a fixed capacity using reserve() instead auto col{ etoi(i) }; auto urows{ to_unsigned(ms_nNumOccupiedRows) }; switch (i) { case ReporterColumns::NumReporterColumns: _FALLTHROUGH; case ReporterColumns::Checked: ms_lbxData.at(urows).at(col) = ""; break; case ReporterColumns::Title: ms_lbxData.at(urows).at(col) = pAch->Title(); break; case ReporterColumns::Desc: ms_lbxData.at(urows).at(col) = pAch->Description(); break; case ReporterColumns::Author: ms_lbxData.at(urows).at(col) = pAch->Author(); break; case ReporterColumns::Achieved: ms_lbxData.at(urows).at(col) = !pAch->Active() ? "Yes" : "No"; break; default: throw std::out_of_range{ "Unknown col!" }; } } LV_ITEM item{ LVIF_TEXT, ms_nNumOccupiedRows, 0, 0_z, 0_z, nullptr, 256 }; for (size_t i = 0; i < num_rep_cols; ++i) { item.iSubItem = to_signed(i); // how did i miss this? tstring sStr = ms_lbxData.at(to_unsigned(ms_nNumOccupiedRows)).at(i); //Scoped cache item.pszText = sStr.data(); if (i == 0) item.iItem = ListView_InsertItem(m_hList, &item); else ListView_SetItem(m_hList, &item); } ASSERT(item.iItem == ms_nNumOccupiedRows); ms_nNumOccupiedRows++; // Last thing to do! return item.iItem; }
inline int list_geti(list_t lst, uint32 index) { return etoi(lst.data[index]); }