diff --git a/src/cheat/Cheat.hxx b/src/cheat/Cheat.hxx index c8f03bd52..be584dc49 100644 --- a/src/cheat/Cheat.hxx +++ b/src/cheat/Cheat.hxx @@ -50,10 +50,8 @@ class Cheat static uInt16 unhex(const string& hex) { int ret = 0; - - for(unsigned int i = 0; i < hex.size(); ++i) { - char c = hex[i]; - + for(char c: hex) + { ret *= 16; if(c >= '0' && c <= '9') ret += c - '0'; diff --git a/src/cheat/CheatCodeDialog.cxx b/src/cheat/CheatCodeDialog.cxx index 8a7577721..ae27cf0c8 100644 --- a/src/cheat/CheatCodeDialog.cxx +++ b/src/cheat/CheatCodeDialog.cxx @@ -111,10 +111,10 @@ void CheatCodeDialog::loadConfig() BoolArray b; const CheatList& list = instance().cheat().list(); - for(unsigned int i = 0; i < list.size(); ++i) + for(const auto& c: list) { - l.push_back(list[i]->name()); - b.push_back(bool(list[i]->enabled())); + l.push_back(c->name()); + b.push_back(bool(c->enabled())); } myCheatList->setList(l, b); diff --git a/src/debugger/gui/PromptWidget.cxx b/src/debugger/gui/PromptWidget.cxx index b0ef57a51..aeed05038 100644 --- a/src/debugger/gui/PromptWidget.cxx +++ b/src/debugger/gui/PromptWidget.cxx @@ -892,9 +892,8 @@ string PromptWidget::getCompletionPrefix(const StringList& completions, string p // of the strings we're dealing with, it's probably not worth it for(;;) { - for(uInt32 i = 0; i < completions.size(); ++i) + for(const auto& s: completions) { - const string& s = completions[i]; if(s.length() < prefix.length()) return prefix; // current prefix is the best we're going to get else if(!BSPF_startsWithIgnoreCase(s, prefix)) diff --git a/src/emucore/Settings.cxx b/src/emucore/Settings.cxx index 72f08f4a1..70eea4926 100644 --- a/src/emucore/Settings.cxx +++ b/src/emucore/Settings.cxx @@ -504,9 +504,9 @@ void Settings::saveConfig() // Do a quick scan of the internal settings to see if any have // changed. If not, we don't need to save them at all. bool settingsChanged = false; - for(unsigned int i = 0; i < myInternalSettings.size(); ++i) + for(const auto& s: myInternalSettings) { - if(myInternalSettings[i].value != myInternalSettings[i].initialValue) + if(s.value != s.initialValue) { settingsChanged = true; break; @@ -539,11 +539,8 @@ void Settings::saveConfig() << ";" << endl; // Write out each of the key and value pairs - for(unsigned int i = 0; i < myInternalSettings.size(); ++i) - { - out << myInternalSettings[i].key << " = " << - myInternalSettings[i].value << endl; - } + for(const auto& s: myInternalSettings) + out << s.key << " = " << s.value << endl; out.close(); } diff --git a/src/gui/ComboDialog.cxx b/src/gui/ComboDialog.cxx index aaa215502..59da40e4f 100644 --- a/src/gui/ComboDialog.cxx +++ b/src/gui/ComboDialog.cxx @@ -59,8 +59,8 @@ ComboDialog::ComboDialog(GuiObject* boss, const GUI::Font& font, // Get maximum width of popupwidget int pwidth = 0; - for(uInt32 i = 0; i < combolist.size(); ++i) - pwidth = BSPF_max(font.getStringWidth(combolist[i].first), pwidth); + for(const auto& s: combolist) + pwidth = BSPF_max(font.getStringWidth(s.first), pwidth); // Label for dialog, indicating which combo is being changed myComboName = new StaticTextWidget(this, font, xpos, ypos, _w - xpos - 10, diff --git a/src/gui/ContextMenu.cxx b/src/gui/ContextMenu.cxx index 9f34227e4..6f7691d05 100644 --- a/src/gui/ContextMenu.cxx +++ b/src/gui/ContextMenu.cxx @@ -60,12 +60,8 @@ void ContextMenu::addItems(const VariantList& items) // Resize to largest string int maxwidth = 0; - for(unsigned int i = 0; i < _entries.size(); ++i) - { - int length = _font.getStringWidth(_entries[i].first); - if(length > maxwidth) - maxwidth = length; - } + for(const auto& e: _entries) + maxwidth = BSPF_max(maxwidth, _font.getStringWidth(e.first)); _x = _y = 0; _w = maxwidth + 10; diff --git a/src/gui/Dialog.cxx b/src/gui/Dialog.cxx index 6d0042cf6..dd0f243c1 100644 --- a/src/gui/Dialog.cxx +++ b/src/gui/Dialog.cxx @@ -145,8 +145,8 @@ void Dialog::addFocusWidget(Widget* w) void Dialog::addToFocusList(WidgetArray& list) { // All focusable widgets should retain focus - for(uInt32 i = 0; i < list.size(); ++i) - list[i]->setFlags(WIDGET_RETAIN_FOCUS); + for(const auto& w: list) + w->setFlags(WIDGET_RETAIN_FOCUS); Vec::append(_myFocus.list, list); _focusList = _myFocus.list; @@ -165,8 +165,8 @@ void Dialog::addToFocusList(WidgetArray& list, TabWidget* w, int tabId) assert(w == _myTabList[w->getID()].widget); // All focusable widgets should retain focus - for(uInt32 i = 0; i < list.size(); ++i) - list[i]->setFlags(WIDGET_RETAIN_FOCUS); + for(const auto& w: list) + w->setFlags(WIDGET_RETAIN_FOCUS); // First get the appropriate focus list FocusList& focus = _myTabList[w->getID()].focus; diff --git a/src/gui/FileListWidget.cxx b/src/gui/FileListWidget.cxx index e16c99382..85c1b9fdd 100644 --- a/src/gui/FileListWidget.cxx +++ b/src/gui/FileListWidget.cxx @@ -63,22 +63,22 @@ void FileListWidget::setLocation(const FilesystemNode& node, string select) _gameList.appendGame(" [..]", _node.getParent().getPath(), "", true); // Now add the directory entries - for(unsigned int idx = 0; idx < content.size(); idx++) + for(const auto& file: content) { - string name = content[idx].getName(); - bool isDir = content[idx].isDirectory(); + string name = file.getName(); + bool isDir = file.isDirectory(); if(isDir) name = " [" + name + "]"; else if(!BSPF_endsWithIgnoreCase(name, _extension)) continue; - _gameList.appendGame(name, content[idx].getPath(), "", isDir); + _gameList.appendGame(name, file.getPath(), "", isDir); } _gameList.sortByName(); // Now fill the list widget with the contents of the GameList StringList l; - for (int i = 0; i < (int) _gameList.size(); ++i) + for(int i = 0; i < (int) _gameList.size(); ++i) l.push_back(_gameList.name(i)); setList(l); diff --git a/src/gui/Font.cxx b/src/gui/Font.cxx index 1e2fdc908..7a6aa1d99 100644 --- a/src/gui/Font.cxx +++ b/src/gui/Font.cxx @@ -57,9 +57,8 @@ int Font::getStringWidth(const string& str) const else { int space = 0; - - for(unsigned int i = 0; i < str.size(); ++i) - space += getCharWidth(str[i]); + for(auto c: str) + space += getCharWidth(c); return space; } diff --git a/src/gui/GameList.cxx b/src/gui/GameList.cxx index ccd47a875..753a4697a 100644 --- a/src/gui/GameList.cxx +++ b/src/gui/GameList.cxx @@ -33,7 +33,6 @@ GameList::GameList() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - GameList::~GameList() { - clear(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/gui/LauncherDialog.cxx b/src/gui/LauncherDialog.cxx index 5a2d9c5d3..464568dbf 100644 --- a/src/gui/LauncherDialog.cxx +++ b/src/gui/LauncherDialog.cxx @@ -307,11 +307,10 @@ void LauncherDialog::loadDirListing() // Now add the directory entries bool domatch = myPattern && myPattern->getText() != ""; - for(unsigned int idx = 0; idx < files.size(); idx++) + for(const auto& f: files) { - bool isDir = files[idx].isDirectory(); - const string& name = isDir ? (" [" + files[idx].getName() + "]") - : files[idx].getName(); + bool isDir = f.isDirectory(); + const string& name = isDir ? (" [" + f.getName() + "]") : f.getName(); // Honour the filtering settings // Showing only certain ROM extensions is determined by the extension @@ -328,7 +327,7 @@ void LauncherDialog::loadDirListing() if(domatch && !isDir && !matchPattern(name, myPattern->getText())) continue; - myGameList->appendGame(name, files[idx].getPath(), "", isDir); + myGameList->appendGame(name, f.getPath(), "", isDir); } // Sort the list by rom name (since that's what we see in the listview) diff --git a/src/gui/LauncherFilterDialog.cxx b/src/gui/LauncherFilterDialog.cxx index 82809808e..8ed9082dc 100644 --- a/src/gui/LauncherFilterDialog.cxx +++ b/src/gui/LauncherFilterDialog.cxx @@ -130,8 +130,8 @@ bool LauncherFilterDialog::isValidRomName(const string& name, { const char* ext = name.c_str() + idx + 1; - for(uInt32 i = 0; i < exts.size(); ++i) - if(BSPF_equalsIgnoreCase(ext, exts[i])) + for(const auto& s: exts) + if(BSPF_equalsIgnoreCase(ext, s)) return true; } diff --git a/src/gui/MessageBox.cxx b/src/gui/MessageBox.cxx index bf55f88e3..d5b55c604 100644 --- a/src/gui/MessageBox.cxx +++ b/src/gui/MessageBox.cxx @@ -73,16 +73,16 @@ void MessageBox::addText(const GUI::Font& font, const StringList& text) // Set real dimensions int str_w = 0; - for(uInt32 i = 0; i < text.size(); ++i) - str_w = BSPF_max((int)text[i].length(), str_w); + for(const auto& s: text) + str_w = BSPF_max((int)s.length(), str_w); _w = BSPF_min(str_w * fontWidth + 20, _w); _h = BSPF_min((uInt32)((text.size() + 2) * lineHeight + 20), (uInt32)_h); xpos = 10; ypos = 10; - for(uInt32 i = 0; i < text.size(); ++i) + for(const auto& s: text) { new StaticTextWidget(this, font, xpos, ypos, _w - 20, - fontHeight, text[i], kTextAlignLeft); + fontHeight, s, kTextAlignLeft); ypos += fontHeight; } } diff --git a/src/gui/Rect.hxx b/src/gui/Rect.hxx index 6a018edb9..72a311089 100644 --- a/src/gui/Rect.hxx +++ b/src/gui/Rect.hxx @@ -37,9 +37,9 @@ struct Point int x; //!< The horizontal part of the point int y; //!< The vertical part of the point - Point() : x(0), y(0) {}; - Point(const Point& p) : x(p.x), y(p.y) {}; - explicit Point(int x1, int y1) : x(x1), y(y1) {}; + Point() : x(0), y(0) { }; + Point(const Point& p) : x(p.x), y(p.y) { }; + explicit Point(int x1, int y1) : x(x1), y(y1) { }; Point(const string& p) { char c = '\0'; x = y = -1; @@ -48,7 +48,7 @@ struct Point if(c != 'x') x = y = 0; } - Point & operator=(const Point & p) { x = p.x; y = p.y; return *this; }; + Point& operator=(const Point & p) { x = p.x; y = p.y; return *this; }; bool operator==(const Point & p) const { return x == p.x && y == p.y; }; bool operator!=(const Point & p) const { return x != p.x || y != p.y; }; @@ -63,9 +63,9 @@ struct Size uInt32 w; //!< The width part of the size uInt32 h; //!< The height part of the size - Size() : w(0), h(0) {}; - Size(const Size& s) : w(s.w), h(s.h) {}; - explicit Size(uInt32 w1, uInt32 h1) : w(w1), h(h1) {}; + Size() : w(0), h(0) { }; + Size(const Size& s) : w(s.w), h(s.h) { }; + explicit Size(uInt32 w1, uInt32 h1) : w(w1), h(h1) { }; Size(const string& s) { char c = '\0'; w = h = 0; @@ -112,10 +112,10 @@ struct Rect uInt32 top, left; //!< The point at the top left of the rectangle (part of the rect). uInt32 bottom, right; //!< The point at the bottom right of the rectangle (not part of the rect). - Rect() : top(0), left(0), bottom(0), right(0) {} - Rect(const Rect& s) : top(s.top), left(s.left), bottom(s.bottom), right(s.right) {} - Rect(uInt32 w, uInt32 h) : top(0), left(0), bottom(h), right(w) {} - Rect(const Point& p, uInt32 w, uInt32 h) : top(p.y), left(p.x), bottom(h), right(w) {} + Rect() : top(0), left(0), bottom(0), right(0) { } + Rect(const Rect& s) : top(s.top), left(s.left), bottom(s.bottom), right(s.right) { } + Rect(uInt32 w, uInt32 h) : top(0), left(0), bottom(h), right(w) { } + Rect(const Point& p, uInt32 w, uInt32 h) : top(p.y), left(p.x), bottom(h), right(w) { } Rect(uInt32 x1, uInt32 y1, uInt32 x2, uInt32 y2) : top(y1), left(x1), bottom(y2), right(x2) { assert(valid()); @@ -127,7 +127,7 @@ struct Rect uInt32 width() const { return right - left; } uInt32 height() const { return bottom - top; } - Size size() const { return Size(width(), height()); } + Size size() const { return Size(width(), height()); } void setWidth(uInt32 aWidth) { right = left + aWidth; } void setHeight(uInt32 aHeight) { bottom = top + aHeight; } diff --git a/src/gui/RomInfoWidget.cxx b/src/gui/RomInfoWidget.cxx index ea0a4dd16..6fd0cf98b 100644 --- a/src/gui/RomInfoWidget.cxx +++ b/src/gui/RomInfoWidget.cxx @@ -169,9 +169,9 @@ void RomInfoWidget::drawWidget(bool hilite) } int xpos = _x + 5, ypos = _y + yoff + 10; - for(unsigned int i = 0; i < myRomInfo.size(); ++i) + for(const auto& info: myRomInfo) { - s.drawString(_font, myRomInfo[i], xpos, ypos, _w - 10, _textcolor); + s.drawString(_font, info, xpos, ypos, _w - 10, _textcolor); ypos += _font.getLineHeight(); } } diff --git a/src/gui/TabWidget.cxx b/src/gui/TabWidget.cxx index f801fb2d0..3e4433ff3 100644 --- a/src/gui/TabWidget.cxx +++ b/src/gui/TabWidget.cxx @@ -50,10 +50,10 @@ TabWidget::TabWidget(GuiObject* boss, const GUI::Font& font, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - TabWidget::~TabWidget() { - for (unsigned int i = 0; i < _tabs.size(); ++i) + for(auto& tab: _tabs) { - delete _tabs[i].firstWidget; - _tabs[i].firstWidget = 0; + delete tab.firstWidget; + tab.firstWidget = nullptr; // _tabs[i].parentWidget is deleted elsewhere } _tabs.clear(); diff --git a/src/gui/Widget.cxx b/src/gui/Widget.cxx index 2b2d45a2d..b2adeaf6a 100644 --- a/src/gui/Widget.cxx +++ b/src/gui/Widget.cxx @@ -192,8 +192,8 @@ bool Widget::isWidgetInChain(Widget* w, Widget* find) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool Widget::isWidgetInChain(WidgetArray& list, Widget* find) { - for(int i = 0; i < (int)list.size(); ++i) - if(list[i] == find) + for(const auto& w: list) + if(w == find) return true; return false; diff --git a/src/macosx/SettingsMACOSX.cxx b/src/macosx/SettingsMACOSX.cxx index d2aaecc1b..ef11ac9db 100644 --- a/src/macosx/SettingsMACOSX.cxx +++ b/src/macosx/SettingsMACOSX.cxx @@ -56,9 +56,8 @@ void SettingsMACOSX::loadConfig() void SettingsMACOSX::saveConfig() { // Write out each of the key and value pairs - const SettingsArray& settings = getInternalSettings(); - for(unsigned int i = 0; i < settings.size(); ++i) - prefsSetString(settings[i].key.c_str(), settings[i].value.toCString()); + for(const auto& s: getInternalSettings()) + prefsSetString(s.key.c_str(), s.value.toCString()); prefsSave(); }