GeckoCodeConfig: Return vector by value for LoadCodes()

Using an out-param is a leftover from C++03. Action Replay codes already
return the vector of codes by value as well.
This commit is contained in:
Lioncash 2017-03-21 16:24:16 -04:00
parent 9ea255c04d
commit f91292eff2
4 changed files with 11 additions and 12 deletions

View File

@ -13,14 +13,14 @@
namespace Gecko namespace Gecko
{ {
void LoadCodes(const IniFile& globalIni, const IniFile& localIni, std::vector<GeckoCode>& gcodes) std::vector<GeckoCode> LoadCodes(const IniFile& globalIni, const IniFile& localIni)
{ {
const IniFile* inis[2] = {&globalIni, &localIni}; std::vector<GeckoCode> gcodes;
for (const IniFile* ini : inis) for (const IniFile& ini : {globalIni, localIni})
{ {
std::vector<std::string> lines; std::vector<std::string> lines;
ini->GetLines("Gecko", &lines, false); ini.GetLines("Gecko", &lines, false);
GeckoCode gcode; GeckoCode gcode;
@ -42,7 +42,7 @@ void LoadCodes(const IniFile& globalIni, const IniFile& localIni, std::vector<Ge
gcodes.push_back(gcode); gcodes.push_back(gcode);
gcode = GeckoCode(); gcode = GeckoCode();
gcode.enabled = (1 == ss.tellg()); // silly gcode.enabled = (1 == ss.tellg()); // silly
gcode.user_defined = (ini == &localIni); gcode.user_defined = (&ini == &localIni);
ss.seekg(1, std::ios_base::cur); ss.seekg(1, std::ios_base::cur);
// read the code name // read the code name
std::getline(ss, gcode.name, '['); // stop at [ character (beginning of contributor name) std::getline(ss, gcode.name, '['); // stop at [ character (beginning of contributor name)
@ -75,7 +75,7 @@ void LoadCodes(const IniFile& globalIni, const IniFile& localIni, std::vector<Ge
gcodes.push_back(gcode); gcodes.push_back(gcode);
} }
ini->GetLines("Gecko_Enabled", &lines, false); ini.GetLines("Gecko_Enabled", &lines, false);
for (const std::string& line : lines) for (const std::string& line : lines)
{ {
@ -93,6 +93,8 @@ void LoadCodes(const IniFile& globalIni, const IniFile& localIni, std::vector<Ge
} }
} }
} }
return gcodes;
} }
// used by the SaveGeckoCodes function // used by the SaveGeckoCodes function

View File

@ -11,6 +11,6 @@ class IniFile;
namespace Gecko namespace Gecko
{ {
void LoadCodes(const IniFile& globalIni, const IniFile& localIni, std::vector<GeckoCode>& gcodes); std::vector<GeckoCode> LoadCodes(const IniFile& globalIni, const IniFile& localIni);
void SaveCodes(IniFile& inifile, const std::vector<GeckoCode>& gcodes); void SaveCodes(IniFile& inifile, const std::vector<GeckoCode>& gcodes);
} }

View File

@ -155,10 +155,7 @@ void LoadPatches()
LoadPatchSection("OnFrame", onFrame, globalIni, localIni); LoadPatchSection("OnFrame", onFrame, globalIni, localIni);
ActionReplay::LoadAndApplyCodes(globalIni, localIni); ActionReplay::LoadAndApplyCodes(globalIni, localIni);
// lil silly Gecko::SetActiveCodes(Gecko::LoadCodes(globalIni, localIni));
std::vector<Gecko::GeckoCode> gcodes;
Gecko::LoadCodes(globalIni, localIni, gcodes);
Gecko::SetActiveCodes(gcodes);
LoadSpeedhacks("Speedhacks", merged); LoadSpeedhacks("Speedhacks", merged);
} }

View File

@ -103,7 +103,7 @@ void CodeConfigPanel::LoadCodes(const IniFile& globalIni, const IniFile& localIn
m_gcodes.clear(); m_gcodes.clear();
if (!checkRunning || Core::IsRunning()) if (!checkRunning || Core::IsRunning())
Gecko::LoadCodes(globalIni, localIni, m_gcodes); m_gcodes = Gecko::LoadCodes(globalIni, localIni);
UpdateCodeList(checkRunning); UpdateCodeList(checkRunning);
} }