GameListCtrl: use unique_ptr for underlying game list items

This commit is contained in:
Lioncash 2016-09-30 03:13:12 -04:00
parent 74290e873a
commit 6e0e4646bd
2 changed files with 11 additions and 19 deletions

View File

@ -177,7 +177,6 @@ CGameListCtrl::CGameListCtrl(wxWindow* parent, const wxWindowID id, const wxPoin
CGameListCtrl::~CGameListCtrl() CGameListCtrl::~CGameListCtrl()
{ {
ClearIsoFiles();
} }
template <typename T> template <typename T>
@ -648,7 +647,7 @@ void CGameListCtrl::ScanForISOs()
} }
if (list) if (list)
m_ISOFiles.push_back(iso_file.release()); m_ISOFiles.push_back(std::move(iso_file));
} }
} }
} }
@ -662,7 +661,7 @@ void CGameListCtrl::ScanForISOs()
auto gli = std::make_unique<GameListItem>(drive, custom_title_map); auto gli = std::make_unique<GameListItem>(drive, custom_title_map);
if (gli->IsValid()) if (gli->IsValid())
m_ISOFiles.push_back(gli.release()); m_ISOFiles.push_back(std::move(gli));
} }
} }
@ -715,7 +714,7 @@ void CGameListCtrl::OnColBeginDrag(wxListEvent& event)
const GameListItem* CGameListCtrl::GetISO(size_t index) const const GameListItem* CGameListCtrl::GetISO(size_t index) const
{ {
if (index < m_ISOFiles.size()) if (index < m_ISOFiles.size())
return m_ISOFiles[index]; return m_ISOFiles[index].get();
else else
return nullptr; return nullptr;
} }
@ -850,10 +849,10 @@ void CGameListCtrl::OnMouseMotion(wxMouseEvent& event)
// Emulation status // Emulation status
static const char* const emuState[] = {"Broken", "Intro", "In-Game", "Playable", "Perfect"}; static const char* const emuState[] = {"Broken", "Intro", "In-Game", "Playable", "Perfect"};
const GameListItem& rISO = *m_ISOFiles[GetItemData(item)]; const GameListItem* iso = m_ISOFiles[GetItemData(item)].get();
const int emu_state = rISO.GetEmuState(); const int emu_state = iso->GetEmuState();
const std::string& issues = rISO.GetIssues(); const std::string& issues = iso->GetIssues();
// Show a tooltip containing the EmuState and the state description // Show a tooltip containing the EmuState and the state description
if (emu_state > 0 && emu_state < 6) if (emu_state > 0 && emu_state < 6)
@ -997,7 +996,7 @@ const GameListItem* CGameListCtrl::GetSelectedISO() const
long item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); long item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
if (item == wxNOT_FOUND) if (item == wxNOT_FOUND)
return nullptr; return nullptr;
return m_ISOFiles[GetItemData(item)]; return m_ISOFiles[GetItemData(item)].get();
} }
} }
@ -1010,7 +1009,7 @@ std::vector<const GameListItem*> CGameListCtrl::GetAllSelectedISOs() const
item = GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); item = GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
if (item == wxNOT_FOUND) if (item == wxNOT_FOUND)
return result; return result;
result.push_back(m_ISOFiles[GetItemData(item)]); result.push_back(m_ISOFiles[GetItemData(item)].get());
} }
} }

View File

@ -5,6 +5,7 @@
#pragma once #pragma once
#include <cstddef> #include <cstddef>
#include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
@ -65,17 +66,9 @@ private:
std::vector<int> m_FlagImageIndex; std::vector<int> m_FlagImageIndex;
std::vector<int> m_PlatformImageIndex; std::vector<int> m_PlatformImageIndex;
std::vector<int> m_EmuStateImageIndex; std::vector<int> m_EmuStateImageIndex;
std::vector<GameListItem*> m_ISOFiles; std::vector<std::unique_ptr<GameListItem>> m_ISOFiles;
void ClearIsoFiles()
{
while (!m_ISOFiles.empty()) // so lazy
{
delete m_ISOFiles.back();
m_ISOFiles.pop_back();
}
}
void ClearIsoFiles() { m_ISOFiles.clear(); }
int last_column; int last_column;
int last_sort; int last_sort;
wxSize lastpos; wxSize lastpos;