From 5a7c3ad1945c2829d03642b4526b9a066c73f06c Mon Sep 17 00:00:00 2001 From: archshift Date: Mon, 11 Aug 2014 17:44:59 -0700 Subject: Changed iterators to use auto, some of which using range-based loops --- src/citra_qt/hotkeys.cpp | 30 ++++++++++++------------- src/common/break_points.cpp | 55 +++++++++++++++++++++++---------------------- 2 files changed, 43 insertions(+), 42 deletions(-) diff --git a/src/citra_qt/hotkeys.cpp b/src/citra_qt/hotkeys.cpp index 1aa1e8b96..bbaa4a8dc 100644 --- a/src/citra_qt/hotkeys.cpp +++ b/src/citra_qt/hotkeys.cpp @@ -21,14 +21,14 @@ void SaveHotkeys(QSettings& settings) { settings.beginGroup("Shortcuts"); - for (HotkeyGroupMap::iterator group = hotkey_groups.begin(); group != hotkey_groups.end(); ++group) + for (auto group : hotkey_groups) { - settings.beginGroup(group->first); - for (HotkeyMap::iterator hotkey = group->second.begin(); hotkey != group->second.end(); ++hotkey) + settings.beginGroup(group.first); + for (auto hotkey : group.second) { - settings.beginGroup(hotkey->first); - settings.setValue(QString("KeySeq"), hotkey->second.keyseq.toString()); - settings.setValue(QString("Context"), hotkey->second.context); + settings.beginGroup(hotkey.first); + settings.setValue(QString("KeySeq"), hotkey.second.keyseq.toString()); + settings.setValue(QString("Context"), hotkey.second.context); settings.endGroup(); } settings.endGroup(); @@ -42,17 +42,17 @@ void LoadHotkeys(QSettings& settings) // Make sure NOT to use a reference here because it would become invalid once we call beginGroup() QStringList groups = settings.childGroups(); - for (QList::iterator group = groups.begin(); group != groups.end(); ++group) + for (auto group : groups) { - settings.beginGroup(*group); + settings.beginGroup(group); QStringList hotkeys = settings.childGroups(); - for (QList::iterator hotkey = hotkeys.begin(); hotkey != hotkeys.end(); ++hotkey) + for (auto hotkey : hotkeys) { - settings.beginGroup(*hotkey); + settings.beginGroup(hotkey); // RegisterHotkey assigns default keybindings, so use old values as default parameters - Hotkey& hk = hotkey_groups[*group][*hotkey]; + Hotkey& hk = hotkey_groups[group][hotkey]; hk.keyseq = QKeySequence::fromString(settings.value("KeySeq", hk.keyseq.toString()).toString()); hk.context = (Qt::ShortcutContext)settings.value("Context", hk.context).toInt(); if (hk.shortcut) @@ -91,13 +91,13 @@ GHotkeysDialog::GHotkeysDialog(QWidget* parent): QDialog(parent) { ui.setupUi(this); - for (HotkeyGroupMap::iterator group = hotkey_groups.begin(); group != hotkey_groups.end(); ++group) + for (auto group : hotkey_groups) { - QTreeWidgetItem* toplevel_item = new QTreeWidgetItem(QStringList(group->first)); - for (HotkeyMap::iterator hotkey = group->second.begin(); hotkey != group->second.end(); ++hotkey) + QTreeWidgetItem* toplevel_item = new QTreeWidgetItem(QStringList(group.first)); + for (auto hotkey : group.second) { QStringList columns; - columns << hotkey->first << hotkey->second.keyseq.toString(); + columns << hotkey.first << hotkey.second.keyseq.toString(); QTreeWidgetItem* item = new QTreeWidgetItem(columns); toplevel_item->addChild(item); } diff --git a/src/common/break_points.cpp b/src/common/break_points.cpp index 25d34a21a..4e04a06ff 100644 --- a/src/common/break_points.cpp +++ b/src/common/break_points.cpp @@ -11,16 +11,16 @@ bool BreakPoints::IsAddressBreakPoint(u32 _iAddress) { - for (TBreakPoints::iterator i = m_BreakPoints.begin(); i != m_BreakPoints.end(); ++i) - if (i->iAddress == _iAddress) + for (auto breakpoint : m_BreakPoints) + if (breakpoint.iAddress == _iAddress) return true; return false; } bool BreakPoints::IsTempBreakPoint(u32 _iAddress) { - for (TBreakPoints::iterator i = m_BreakPoints.begin(); i != m_BreakPoints.end(); ++i) - if (i->iAddress == _iAddress && i->bTemporary) + for (auto breakpoint : m_BreakPoints) + if (breakpoint.iAddress == _iAddress && breakpoint.bTemporary) return true; return false; } @@ -28,13 +28,12 @@ bool BreakPoints::IsTempBreakPoint(u32 _iAddress) BreakPoints::TBreakPointsStr BreakPoints::GetStrings() const { TBreakPointsStr bps; - for (TBreakPoints::const_iterator i = m_BreakPoints.begin(); - i != m_BreakPoints.end(); ++i) + for (auto breakpoint : m_BreakPoints) { - if (!i->bTemporary) + if (!breakpoint.bTemporary) { std::stringstream bp; - bp << std::hex << i->iAddress << " " << (i->bOn ? "n" : ""); + bp << std::hex << breakpoint.iAddress << " " << (breakpoint.bOn ? "n" : ""); bps.push_back(bp.str()); } } @@ -44,13 +43,13 @@ BreakPoints::TBreakPointsStr BreakPoints::GetStrings() const void BreakPoints::AddFromStrings(const TBreakPointsStr& bps) { - for (TBreakPointsStr::const_iterator i = bps.begin(); i != bps.end(); ++i) + for (auto bps_item : bps) { TBreakPoint bp; std::stringstream bpstr; - bpstr << std::hex << *i; + bpstr << std::hex << bps_item; bpstr >> bp.iAddress; - bp.bOn = i->find("n") != i->npos; + bp.bOn = bps_item.find("n") != bps_item.npos; bp.bTemporary = false; Add(bp); } @@ -84,7 +83,7 @@ void BreakPoints::Add(u32 em_address, bool temp) void BreakPoints::Remove(u32 em_address) { - for (TBreakPoints::iterator i = m_BreakPoints.begin(); i != m_BreakPoints.end(); ++i) + for (auto i = m_BreakPoints.begin(); i != m_BreakPoints.end(); ++i) { if (i->iAddress == em_address) { @@ -114,14 +113,16 @@ void BreakPoints::Clear() MemChecks::TMemChecksStr MemChecks::GetStrings() const { TMemChecksStr mcs; - for (TMemChecks::const_iterator i = m_MemChecks.begin(); - i != m_MemChecks.end(); ++i) + for (auto memcheck : m_MemChecks) { std::stringstream mc; - mc << std::hex << i->StartAddress; - mc << " " << (i->bRange ? i->EndAddress : i->StartAddress) << " " << - (i->bRange ? "n" : "") << (i->OnRead ? "r" : "") << - (i->OnWrite ? "w" : "") << (i->Log ? "l" : "") << (i->Break ? "p" : ""); + mc << std::hex << memcheck.StartAddress; + mc << " " << (memcheck.bRange ? memcheck.EndAddress : memcheck.StartAddress) << " " + << (memcheck.bRange ? "n" : "") + << (memcheck.OnRead ? "r" : "") + << (memcheck.OnWrite ? "w" : "") + << (memcheck.Log ? "l" : "") + << (memcheck.Break ? "p" : ""); mcs.push_back(mc.str()); } @@ -130,17 +131,17 @@ MemChecks::TMemChecksStr MemChecks::GetStrings() const void MemChecks::AddFromStrings(const TMemChecksStr& mcs) { - for (TMemChecksStr::const_iterator i = mcs.begin(); i != mcs.end(); ++i) + for (auto mcs_item : mcs) { TMemCheck mc; std::stringstream mcstr; - mcstr << std::hex << *i; + mcstr << std::hex << mcs_item; mcstr >> mc.StartAddress; - mc.bRange = i->find("n") != i->npos; - mc.OnRead = i->find("r") != i->npos; - mc.OnWrite = i->find("w") != i->npos; - mc.Log = i->find("l") != i->npos; - mc.Break = i->find("p") != i->npos; + mc.bRange = mcs_item.find("n") != mcs_item.npos; + mc.OnRead = mcs_item.find("r") != mcs_item.npos; + mc.OnWrite = mcs_item.find("w") != mcs_item.npos; + mc.Log = mcs_item.find("l") != mcs_item.npos; + mc.Break = mcs_item.find("p") != mcs_item.npos; if (mc.bRange) mcstr >> mc.EndAddress; else @@ -157,7 +158,7 @@ void MemChecks::Add(const TMemCheck& _rMemoryCheck) void MemChecks::Remove(u32 _Address) { - for (TMemChecks::iterator i = m_MemChecks.begin(); i != m_MemChecks.end(); ++i) + for (auto i = m_MemChecks.begin(); i != m_MemChecks.end(); ++i) { if (i->StartAddress == _Address) { @@ -169,7 +170,7 @@ void MemChecks::Remove(u32 _Address) TMemCheck *MemChecks::GetMemCheck(u32 address) { - for (TMemChecks::iterator i = m_MemChecks.begin(); i != m_MemChecks.end(); ++i) + for (auto i = m_MemChecks.begin(); i != m_MemChecks.end(); ++i) { if (i->bRange) { -- cgit v1.2.3 From e3efc613fd84d62bdc370903c8bfef9743a9e593 Mon Sep 17 00:00:00 2001 From: archshift Date: Tue, 12 Aug 2014 03:44:12 -0700 Subject: break_points: cleaned up, added `find_if`s --- src/common/break_points.cpp | 62 ++++++++++++++++++++------------------------- src/common/break_points.h | 48 +++++++++++++++++------------------ 2 files changed, 51 insertions(+), 59 deletions(-) diff --git a/src/common/break_points.cpp b/src/common/break_points.cpp index 4e04a06ff..392b8530b 100644 --- a/src/common/break_points.cpp +++ b/src/common/break_points.cpp @@ -9,19 +9,21 @@ #include #include -bool BreakPoints::IsAddressBreakPoint(u32 _iAddress) +bool BreakPoints::IsAddressBreakPoint(u32 iAddress) { - for (auto breakpoint : m_BreakPoints) - if (breakpoint.iAddress == _iAddress) - return true; + auto cond = [&iAddress](const TBreakPoint& bp) { return bp.iAddress == iAddress; }; + auto it = std::find_if(m_BreakPoints.begin(), m_BreakPoints.end(), cond); + if (it != m_BreakPoints.end()) + return true; return false; } -bool BreakPoints::IsTempBreakPoint(u32 _iAddress) +bool BreakPoints::IsTempBreakPoint(u32 iAddress) { - for (auto breakpoint : m_BreakPoints) - if (breakpoint.iAddress == _iAddress && breakpoint.bTemporary) - return true; + auto cond = [&iAddress](const TBreakPoint& bp) { return bp.iAddress == iAddress && bp.bTemporary; }; + auto it = std::find_if(m_BreakPoints.begin(), m_BreakPoints.end(), cond); + if (it != m_BreakPoints.end()) + return true; return false; } @@ -83,16 +85,10 @@ void BreakPoints::Add(u32 em_address, bool temp) void BreakPoints::Remove(u32 em_address) { - for (auto i = m_BreakPoints.begin(); i != m_BreakPoints.end(); ++i) - { - if (i->iAddress == em_address) - { - m_BreakPoints.erase(i); - //if (jit) - // jit->GetBlockCache()->InvalidateICache(em_address, 4); - return; - } - } + auto cond = [&em_address](const TBreakPoint& bp) { return bp.iAddress == em_address; }; + auto it = std::find_if(m_BreakPoints.begin(), m_BreakPoints.end(), cond); + if (it != m_BreakPoints.end()) + m_BreakPoints.erase(it); } void BreakPoints::Clear() @@ -106,7 +102,7 @@ void BreakPoints::Clear() // } // ); //} - + m_BreakPoints.clear(); } @@ -118,10 +114,10 @@ MemChecks::TMemChecksStr MemChecks::GetStrings() const std::stringstream mc; mc << std::hex << memcheck.StartAddress; mc << " " << (memcheck.bRange ? memcheck.EndAddress : memcheck.StartAddress) << " " - << (memcheck.bRange ? "n" : "") - << (memcheck.OnRead ? "r" : "") - << (memcheck.OnWrite ? "w" : "") - << (memcheck.Log ? "l" : "") + << (memcheck.bRange ? "n" : "") + << (memcheck.OnRead ? "r" : "") + << (memcheck.OnWrite ? "w" : "") + << (memcheck.Log ? "l" : "") << (memcheck.Break ? "p" : ""); mcs.push_back(mc.str()); } @@ -150,22 +146,18 @@ void MemChecks::AddFromStrings(const TMemChecksStr& mcs) } } -void MemChecks::Add(const TMemCheck& _rMemoryCheck) +void MemChecks::Add(const TMemCheck& rMemoryCheck) { - if (GetMemCheck(_rMemoryCheck.StartAddress) == 0) - m_MemChecks.push_back(_rMemoryCheck); + if (GetMemCheck(rMemoryCheck.StartAddress) == 0) + m_MemChecks.push_back(rMemoryCheck); } -void MemChecks::Remove(u32 _Address) +void MemChecks::Remove(u32 Address) { - for (auto i = m_MemChecks.begin(); i != m_MemChecks.end(); ++i) - { - if (i->StartAddress == _Address) - { - m_MemChecks.erase(i); - return; - } - } + auto cond = [&Address](const TMemCheck& mc) { return mc.StartAddress == Address; }; + auto it = std::find_if(m_MemChecks.begin(), m_MemChecks.end(), cond); + if (it != m_MemChecks.end()) + m_MemChecks.erase(it); } TMemCheck *MemChecks::GetMemCheck(u32 address) diff --git a/src/common/break_points.h b/src/common/break_points.h index 46df34665..da14ca7f3 100644 --- a/src/common/break_points.h +++ b/src/common/break_points.h @@ -14,32 +14,33 @@ class DebugInterface; struct TBreakPoint { - u32 iAddress; - bool bOn; - bool bTemporary; + u32 iAddress; + bool bOn; + bool bTemporary; }; struct TMemCheck { - TMemCheck() { - numHits = 0; - StartAddress = EndAddress = 0; - bRange = OnRead = OnWrite = Log = Break = false; - } - u32 StartAddress; - u32 EndAddress; + TMemCheck(): + StartAddress(0), EndAddress(0), + bRange(false), OnRead(false), OnWrite(false), + Log(false), Break(false), numHits(0) + { } - bool bRange; + u32 StartAddress; + u32 EndAddress; - bool OnRead; - bool OnWrite; + bool bRange; - bool Log; - bool Break; + bool OnRead; + bool OnWrite; - u32 numHits; + bool Log; + bool Break; - void Action(DebugInterface *dbg_interface, u32 _iValue, u32 addr, + u32 numHits; + + void Action(DebugInterface *dbg_interface, u32 iValue, u32 addr, bool write, int size, u32 pc); }; @@ -56,22 +57,22 @@ public: void AddFromStrings(const TBreakPointsStr& bps); // is address breakpoint - bool IsAddressBreakPoint(u32 _iAddress); - bool IsTempBreakPoint(u32 _iAddress); + bool IsAddressBreakPoint(u32 iAddress); + bool IsTempBreakPoint(u32 iAddress); // Add BreakPoint void Add(u32 em_address, bool temp=false); void Add(const TBreakPoint& bp); // Remove Breakpoint - void Remove(u32 _iAddress); + void Remove(u32 iAddress); void Clear(); - void DeleteByAddress(u32 _Address); + void DeleteByAddress(u32 Address); private: TBreakPoints m_BreakPoints; - u32 m_iBreakOnCount; + u32 m_iBreakOnCount; }; @@ -89,7 +90,7 @@ public: TMemChecksStr GetStrings() const; void AddFromStrings(const TMemChecksStr& mcs); - void Add(const TMemCheck& _rMemoryCheck); + void Add(const TMemCheck& rMemoryCheck); // memory breakpoint TMemCheck *GetMemCheck(u32 address); @@ -99,4 +100,3 @@ public: }; #endif - -- cgit v1.2.3 From 1a2604902ff61e9be95cb19468d05a738b6d890f Mon Sep 17 00:00:00 2001 From: archshift Date: Tue, 12 Aug 2014 04:04:54 -0700 Subject: break_points.cpp: return directly from conditionals --- src/common/break_points.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/common/break_points.cpp b/src/common/break_points.cpp index 392b8530b..25528b864 100644 --- a/src/common/break_points.cpp +++ b/src/common/break_points.cpp @@ -13,18 +13,14 @@ bool BreakPoints::IsAddressBreakPoint(u32 iAddress) { auto cond = [&iAddress](const TBreakPoint& bp) { return bp.iAddress == iAddress; }; auto it = std::find_if(m_BreakPoints.begin(), m_BreakPoints.end(), cond); - if (it != m_BreakPoints.end()) - return true; - return false; + return it != m_BreakPoints.end(); } bool BreakPoints::IsTempBreakPoint(u32 iAddress) { auto cond = [&iAddress](const TBreakPoint& bp) { return bp.iAddress == iAddress && bp.bTemporary; }; auto it = std::find_if(m_BreakPoints.begin(), m_BreakPoints.end(), cond); - if (it != m_BreakPoints.end()) - return true; - return false; + return it != m_BreakPoints.end(); } BreakPoints::TBreakPointsStr BreakPoints::GetStrings() const -- cgit v1.2.3