From 72c88d27a9a9783f4c010e01d1380f6c636305c2 Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Thu, 4 Aug 2022 22:15:04 -0230 Subject: [PATCH] Implemented suggestions from various linting tools. --- src/common/PNGLibrary.hxx | 6 ++--- src/common/Rect.hxx | 11 ++++----- src/common/Stack.hxx | 24 +++++++++---------- src/common/Variant.hxx | 7 ++---- src/common/bspf.hxx | 6 ++--- src/debugger/TIADebug.cxx | 2 +- src/emucore/Bankswitch.cxx | 12 +++++----- src/emucore/Bankswitch.hxx | 4 ++-- src/emucore/TIASurface.cxx | 4 ++-- .../tia/frame-manager/FrameLayoutDetector.cxx | 4 ++-- src/gui/ContextMenu.hxx | 3 ++- src/gui/DialogContainer.cxx | 2 +- src/gui/EditableWidget.cxx | 2 +- src/gui/InputDialog.cxx | 5 ++-- src/gui/LauncherDialog.cxx | 2 +- src/gui/StellaSettingsDialog.cxx | 4 ++-- 16 files changed, 47 insertions(+), 51 deletions(-) diff --git a/src/common/PNGLibrary.hxx b/src/common/PNGLibrary.hxx index 814c20a49..6770e7671 100644 --- a/src/common/PNGLibrary.hxx +++ b/src/common/PNGLibrary.hxx @@ -67,7 +67,7 @@ class PNGLibrary more detailed error message. */ void saveImage(const string& filename, - const VariantList& comments = EmptyVarList); + const VariantList& comments = VariantList{}); /** Save the given surface to a PNG file. @@ -82,8 +82,8 @@ class PNGLibrary more detailed error message. */ void saveImage(const string& filename, const FBSurface& surface, - const Common::Rect& rect = Common::EmptyRect, - const VariantList& comments = EmptyVarList); + const Common::Rect& rect = Common::Rect{}, + const VariantList& comments = VariantList{}); /** Called at regular intervals, and used to determine whether a diff --git a/src/common/Rect.hxx b/src/common/Rect.hxx index a9cfbbabf..36bb12359 100644 --- a/src/common/Rect.hxx +++ b/src/common/Rect.hxx @@ -35,7 +35,7 @@ struct Point Int32 x{0}; //!< The horizontal part of the point Int32 y{0}; //!< The vertical part of the point - Point() = default; + constexpr Point() = default; explicit constexpr Point(Int32 x1, Int32 y1) : x{x1}, y{y1} { } explicit Point(const string& p) { char c = '\0'; @@ -58,7 +58,7 @@ struct Size uInt32 w{0}; //!< The width part of the size uInt32 h{0}; //!< The height part of the size - Size() = default; + constexpr Size() = default; explicit constexpr Size(uInt32 w1, uInt32 h1) : w{w1}, h{h1} { } explicit Size(const string& s) { char c = '\0'; @@ -69,7 +69,7 @@ struct Size } constexpr bool valid() const { return w > 0 && h > 0; } - void clamp(uInt32 lower_w, uInt32 upper_w, uInt32 lower_h, uInt32 upper_h) { + constexpr void clamp(uInt32 lower_w, uInt32 upper_w, uInt32 lower_h, uInt32 upper_h) { w = BSPF::clamp(w, lower_w, upper_w); h = BSPF::clamp(h, lower_h, upper_h); } @@ -113,7 +113,7 @@ private: uInt32 bottom{0}, right{0}; public: - Rect() {} + constexpr Rect() = default; constexpr explicit Rect(const Size& s) : bottom{ s.h }, right{ s.w } { assert(valid()); } constexpr Rect(uInt32 w, uInt32 h) : bottom{ h }, right{ w } { assert(valid()); } constexpr Rect(const Point& p, uInt32 w, uInt32 h) @@ -186,9 +186,6 @@ public: } }; -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -static const Rect EmptyRect; - } // End of namespace Common #endif diff --git a/src/common/Stack.hxx b/src/common/Stack.hxx index 8eb48e4f6..4329ecab1 100644 --- a/src/common/Stack.hxx +++ b/src/common/Stack.hxx @@ -27,32 +27,32 @@ */ namespace Common { -template +template class FixedStack { private: std::array _stack; - uInt32 _size{0}; + size_t _size{0}; public: using StackFunction = std::function; - FixedStack() { } + FixedStack() = default; - bool empty() const { return _size <= 0; } + bool empty() const { return _size == 0; } bool full() const { return _size >= CAPACITY; } - T top() const { return _stack[_size - 1]; } - T get(uInt32 pos) const { return _stack[pos]; } - void push(const T& x) { _stack[_size++] = x; } - T pop() { return std::move(_stack[--_size]); } - uInt32 size() const { return _size; } + T top() const { return _stack[_size - 1]; } + T get(size_t pos) const { return _stack[pos]; } + void push(const T& x) { _stack[_size++] = x; } + T pop() { return std::move(_stack[--_size]); } + size_t size() const { return _size; } // Reverse the contents of the stack // This operation isn't needed very often, but it's handy to have void reverse() { if(_size > 1) - for(uInt32 i = 0, j = _size - 1; i < j; ++i, --j) + for(size_t i = 0, j = _size - 1; i < j; ++i, --j) std::swap(_stack[i], _stack[j]); } @@ -61,12 +61,12 @@ class FixedStack // and no access to individual elements is allowed outside // the class. void applyAll(const StackFunction& func) { - for(uInt32 i = 0; i < _size; ++i) + for(size_t i = 0; i < _size; ++i) func(_stack[i]); } friend ostream& operator<<(ostream& os, const FixedStack& s) { - for(uInt32 pos = 0; pos < s._size; ++pos) + for(size_t pos = 0; pos < s._size; ++pos) os << s._stack[pos] << " "; return os; } diff --git a/src/common/Variant.hxx b/src/common/Variant.hxx index 16f83e6a4..edbad771b 100644 --- a/src/common/Variant.hxx +++ b/src/common/Variant.hxx @@ -42,7 +42,7 @@ class Variant } public: - Variant() { } // NOLINT + Variant() = default; // NOLINT Variant(const string& s) : data{s} { } Variant(const char* s) : data{s} { } @@ -93,13 +93,10 @@ using VariantList = vector>; namespace VarList { inline void push_back(VariantList& list, const Variant& name, - const Variant& tag = EmptyVariant) + const Variant& tag = Variant{}) { list.emplace_back(name.toString(), tag); } } -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -static const VariantList EmptyVarList; - #endif diff --git a/src/common/bspf.hxx b/src/common/bspf.hxx index f9371d64e..1e77ae7d2 100644 --- a/src/common/bspf.hxx +++ b/src/common/bspf.hxx @@ -155,15 +155,15 @@ namespace BSPF // Combines 'max' and 'min', and clamps value to the upper/lower value // if it is outside the specified range - template inline T clamp(T val, T lower, T upper) + template inline constexpr T clamp(T val, T lower, T upper) { return (val < lower) ? lower : (val > upper) ? upper : val; } - template inline void clamp(T& val, T lower, T upper, T setVal) + template inline constexpr void clamp(T& val, T lower, T upper, T setVal) { if(val < lower || val > upper) val = setVal; } - template inline T clampw(T val, T lower, T upper) + template inline constexpr T clampw(T val, T lower, T upper) { return (val < lower) ? upper : (val > upper) ? lower : val; } diff --git a/src/debugger/TIADebug.cxx b/src/debugger/TIADebug.cxx index b2e56e458..15a979fff 100644 --- a/src/debugger/TIADebug.cxx +++ b/src/debugger/TIADebug.cxx @@ -1021,7 +1021,7 @@ string TIADebug::audFreq1() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - string TIADebug::audFreq(uInt8 dist, uInt8 div) { - constexpr uInt16 dist_div[16] = { + static constexpr uInt16 dist_div[16] = { 1, 15, 465, 465, 2, 2, 31, 31, 511, 31, 31, 1, 6, 6, 93, 93 }; diff --git a/src/emucore/Bankswitch.cxx b/src/emucore/Bankswitch.cxx index a64bbf066..61d91a498 100644 --- a/src/emucore/Bankswitch.cxx +++ b/src/emucore/Bankswitch.cxx @@ -92,7 +92,7 @@ bool Bankswitch::isValidRomName(const string& name) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -const std::array(Bankswitch::Type::NumSchemes)> +constexpr std::array(Bankswitch::Type::NumSchemes)> Bankswitch::BSList = {{ { "AUTO" , "Auto-detect" }, { "0840" , "0840 (8K EconoBanking)" }, @@ -153,10 +153,10 @@ Bankswitch::BSList = {{ #endif }}; -#ifdef GUI_SUPPORT -const std::array(Bankswitch::Type::NumSchemes)> +#if defined(GUI_SUPPORT) +constexpr std::array(Bankswitch::Type::NumSchemes)> Bankswitch::Sizes = {{ - { Bankswitch::any_KB, Bankswitch::any_KB }, // _AUTO + { Bankswitch::any_KB, Bankswitch::any_KB }, // _AUTO { 8_KB, 8_KB }, // _0840 { 8_KB, 8_KB }, // _0FA0 { 4_KB, 64_KB }, // _2IN1 @@ -195,7 +195,7 @@ Bankswitch::Sizes = {{ { 32_KB, 32_KB }, // _F4SC { 16_KB, 16_KB }, // _F6 { 16_KB, 16_KB }, // _F6SC - { 8_KB, 8_KB }, // _F8 + { 8_KB, 8_KB }, // _F8 { 8_KB, 8_KB }, // _F8SC { 12_KB, 12_KB }, // _FA { 24_KB, 32_KB }, // _FA2 @@ -214,7 +214,7 @@ Bankswitch::Sizes = {{ { Bankswitch::any_KB, Bankswitch::any_KB } } #endif }}; -#endif +#endif // GUI_SUPPORT // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Bankswitch::ExtensionMap Bankswitch::ourExtensions = { diff --git a/src/emucore/Bankswitch.hxx b/src/emucore/Bankswitch.hxx index 31be35f50..eb558b2d0 100644 --- a/src/emucore/Bankswitch.hxx +++ b/src/emucore/Bankswitch.hxx @@ -54,8 +54,8 @@ class Bankswitch #ifdef GUI_SUPPORT struct SizesType { - size_t minSize; - size_t maxSize; + size_t minSize{0}; + size_t maxSize{0}; }; static constexpr size_t any_KB = 0; diff --git a/src/emucore/TIASurface.cxx b/src/emucore/TIASurface.cxx index 09b0ca027..2b53ddb05 100644 --- a/src/emucore/TIASurface.cxx +++ b/src/emucore/TIASurface.cxx @@ -174,7 +174,7 @@ void TIASurface::setNTSC(NTSCFilter::Preset preset, bool show) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void TIASurface::changeNTSC(int direction) { - constexpr NTSCFilter::Preset PRESETS[] = { + static constexpr std::array PRESETS = { NTSCFilter::Preset::OFF, NTSCFilter::Preset::RGB, NTSCFilter::Preset::SVIDEO, NTSCFilter::Preset::COMPOSITE, NTSCFilter::Preset::BAD, NTSCFilter::Preset::CUSTOM }; @@ -334,7 +334,7 @@ void TIASurface::createScanlineSurface() : vRepeats(c_vRepeats), data(c_data) {} }; - std::array Patterns = {{ + static std::array Patterns = {{ Pattern(1, // standard { { 0x00000000 }, diff --git a/src/emucore/tia/frame-manager/FrameLayoutDetector.cxx b/src/emucore/tia/frame-manager/FrameLayoutDetector.cxx index 8c1fb81db..ba5c3f45f 100644 --- a/src/emucore/tia/frame-manager/FrameLayoutDetector.cxx +++ b/src/emucore/tia/frame-manager/FrameLayoutDetector.cxx @@ -79,11 +79,11 @@ FrameLayout FrameLayoutDetector::detectedLayout(bool detectPal60, bool detectNts { // Multiply each hue's count with its NTSC and PAL stats and aggregate results // If NTSC/PAL results differ significantly, overrule frame result - constexpr std::array ntscColorFactor{ + static constexpr std::array ntscColorFactor{ 0.00000, 0.05683, 0.06220, 0.05505, 0.06162, 0.02874, 0.03532, 0.03716, 0.15568, 0.06471, 0.02886, 0.03224, 0.06903, 0.11478, 0.02632, 0.01675 }; // ignore black = 0x00! - constexpr std::array palColorFactor{ + static constexpr std::array palColorFactor{ 0.00000, 0.00450, 0.09962, 0.07603, 0.06978, 0.13023, 0.09638, 0.02268, 0.02871, 0.04700, 0.02950, 0.11974, 0.03474, 0.08025, 0.00642, 0.00167 }; // ignore black = 0x00! diff --git a/src/gui/ContextMenu.hxx b/src/gui/ContextMenu.hxx index 3865be774..1e73a717d 100644 --- a/src/gui/ContextMenu.hxx +++ b/src/gui/ContextMenu.hxx @@ -42,7 +42,8 @@ class ContextMenu : public Dialog, public CommandSender public: ContextMenu(GuiObject* boss, const GUI::Font& font, - const VariantList& items, int cmd = 0, int width = 0); + const VariantList& items = VariantList{}, + int cmd = 0, int width = 0); ~ContextMenu() override = default; bool isShading() const override { return false; } diff --git a/src/gui/DialogContainer.cxx b/src/gui/DialogContainer.cxx index 8669439d6..35e5cf601 100644 --- a/src/gui/DialogContainer.cxx +++ b/src/gui/DialogContainer.cxx @@ -166,7 +166,7 @@ int DialogContainer::addDialog(Dialog* d) d->setDirty(); myDialogStack.push(d); } - return myDialogStack.size(); + return static_cast(myDialogStack.size()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/gui/EditableWidget.cxx b/src/gui/EditableWidget.cxx index dbadf83bf..67855823b 100644 --- a/src/gui/EditableWidget.cxx +++ b/src/gui/EditableWidget.cxx @@ -182,7 +182,7 @@ ContextMenu& EditableWidget::mouseMenu() { // add mouse context menu if(myMouseMenu == nullptr) - myMouseMenu = make_unique(this, _font, EmptyVarList); + myMouseMenu = make_unique(this, _font); return *myMouseMenu; } diff --git a/src/gui/InputDialog.cxx b/src/gui/InputDialog.cxx index 64f474807..f34830c77 100644 --- a/src/gui/InputDialog.cxx +++ b/src/gui/InputDialog.cxx @@ -256,8 +256,9 @@ void InputDialog::addDevicePortTab() ypos += lineHeight + VGAP * 3; lwidth = _font.getStringWidth("AtariVox serial port "); fwidth = _w - HBORDER * 2 - 2 - lwidth - PopUpWidget::dropDownWidth(_font); - myAVoxPort = new PopUpWidget(myTab, _font, HBORDER, ypos, fwidth, lineHeight, EmptyVarList, - "AtariVox serial port ", lwidth, kCursorStateChanged); + myAVoxPort = new PopUpWidget(myTab, _font, HBORDER, ypos, fwidth, lineHeight, + VariantList{}, "AtariVox serial port ", lwidth, + kCursorStateChanged); myAVoxPort->setEditable(true); wid.push_back(myAVoxPort); diff --git a/src/gui/LauncherDialog.cxx b/src/gui/LauncherDialog.cxx index 4bd4a6078..128f2eee2 100644 --- a/src/gui/LauncherDialog.cxx +++ b/src/gui/LauncherDialog.cxx @@ -788,7 +788,7 @@ ContextMenu& LauncherDialog::contextMenu() { if(myContextMenu == nullptr) // Create (empty) context menu for ROM list options - myContextMenu = make_unique(this, _font, EmptyVarList); + myContextMenu = make_unique(this, _font); return *myContextMenu; } diff --git a/src/gui/StellaSettingsDialog.cxx b/src/gui/StellaSettingsDialog.cxx index 4652e0da3..550777c43 100644 --- a/src/gui/StellaSettingsDialog.cxx +++ b/src/gui/StellaSettingsDialog.cxx @@ -481,7 +481,7 @@ void StellaSettingsDialog::loadControllerProperties(const Properties& props) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - int StellaSettingsDialog::levelToValue(int level) { - constexpr int NUM_LEVELS = 11; + static constexpr int NUM_LEVELS = 11; static constexpr std::array values = { 0, 5, 11, 18, 26, 35, 45, 56, 68, 81, 95 }; @@ -492,7 +492,7 @@ int StellaSettingsDialog::levelToValue(int level) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - int StellaSettingsDialog::valueToLevel(int value) { - constexpr int NUM_LEVELS = 11; + static constexpr int NUM_LEVELS = 11; static constexpr std::array values = { 0, 5, 11, 18, 26, 35, 45, 56, 68, 81, 95 };