From 380169f23c308aa6e2b6e4d95876631bdb1e943c Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Thu, 1 Dec 2022 15:39:21 -0330 Subject: [PATCH] Implemented suggestions from clang-tidy-16 (mostly emplace vs. push_back). --- src/cheat/CheatCodeDialog.cxx | 4 +- .../repository/CompositeKVRJsonAdapter.cxx | 5 +- src/debugger/CartDebug.cxx | 10 +-- src/debugger/Debugger.cxx | 4 +- src/debugger/gui/RiotWidget.cxx | 36 +++++----- src/debugger/gui/ToggleBitWidget.cxx | 4 +- src/emucore/EventHandler.cxx | 8 +-- src/gui/Dialog.cxx | 6 +- src/gui/HighScoresDialog.cxx | 6 +- src/gui/InputDialog.cxx | 14 ++-- src/gui/LauncherDialog.cxx | 66 +++++++++---------- src/gui/RomAuditDialog.cxx | 14 ++-- src/gui/StellaSettingsDialog.cxx | 18 ++--- src/gui/TabWidget.cxx | 4 +- 14 files changed, 100 insertions(+), 99 deletions(-) diff --git a/src/cheat/CheatCodeDialog.cxx b/src/cheat/CheatCodeDialog.cxx index 32c91b429..4622cb188 100644 --- a/src/cheat/CheatCodeDialog.cxx +++ b/src/cheat/CheatCodeDialog.cxx @@ -83,8 +83,8 @@ CheatCodeDialog::CheatCodeDialog(OSystem& osystem, DialogContainer& parent, // Inputbox which will pop up when adding/editing a cheat StringList labels; - labels.push_back("Name "); - labels.push_back("Code (hex) "); + labels.emplace_back("Name "); + labels.emplace_back("Code (hex) "); myCheatInput = make_unique(this, font, labels, "Cheat code"); myCheatInput->setTarget(this); diff --git a/src/common/repository/CompositeKVRJsonAdapter.cxx b/src/common/repository/CompositeKVRJsonAdapter.cxx index 3c2c8699f..a9b3672eb 100644 --- a/src/common/repository/CompositeKVRJsonAdapter.cxx +++ b/src/common/repository/CompositeKVRJsonAdapter.cxx @@ -48,8 +48,9 @@ namespace { private: - KeyValueRepositoryAtomic& myKvr; - const string& myKey; + // NOLINT: cppcoreguidelines-avoid-const-or-ref-data-members + KeyValueRepositoryAtomic& myKvr; // NOLINT + const string& myKey; // NOLINT }; } // namespace diff --git a/src/debugger/CartDebug.cxx b/src/debugger/CartDebug.cxx index 4c7b60192..ed70f94ed 100644 --- a/src/debugger/CartDebug.cxx +++ b/src/debugger/CartDebug.cxx @@ -1541,23 +1541,23 @@ void CartDebug::getCompletions(const char* in, StringList& completions) const // First scan system equates for(uInt16 addr = 0x00; addr <= 0x0F; ++addr) if(ourTIAMnemonicR[addr] && BSPF::matchesIgnoreCase(ourTIAMnemonicR[addr], in)) - completions.push_back(ourTIAMnemonicR[addr]); + completions.emplace_back(ourTIAMnemonicR[addr]); for(uInt16 addr = 0x00; addr <= 0x3F; ++addr) if(ourTIAMnemonicW[addr] && BSPF::matchesIgnoreCase(ourTIAMnemonicW[addr], in)) - completions.push_back(ourTIAMnemonicW[addr]); + completions.emplace_back(ourTIAMnemonicW[addr]); for(uInt16 addr = 0; addr <= 0x29F-0x280; ++addr) if(ourIOMnemonic[addr] && BSPF::matchesIgnoreCase(ourIOMnemonic[addr], in)) - completions.push_back(ourIOMnemonic[addr]); + completions.emplace_back(ourIOMnemonic[addr]); for(uInt16 addr = 0; addr <= 0x7F; ++addr) if(ourZPMnemonic[addr] && BSPF::matchesIgnoreCase(ourZPMnemonic[addr], in)) - completions.push_back(ourZPMnemonic[addr]); + completions.emplace_back(ourZPMnemonic[addr]); // Now scan user-defined labels for(const auto& iter: myUserAddresses) { const char* const l = iter.first.c_str(); if(BSPF::matchesCamelCase(l, in)) - completions.push_back(l); + completions.emplace_back(l); } } diff --git a/src/debugger/Debugger.cxx b/src/debugger/Debugger.cxx index dda3774e1..0f0bde82c 100644 --- a/src/debugger/Debugger.cxx +++ b/src/debugger/Debugger.cxx @@ -901,12 +901,12 @@ void Debugger::getCompletions(const char* in, StringList& list) const { const char* const l = iter.first.c_str(); if(BSPF::matchesCamelCase(l, in)) - list.push_back(l); + list.emplace_back(l); } for(const auto& reg: ourPseudoRegisters) if(BSPF::matchesCamelCase(reg.name, in)) - list.push_back(reg.name); + list.emplace_back(reg.name); } } diff --git a/src/debugger/gui/RiotWidget.cxx b/src/debugger/gui/RiotWidget.cxx index ddca888e7..d6c1f857c 100644 --- a/src/debugger/gui/RiotWidget.cxx +++ b/src/debugger/gui/RiotWidget.cxx @@ -63,8 +63,8 @@ RiotWidget::RiotWidget(GuiObject* boss, const GUI::Font& lfont, StringList off, on; for(int i = 0; i < 8; ++i) { - off.push_back("0"); - on.push_back("1"); + off.emplace_back("0"); + on.emplace_back("1"); } StringList labels; @@ -91,14 +91,14 @@ RiotWidget::RiotWidget(GuiObject* boss, const GUI::Font& lfont, // SWCHA bits in 'peek' mode xpos = 10; ypos += lineHeight + 5; labels.clear(); - labels.push_back("Left right"); - labels.push_back("Left left"); - labels.push_back("Left down"); - labels.push_back("Left up"); - labels.push_back("Right right"); - labels.push_back("Right left"); - labels.push_back("Right down"); - labels.push_back("Right up"); + labels.emplace_back("Left right"); + labels.emplace_back("Left left"); + labels.emplace_back("Left down"); + labels.emplace_back("Left up"); + labels.emplace_back("Right right"); + labels.emplace_back("Right left"); + labels.emplace_back("Right down"); + labels.emplace_back("Right up"); CREATE_IO_REGS("SWCHA(R)", mySWCHAReadBits, kSWCHARBitsID, true) // SWCHB bits in 'poke' mode @@ -113,14 +113,14 @@ RiotWidget::RiotWidget(GuiObject* boss, const GUI::Font& lfont, // SWCHB bits in 'peek' mode xpos = 10; ypos += lineHeight + 5; labels.clear(); - labels.push_back("Right difficulty"); - labels.push_back("Left difficulty"); - labels.push_back(""); - labels.push_back(""); - labels.push_back("Color/B+W"); - labels.push_back(""); - labels.push_back("Select"); - labels.push_back("Reset"); + labels.emplace_back("Right difficulty"); + labels.emplace_back("Left difficulty"); + labels.emplace_back(""); + labels.emplace_back(""); + labels.emplace_back("Color/B+W"); + labels.emplace_back(""); + labels.emplace_back("Select"); + labels.emplace_back("Reset"); CREATE_IO_REGS("SWCHB(R)", mySWCHBReadBits, kSWCHBRBitsID, true) // Timer registers (R/W) diff --git a/src/debugger/gui/ToggleBitWidget.cxx b/src/debugger/gui/ToggleBitWidget.cxx index cb4d6a8ca..48f89b10f 100644 --- a/src/debugger/gui/ToggleBitWidget.cxx +++ b/src/debugger/gui/ToggleBitWidget.cxx @@ -38,8 +38,8 @@ ToggleBitWidget::ToggleBitWidget(GuiObject* boss, const GUI::Font& font, int size = _rows * _cols; while(size--) { - _offList.push_back("0"); - _onList.push_back("1"); + _offList.emplace_back("0"); + _onList.emplace_back("1"); _stateList.push_back(false); _changedList.push_back(false); } diff --git a/src/emucore/EventHandler.cxx b/src/emucore/EventHandler.cxx index b7f6610d6..a6dc84a73 100644 --- a/src/emucore/EventHandler.cxx +++ b/src/emucore/EventHandler.cxx @@ -1543,11 +1543,11 @@ void EventHandler::handleEvent(Event::Type event, Int32 value, bool repeated) myOSystem.settings().getBool("dev.settings") ? "dev.timemachine" : "plr.timemachine"); - msg.push_back("Do you really want to exit emulation?"); + msg.emplace_back("Do you really want to exit emulation?"); if (saveOnExit != "all" || !activeTM) { - msg.push_back(""); - msg.push_back("You will lose all your progress."); + msg.emplace_back(""); + msg.emplace_back("You will lose all your progress."); } MessageMenu::setMessage("Exit Emulation", msg, true); enterMenuMode(EventHandlerState::MESSAGEMENU); @@ -2330,7 +2330,7 @@ StringList EventHandler::getComboListForEvent(Event::Type event) const } // Make sure entries are 1-to-1, using '-1' to indicate Event::NoType if(i == l.size()) - l.push_back("-1"); + l.emplace_back("-1"); } } return l; diff --git a/src/gui/Dialog.cxx b/src/gui/Dialog.cxx index 7687cf307..4f667c0a9 100644 --- a/src/gui/Dialog.cxx +++ b/src/gui/Dialog.cxx @@ -441,7 +441,7 @@ void Dialog::addToFocusList(const WidgetArray& list, const TabWidget* w, int tab { // Make sure the array is large enough while(focus.size() <= id) - focus.push_back(Focus()); + focus.emplace_back(); Vec::append(focus[id].list, list); } @@ -459,9 +459,9 @@ void Dialog::addTabWidget(TabWidget* w) // Make sure the array is large enough const uInt32 id = w->getID(); while(_myTabList.size() < id) - _myTabList.push_back(TabFocus()); + _myTabList.emplace_back(); - _myTabList.push_back(TabFocus(w)); + _myTabList.emplace_back(w); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/gui/HighScoresDialog.cxx b/src/gui/HighScoresDialog.cxx index f4a9e8189..0fe295295 100644 --- a/src/gui/HighScoresDialog.cxx +++ b/src/gui/HighScoresDialog.cxx @@ -509,9 +509,9 @@ bool HighScoresDialog::handleDirty() { StringList msg; - msg.push_back("Do you want to save the changes"); - msg.push_back("for this variation?"); - msg.push_back(""); + msg.emplace_back("Do you want to save the changes"); + msg.emplace_back("for this variation?"); + msg.emplace_back(""); myConfirmMsg = make_unique (this, _font, msg, _max_w, _max_h, kConfirmSave, kCancelSave, "Yes", "No", "Save High Scores", false); diff --git a/src/gui/InputDialog.cxx b/src/gui/InputDialog.cxx index 385b7b365..7c9836cc3 100644 --- a/src/gui/InputDialog.cxx +++ b/src/gui/InputDialog.cxx @@ -783,13 +783,13 @@ void InputDialog::handleCommand(CommandSender* sender, int cmd, if(!myConfirmMsg) { StringList msg; - msg.push_back("This operation cannot be undone."); - msg.push_back("All data stored on your AtariVox"); - msg.push_back("or SaveKey will be erased!"); - msg.push_back(""); - msg.push_back("If you are sure you want to erase"); - msg.push_back("the data, click 'OK', otherwise "); - msg.push_back("click 'Cancel'."); + msg.emplace_back("This operation cannot be undone."); + msg.emplace_back("All data stored on your AtariVox"); + msg.emplace_back("or SaveKey will be erased!"); + msg.emplace_back(""); + msg.emplace_back("If you are sure you want to erase"); + msg.emplace_back("the data, click 'OK', otherwise "); + msg.emplace_back("click 'Cancel'."); myConfirmMsg = make_unique (this, instance().frameBuffer().font(), msg, myMaxWidth, myMaxHeight, kConfirmEEEraseCmd, diff --git a/src/gui/LauncherDialog.cxx b/src/gui/LauncherDialog.cxx index 5ddcc8bd9..f692f9229 100644 --- a/src/gui/LauncherDialog.cxx +++ b/src/gui/LauncherDialog.cxx @@ -1166,64 +1166,64 @@ void LauncherDialog::openContextMenu(int x, int y) if(!currentNode().isDirectory()) { if(myList->isUserDir(currentNode().getName())) - items.push_back(ContextItem("Remove all from favorites", "removefavorites")); + items.emplace_back("Remove all from favorites", "removefavorites"); if(myList->isPopularDir(currentNode().getName())) - items.push_back(ContextItem("Remove all from most popular", "removepopular")); + items.emplace_back("Remove all from most popular", "removepopular"); if(myList->isRecentDir(currentNode().getName())) - items.push_back(ContextItem("Remove all from recently played", "removerecent")); + items.emplace_back("Remove all from recently played", "removerecent"); if(myList->inRecentDir()) - items.push_back(ContextItem("Remove from recently played", "Ctrl+X", "remove")); + items.emplace_back("Remove from recently played", "Ctrl+X", "remove"); if(myList->inPopularDir()) - items.push_back(ContextItem("Remove from most popular", "Ctrl+X", "remove")); + items.emplace_back("Remove from most popular", "Ctrl+X", "remove"); } if((currentNode().isDirectory() && currentNode().getName() != "..") || Bankswitch::isValidRomName(currentNode())) - items.push_back(ContextItem(myList->isUserFavorite(myList->selected().getPath()) + items.emplace_back(myList->isUserFavorite(myList->selected().getPath()) ? "Remove from favorites" - : "Add to favorites", "Ctrl+F", "favorite")); + : "Add to favorites", "Ctrl+F", "favorite"); } if(!currentNode().isDirectory() && Bankswitch::isValidRomName(currentNode())) { - items.push_back(ContextItem("Game properties" + ELLIPSIS, "Ctrl+G", "properties")); - items.push_back(ContextItem("Power-on options" + ELLIPSIS, "Ctrl+P", "override")); + items.emplace_back("Game properties" + ELLIPSIS, "Ctrl+G", "properties"); + items.emplace_back("Power-on options" + ELLIPSIS, "Ctrl+P", "override"); if(instance().highScores().enabled()) - items.push_back(ContextItem("High scores" + ELLIPSIS, "Ctrl+H", "highscores")); + items.emplace_back("High scores" + ELLIPSIS, "Ctrl+H", "highscores"); } if(myUseMinimalUI) { #ifndef RETRON77 - items.push_back(ContextItem(instance().settings().getBool("launchersubdirs") + items.emplace_back(instance().settings().getBool("launchersubdirs") ? "Exclude subdirectories" - : "Include subdirectories", "subdirs")); - items.push_back(ContextItem(instance().settings().getBool("launcherroms") + : "Include subdirectories", "subdirs"); + items.emplace_back(instance().settings().getBool("launcherroms") ? "Show all files" - : "Show only ROMs", "showall")); + : "Show only ROMs", "showall"); #endif - items.push_back(ContextItem("Go to initial directory", "homedir")); - items.push_back(ContextItem("Go to parent directory", "prevdir")); + items.emplace_back("Go to initial directory", "homedir"); + items.emplace_back("Go to parent directory", "prevdir"); #ifndef RETRON77 - items.push_back(ContextItem("Reload listing", "reload")); - items.push_back(ContextItem("Options" + ELLIPSIS, "options")); + items.emplace_back("Reload listing", "reload"); + items.emplace_back("Options" + ELLIPSIS, "options"); #else - items.push_back(ContextItem("Settings" + ELLIPSIS, "options")); + items.emplace_back("Settings" + ELLIPSIS, "options"); #endif } else { - items.push_back(ContextItem(instance().settings().getBool("launcherextensions") + items.emplace_back(instance().settings().getBool("launcherextensions") ? "Disable file extensions" - : "Enable file extensions", "Ctrl+E", "extensions")); + : "Enable file extensions", "Ctrl+E", "extensions"); if(useFavorites && myList->inVirtualDir()) - items.push_back(ContextItem(instance().settings().getBool("altsorting") + items.emplace_back(instance().settings().getBool("altsorting") ? "Normal sorting" - : "Alternative sorting", "Ctrl+S", "sorting")); + : "Alternative sorting", "Ctrl+S", "sorting"); //if(!instance().settings().getBool("launcherbuttons")) //{ - // items.push_back(ContextItem("Options" + ELLIPSIS, "Ctrl+O", "options")); + // items.emplace_back("Options" + ELLIPSIS, "Ctrl+O", "options"); //} } if(addCancel) - items.push_back(ContextItem("Cancel", "")); // closes the context menu and does nothing + items.emplace_back("Cancel", ""); // closes the context menu and does nothing // Format items for menu VariantList varItems; @@ -1382,10 +1382,10 @@ void LauncherDialog::removeAllFavorites() { StringList msg; - msg.push_back("This will remove ALL ROMs from"); - msg.push_back("your 'Favorites' list!"); - msg.push_back(""); - msg.push_back("Are you sure?"); + msg.emplace_back("This will remove ALL ROMs from"); + msg.emplace_back("your 'Favorites' list!"); + msg.emplace_back(""); + msg.emplace_back("Are you sure?"); myConfirmMsg = make_unique (this, _font, msg, _w, _h, kRmAllFav, "Yes", "No", "Remove all Favorites", false); @@ -1397,10 +1397,10 @@ void LauncherDialog::removeAll(const string& name) { StringList msg; - msg.push_back("This will remove ALL ROMs from"); - msg.push_back("your '" + name + "' list!"); - msg.push_back(""); - msg.push_back("Are you sure?"); + msg.emplace_back("This will remove ALL ROMs from"); + msg.emplace_back("your '" + name + "' list!"); + msg.emplace_back(""); + msg.emplace_back("Are you sure?"); myConfirmMsg = make_unique (this, _font, msg, _w, _h, kRmAllPop, "Yes", "No", "Remove all " + name, false); diff --git a/src/gui/RomAuditDialog.cxx b/src/gui/RomAuditDialog.cxx index 4969d004f..f4f7efb92 100644 --- a/src/gui/RomAuditDialog.cxx +++ b/src/gui/RomAuditDialog.cxx @@ -177,13 +177,13 @@ void RomAuditDialog::handleCommand(CommandSender* sender, int cmd, if(!myConfirmMsg) { StringList msg; - msg.push_back("This operation cannot be undone. Your ROMs"); - msg.push_back("will be modified, and as such there is a chance"); - msg.push_back("that files may be lost. You are recommended"); - msg.push_back("to back up your files before proceeding."); - msg.push_back(""); - msg.push_back("If you're sure you want to proceed with the"); - msg.push_back("audit, click 'OK', otherwise click 'Cancel'."); + msg.emplace_back("This operation cannot be undone. Your ROMs"); + msg.emplace_back("will be modified, and as such there is a chance"); + msg.emplace_back("that files may be lost. You are recommended"); + msg.emplace_back("to back up your files before proceeding."); + msg.emplace_back(""); + msg.emplace_back("If you're sure you want to proceed with the"); + msg.emplace_back("audit, click 'OK', otherwise click 'Cancel'."); myConfirmMsg = make_unique (this, _font, msg, myMaxWidth, myMaxHeight, kConfirmAuditCmd, "OK", "Cancel", "ROM Audit", false); diff --git a/src/gui/StellaSettingsDialog.cxx b/src/gui/StellaSettingsDialog.cxx index 91360d4ce..08e05d162 100644 --- a/src/gui/StellaSettingsDialog.cxx +++ b/src/gui/StellaSettingsDialog.cxx @@ -412,15 +412,15 @@ void StellaSettingsDialog::switchSettingsMode() { StringList msg; - msg.push_back("Warning!"); - msg.push_back(""); - msg.push_back("Advanced settings should be"); - msg.push_back("handled with care! When in"); - msg.push_back("doubt, read the manual."); - msg.push_back(""); - msg.push_back("If you are sure you want to"); - msg.push_back("proceed with the switch, click"); - msg.push_back("'OK', otherwise click 'Cancel'."); + msg.emplace_back("Warning!"); + msg.emplace_back(""); + msg.emplace_back("Advanced settings should be"); + msg.emplace_back("handled with care! When in"); + msg.emplace_back("doubt, read the manual."); + msg.emplace_back(""); + msg.emplace_back("If you are sure you want to"); + msg.emplace_back("proceed with the switch, click"); + msg.emplace_back("'OK', otherwise click 'Cancel'."); myConfirmMsg = make_unique(this, _font, msg, _w-16, _h, kConfirmSwitchCmd, "OK", "Cancel", "Switch settings mode", false); diff --git a/src/gui/TabWidget.cxx b/src/gui/TabWidget.cxx index 0c43bc7e3..e3a0171c4 100644 --- a/src/gui/TabWidget.cxx +++ b/src/gui/TabWidget.cxx @@ -66,9 +66,9 @@ int TabWidget::addTab(const string& title, int tabWidth) const int newWidth = _font.getStringWidth(title) + 2 * kTabPadding; if(tabWidth == AUTO_WIDTH) - _tabs.push_back(Tab(title, newWidth)); + _tabs.emplace_back(title, newWidth); else - _tabs.push_back(Tab(title, tabWidth)); + _tabs.emplace_back(title, tabWidth); const int numTabs = static_cast(_tabs.size()); // Determine the new tab width