From 343a6a092436c0307e72f20c803bb24e8bbde011 Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Sun, 8 May 2022 13:55:17 -0230 Subject: [PATCH] Minor fixes for warnings from some lint tools. --- src/common/HighScoresManager.cxx | 4 ++-- src/common/PJoystickHandler.hxx | 2 +- src/common/RewindManager.hxx | 16 ++++++++-------- src/common/bspf.hxx | 17 +++++------------ .../repository/CompositeKeyValueRepository.cxx | 2 +- .../repository/CompositeKeyValueRepository.hxx | 2 +- src/emucore/FBSurface.cxx | 10 ++-------- src/emucore/FBSurface.hxx | 4 ++-- src/emucore/Paddles.cxx | 18 +++++++++--------- src/gui/FileListWidget.cxx | 4 ++-- src/gui/FileListWidget.hxx | 4 +--- src/gui/NavigationWidget.hxx | 4 +++- 12 files changed, 37 insertions(+), 50 deletions(-) diff --git a/src/common/HighScoresManager.cxx b/src/common/HighScoresManager.cxx index d1bad0b7d..5b7e5ec62 100644 --- a/src/common/HighScoresManager.cxx +++ b/src/common/HighScoresManager.cxx @@ -522,7 +522,7 @@ const HSM::ScoreAddresses HighScoresManager::getPropScoreAddr(const json& jprops if(jprops.contains(SCORE_ADDRESSES)) { - const json addrProps = jprops.at(SCORE_ADDRESSES); + const json& addrProps = jprops.at(SCORE_ADDRESSES); if(!addrProps.empty() && addrProps.is_array()) { @@ -642,7 +642,7 @@ void HighScoresManager::loadHighScores(ScoresData& data) buf << "Error: Incompatible high scores data for variation " << data.variation << "."; else if(hsObject.contains(DATA)) { - const json hsData = hsObject.at(DATA); + const json& hsData = hsObject.at(DATA); if(!load(hsData, data) || !hsObject.contains(MD5) || hsObject.at(MD5) != data.md5 diff --git a/src/common/PJoystickHandler.hxx b/src/common/PJoystickHandler.hxx index e32f87fac..a2872d212 100644 --- a/src/common/PJoystickHandler.hxx +++ b/src/common/PJoystickHandler.hxx @@ -50,7 +50,7 @@ class PhysicalJoystickHandler struct StickInfo { explicit StickInfo(nlohmann::json map, PhysicalJoystickPtr stick = nullptr) - : mapping(map), joy{std::move(stick)} {} + : mapping{std::move(map)}, joy{std::move(stick)} {} nlohmann::json mapping; PhysicalJoystickPtr joy; diff --git a/src/common/RewindManager.hxx b/src/common/RewindManager.hxx index 200b9b818..795927181 100644 --- a/src/common/RewindManager.hxx +++ b/src/common/RewindManager.hxx @@ -75,14 +75,14 @@ class RewindManager static constexpr int NUM_HORIZONS = 8; // cycle values for the horzions const std::array HORIZON_CYCLES = { - 76 * 262 * 60 * 3, - 76 * 262 * 60 * 10, - 76 * 262 * 60 * 30, - 76 * 262 * 60 * 60, - 76 * 262 * 60 * 60 * 3, - 76 * 262 * 60 * 60 * 10, - uInt64{76} *262 * 60 * 60 * 30, - uInt64{76} *262 * 60 * 60 * 60 + uInt64{76} * 262 * 60 * 3, + uInt64{76} * 262 * 60 * 10, + uInt64{76} * 262 * 60 * 30, + uInt64{76} * 262 * 60 * 60, + uInt64{76} * 262 * 60 * 60 * 3, + uInt64{76} * 262 * 60 * 60 * 10, + uInt64{76} * 262 * 60 * 60 * 30, + uInt64{76} * 262 * 60 * 60 * 60 }; // settings values for the horzions const std::array HOR_SETTINGS = { diff --git a/src/common/bspf.hxx b/src/common/bspf.hxx index 10863f5ca..51cf5b64d 100644 --- a/src/common/bspf.hxx +++ b/src/common/bspf.hxx @@ -242,7 +242,7 @@ namespace BSPF // starting from 'startpos' in the first string static size_t findIgnoreCase(string_view s1, string_view s2, size_t startpos = 0) { - auto pos = std::search(s1.cbegin()+startpos, s1.cend(), + const auto pos = std::search(s1.cbegin()+startpos, s1.cend(), s2.cbegin(), s2.cend(), [](char ch1, char ch2) { return toupper(static_cast(ch1)) == toupper(static_cast(ch2)); }); @@ -335,7 +335,7 @@ namespace BSPF // Trim leading and trailing whitespace from a string inline string trim(const string& str) { - const string::size_type first = str.find_first_not_of(' '); + const auto first = str.find_first_not_of(' '); return (first == string::npos) ? EmptyString : str.substr(first, str.find_last_not_of(' ')-first+1); } @@ -344,8 +344,7 @@ namespace BSPF // Equivalent to the C-style localtime() function, but is thread-safe inline std::tm localTime() { - std::time_t currtime; - std::time(&currtime); + const auto currtime = std::time(nullptr); std::tm tm_snapshot; #if (defined BSPF_WINDOWS || defined __WIN32__) && (!defined __GNUG__ || defined __MINGW32__) localtime_s(&tm_snapshot, &currtime); @@ -355,15 +354,9 @@ namespace BSPF return tm_snapshot; } - inline bool isWhiteSpace(const char s) + inline bool isWhiteSpace(const char c) { - const string WHITESPACES = " ,.;:+-*&/\\'"; - - for(size_t i = 0; i < WHITESPACES.length(); ++i) - if(s == WHITESPACES[i]) - return true; - - return false; + return string(" ,.;:+-*&/\\'").find(c) != string::npos; } } // namespace BSPF diff --git a/src/common/repository/CompositeKeyValueRepository.cxx b/src/common/repository/CompositeKeyValueRepository.cxx index 257d2cd60..31eaf3afd 100644 --- a/src/common/repository/CompositeKeyValueRepository.cxx +++ b/src/common/repository/CompositeKeyValueRepository.cxx @@ -45,7 +45,7 @@ bool CompositeKeyValueRepositoryAtomic::has(const string& key1, const string& ke } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void CompositeKeyValueRepositoryAtomic::remove(const string& key1, const string key2) +void CompositeKeyValueRepositoryAtomic::remove(const string& key1, const string& key2) { getAtomic(key1)->remove(key2); } diff --git a/src/common/repository/CompositeKeyValueRepository.hxx b/src/common/repository/CompositeKeyValueRepository.hxx index 46cf5ae3e..76e797059 100644 --- a/src/common/repository/CompositeKeyValueRepository.hxx +++ b/src/common/repository/CompositeKeyValueRepository.hxx @@ -63,7 +63,7 @@ class CompositeKeyValueRepositoryAtomic : public CompositeKeyValueRepository virtual bool has(const string& key1, const string& key2); - virtual void remove(const string& key1, const string key2); + virtual void remove(const string& key1, const string& key2); CompositeKeyValueRepositoryAtomic* atomic() override { return this; } }; diff --git a/src/emucore/FBSurface.cxx b/src/emucore/FBSurface.cxx index 8aaadab29..940569371 100644 --- a/src/emucore/FBSurface.cxx +++ b/src/emucore/FBSurface.cxx @@ -334,15 +334,9 @@ void FBSurface::splitString(const GUI::Font& font, const string& s, int w, } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool FBSurface::isWhiteSpace(const char s) const +bool FBSurface::isWhiteSpace(const char c) const { - const string WHITESPACES = " ,.;:+-*/\\'([\n"; - - for(size_t i = 0; i < WHITESPACES.length(); ++i) - if(s == WHITESPACES[i]) - return true; - - return false; + return string(" ,.;:+-*/\\'([\n").find(c) != string::npos; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/FBSurface.hxx b/src/emucore/FBSurface.hxx index e342dcd06..d4906d1c7 100644 --- a/src/emucore/FBSurface.hxx +++ b/src/emucore/FBSurface.hxx @@ -400,10 +400,10 @@ class FBSurface /** Check if the given character is a whitespace. - @param s Character to check + @param c Character to check @return True if whitespace character */ - bool isWhiteSpace(const char s) const; + bool isWhiteSpace(const char c) const; protected: uInt32* myPixels{nullptr}; // NOTE: MUST be set in child classes diff --git a/src/emucore/Paddles.cxx b/src/emucore/Paddles.cxx index 3b6a8a8d6..e19e39456 100644 --- a/src/emucore/Paddles.cxx +++ b/src/emucore/Paddles.cxx @@ -209,15 +209,15 @@ AnalogReadout::Connection Paddles::getReadOut(int lastAxis, int& newAxis, int ce static constexpr std::array bFac = { // higher values mean more dejitter strength - 0.f, // off - 0.50f, 0.59f, 0.67f, 0.74f, 0.80f, - 0.85f, 0.89f, 0.92f, 0.94f, 0.95f + 0.F, // off + 0.50F, 0.59F, 0.67F, 0.74F, 0.80F, + 0.85F, 0.89F, 0.92F, 0.94F, 0.95F }; static constexpr std::array dFac = { // lower values mean more dejitter strength - 1.f, // off - 1.0f / 181, 1.0f / 256, 1.0f / 362, 1.0f / 512, 1.0f / 724, - 1.0f / 1024, 1.0f / 1448, 1.0f / 2048, 1.0f / 2896, 1.0f / 4096 + 1.F, // off + 1.0F / 181, 1.0F / 256, 1.0F / 362, 1.0F / 512, 1.0F / 724, + 1.0F / 1024, 1.0F / 1448, 1.0F / 2048, 1.0F / 2896, 1.0F / 4096 }; const float baseFactor = bFac[DEJITTER_BASE]; const float diffFactor = dFac[DEJITTER_DIFF]; @@ -518,7 +518,7 @@ float Paddles::analogSensitivityValue(int sensitivity) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Paddles::setAnalogLinearity(int linearity) { - LINEARITY = 100.f / BSPF::clamp(linearity, MIN_ANALOG_LINEARITY, MAX_ANALOG_LINEARITY); + LINEARITY = 100.F / BSPF::clamp(linearity, MIN_ANALOG_LINEARITY, MAX_ANALOG_LINEARITY); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Paddles::setDejitterBase(int strength) @@ -549,8 +549,8 @@ void Paddles::setDigitalPaddleRange(int range) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - int Paddles::XCENTER = 0; int Paddles::YCENTER = 0; -float Paddles::SENSITIVITY = 1.0; -float Paddles::LINEARITY = 1.0; +float Paddles::SENSITIVITY = 1.F; +float Paddles::LINEARITY = 1.F; int Paddles::DEJITTER_BASE = 0; int Paddles::DEJITTER_DIFF = 0; int Paddles::TRIGRANGE = Paddles::TRIGMAX; diff --git a/src/gui/FileListWidget.cxx b/src/gui/FileListWidget.cxx index dda5d2c7a..1243841b3 100644 --- a/src/gui/FileListWidget.cxx +++ b/src/gui/FileListWidget.cxx @@ -58,7 +58,7 @@ void FileListWidget::setDirectory(const FilesystemNode& node, _history.clear(); while(tmp.hasParent()) { - _history.push_back(HistoryType(tmp, fixPath(name))); + _history.emplace_back(tmp, fixPath(name)); name = tmp.getName(); tmp = tmp.getParent(); @@ -262,7 +262,7 @@ void FileListWidget::addHistory(const FilesystemNode& node) string select = selected().getName(); _currentHistory->selected = fixPath(select); - _history.push_back(HistoryType(node, "..")); + _history.emplace_back(node, ".."); _currentHistory = std::prev(_history.end(), 1); //_historyIndex++; } diff --git a/src/gui/FileListWidget.hxx b/src/gui/FileListWidget.hxx index bf410d18d..be03b1e60 100644 --- a/src/gui/FileListWidget.hxx +++ b/src/gui/FileListWidget.hxx @@ -117,9 +117,7 @@ class FileListWidget : public StringListWidget FilesystemNode node; string selected; - HistoryType() - : node{}, selected{} {} - explicit HistoryType(const FilesystemNode _hnode, const string _hselected) + explicit HistoryType(const FilesystemNode& _hnode, const string& _hselected) : node{_hnode}, selected{_hselected} {} }; enum class IconType { diff --git a/src/gui/NavigationWidget.hxx b/src/gui/NavigationWidget.hxx index 0be06c879..1235083bb 100644 --- a/src/gui/NavigationWidget.hxx +++ b/src/gui/NavigationWidget.hxx @@ -20,7 +20,9 @@ class EditTextWidget; class FileListWidget; -class Font; +namespace GUI { + class Font; +} #include "Widget.hxx"