More conversions from normal for to range-based for. Yes, I really love

range-based for that much.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@3070 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2014-11-10 21:59:56 +00:00
parent e352b3a6bb
commit 49eadb7463
18 changed files with 56 additions and 70 deletions

View File

@ -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';

View File

@ -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);

View File

@ -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))

View File

@ -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();
}

View File

@ -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,

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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;
}

View File

@ -33,7 +33,6 @@ GameList::GameList()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
GameList::~GameList()
{
clear();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -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)

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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; }

View File

@ -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();
}
}

View File

@ -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();

View File

@ -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;

View File

@ -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();
}