Merge pull request #34 from lioncash/geckocode-foreach
Change some for+iterator loops in GeckoCode.cpp and GeckoCodeConfig.cpp into foreach loops.
This commit is contained in:
commit
9a24ba343b
|
@ -7,24 +7,22 @@
|
||||||
#include "Thread.h"
|
#include "Thread.h"
|
||||||
#include "HW/Memmap.h"
|
#include "HW/Memmap.h"
|
||||||
#include "ConfigManager.h"
|
#include "ConfigManager.h"
|
||||||
|
|
||||||
#include "vector"
|
|
||||||
#include "PowerPC/PowerPC.h"
|
#include "PowerPC/PowerPC.h"
|
||||||
#include "CommonPaths.h"
|
#include "CommonPaths.h"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace Gecko
|
namespace Gecko
|
||||||
{
|
{
|
||||||
// return true if a code exists
|
// return true if a code exists
|
||||||
bool GeckoCode::Exist(u32 address, u32 data)
|
bool GeckoCode::Exist(u32 address, u32 data)
|
||||||
{
|
{
|
||||||
std::vector<GeckoCode::Code>::const_iterator
|
for (const GeckoCode::Code& code : codes)
|
||||||
codes_iter = codes.begin(),
|
|
||||||
codes_end = codes.end();
|
|
||||||
for (; codes_iter != codes_end; ++codes_iter)
|
|
||||||
{
|
{
|
||||||
if (codes_iter->address == address && codes_iter->data == data)
|
if (code.address == address && code.data == data)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,14 +33,13 @@ bool GeckoCode::Compare(GeckoCode compare) const
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
unsigned int exist = 0;
|
unsigned int exist = 0;
|
||||||
std::vector<GeckoCode::Code>::const_iterator
|
|
||||||
codes_iter = codes.begin(),
|
for (const GeckoCode::Code& code : codes)
|
||||||
codes_end = codes.end();
|
|
||||||
for (; codes_iter != codes_end; ++codes_iter)
|
|
||||||
{
|
{
|
||||||
if (compare.Exist(codes_iter->address, codes_iter->data))
|
if (compare.Exist(code.address, code.data))
|
||||||
exist++;
|
exist++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return exist == codes.size();
|
return exist == codes.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,17 +53,15 @@ void SetActiveCodes(const std::vector<GeckoCode>& gcodes)
|
||||||
std::lock_guard<std::mutex> lk(active_codes_lock);
|
std::lock_guard<std::mutex> lk(active_codes_lock);
|
||||||
|
|
||||||
active_codes.clear();
|
active_codes.clear();
|
||||||
|
|
||||||
// add enabled codes
|
// add enabled codes
|
||||||
std::vector<GeckoCode>::const_iterator
|
for (const GeckoCode& gecko_code : gcodes)
|
||||||
gcodes_iter = gcodes.begin(),
|
|
||||||
gcodes_end = gcodes.end();
|
|
||||||
for (; gcodes_iter!=gcodes_end; ++gcodes_iter)
|
|
||||||
{
|
{
|
||||||
if (gcodes_iter->enabled)
|
if (gecko_code.enabled)
|
||||||
{
|
{
|
||||||
// TODO: apply modifiers
|
// TODO: apply modifiers
|
||||||
// TODO: don't need description or creator string, just takin up memory
|
// TODO: don't need description or creator string, just takin up memory
|
||||||
active_codes.push_back(*gcodes_iter);
|
active_codes.push_back(gecko_code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,14 +96,12 @@ bool InstallCodeHandler()
|
||||||
std::lock_guard<std::mutex> lk(active_codes_lock);
|
std::lock_guard<std::mutex> lk(active_codes_lock);
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
std::vector<GeckoCode>::iterator
|
|
||||||
gcodes_iter = active_codes.begin(),
|
for (const GeckoCode& active_code : active_codes)
|
||||||
gcodes_end = active_codes.end();
|
|
||||||
for (; gcodes_iter!=gcodes_end; ++gcodes_iter)
|
|
||||||
{
|
{
|
||||||
if (gcodes_iter->enabled)
|
if (active_code.enabled)
|
||||||
{
|
{
|
||||||
for (auto& code : gcodes_iter->codes)
|
for (const GeckoCode::Code& code : active_code.codes)
|
||||||
{
|
{
|
||||||
// Make sure we have enough memory to hold the code list
|
// Make sure we have enough memory to hold the code list
|
||||||
if ((codelist_location + 24 + i) < 0x80003000)
|
if ((codelist_location + 24 + i) < 0x80003000)
|
||||||
|
|
|
@ -115,23 +115,17 @@ void SaveGeckoCode(std::vector<std::string>& lines, std::vector<std::string>& en
|
||||||
lines.push_back(name);
|
lines.push_back(name);
|
||||||
|
|
||||||
// save all the code lines
|
// save all the code lines
|
||||||
std::vector<GeckoCode::Code>::const_iterator
|
for (const GeckoCode::Code& code : gcode.codes)
|
||||||
codes_iter = gcode.codes.begin(),
|
|
||||||
codes_end = gcode.codes.end();
|
|
||||||
for (; codes_iter!=codes_end; ++codes_iter)
|
|
||||||
{
|
{
|
||||||
//ss << std::hex << codes_iter->address << ' ' << codes_iter->data;
|
//ss << std::hex << codes_iter->address << ' ' << codes_iter->data;
|
||||||
//lines.push_back(StringFromFormat("%08X %08X", codes_iter->address, codes_iter->data));
|
//lines.push_back(StringFromFormat("%08X %08X", codes_iter->address, codes_iter->data));
|
||||||
lines.push_back(codes_iter->original_line);
|
lines.push_back(code.original_line);
|
||||||
//ss.clear();
|
//ss.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// save the notes
|
// save the notes
|
||||||
std::vector<std::string>::const_iterator
|
for (const std::string& note : gcode.notes)
|
||||||
notes_iter = gcode.notes.begin(),
|
lines.push_back(std::string("*") + note);
|
||||||
notes_end = gcode.notes.end();
|
|
||||||
for (; notes_iter!=notes_end; ++notes_iter)
|
|
||||||
lines.push_back(std::string("*") + *notes_iter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveCodes(IniFile& inifile, const std::vector<GeckoCode>& gcodes)
|
void SaveCodes(IniFile& inifile, const std::vector<GeckoCode>& gcodes)
|
||||||
|
@ -139,12 +133,9 @@ void SaveCodes(IniFile& inifile, const std::vector<GeckoCode>& gcodes)
|
||||||
std::vector<std::string> lines;
|
std::vector<std::string> lines;
|
||||||
std::vector<std::string> enabledLines;
|
std::vector<std::string> enabledLines;
|
||||||
|
|
||||||
std::vector<GeckoCode>::const_iterator
|
for (const GeckoCode& geckoCode : gcodes)
|
||||||
gcodes_iter = gcodes.begin(),
|
|
||||||
gcodes_end = gcodes.end();
|
|
||||||
for (; gcodes_iter!=gcodes_end; ++gcodes_iter)
|
|
||||||
{
|
{
|
||||||
SaveGeckoCode(lines, enabledLines, *gcodes_iter);
|
SaveGeckoCode(lines, enabledLines, geckoCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
inifile.SetLines("Gecko", lines);
|
inifile.SetLines("Gecko", lines);
|
||||||
|
|
Loading…
Reference in New Issue