From c2d2a27d44cfaf402a785a54be2e2e4ff80a795a Mon Sep 17 00:00:00 2001 From: WarmUpTill Date: Sun, 23 May 2021 10:09:31 +0200 Subject: [PATCH] Use more const refs where applicable --- src/advanced-scene-switcher.cpp | 2 +- src/headers/advanced-scene-switcher.hpp | 13 +++++++------ src/headers/macro-action-edit.hpp | 12 ++++++------ src/headers/macro-condition-edit.hpp | 2 +- src/headers/macro.hpp | 2 +- src/headers/scene-group.hpp | 6 +++--- src/headers/switcher-data-structs.hpp | 4 ++-- src/headers/utility.hpp | 4 ++-- src/linux/advanced-scene-switcher-nix.cpp | 4 ++-- src/macro-action-edit.cpp | 13 +++++++------ src/macro-condition-edit.cpp | 2 +- src/osx/advanced-scene-switcher-osx.mm | 4 ++-- src/switch-file.cpp | 2 +- src/switch-transitions.cpp | 6 +++--- src/switcher-data-structs.cpp | 3 ++- src/win/advanced-scene-switcher-win.cpp | 4 ++-- 16 files changed, 43 insertions(+), 40 deletions(-) diff --git a/src/advanced-scene-switcher.cpp b/src/advanced-scene-switcher.cpp index bb0e3b32..f416c638 100644 --- a/src/advanced-scene-switcher.cpp +++ b/src/advanced-scene-switcher.cpp @@ -618,7 +618,7 @@ bool SwitcherData::checkForMatch(OBSWeakSource &scene, return match; } -void switchScene(sceneSwitchInfo sceneSwitch) +void switchScene(const sceneSwitchInfo &sceneSwitch) { if (!sceneSwitch.scene && switcher->verbose) { blog(LOG_INFO, "nothing to switch to"); diff --git a/src/headers/advanced-scene-switcher.hpp b/src/headers/advanced-scene-switcher.hpp index 7bf44ce6..c5c7fde4 100644 --- a/src/headers/advanced-scene-switcher.hpp +++ b/src/headers/advanced-scene-switcher.hpp @@ -286,8 +286,8 @@ private: void GetWindowList(std::vector &windows); void GetWindowList(QStringList &windows); void GetCurrentWindowTitle(std::string &title); -bool isFullscreen(std::string &title); -bool isMaximized(std::string &title); +bool isFullscreen(const std::string &title); +bool isMaximized(const std::string &title); /****************************************************************************** * Screenregion helper @@ -309,11 +309,12 @@ bool isInFocus(const QString &executable); * Sceneswitch helper ******************************************************************************/ -void setNextTransition(sceneSwitchInfo &ssi, obs_source_t *currentSource, +void setNextTransition(const sceneSwitchInfo &ssi, obs_source_t *currentSource, transitionData &td); -void overwriteTransitionOverride(sceneSwitchInfo ssi, transitionData &td); -void restoreTransitionOverride(obs_source_t *scene, transitionData td); -void switchScene(sceneSwitchInfo ssi); +void overwriteTransitionOverride(const sceneSwitchInfo &ssi, + transitionData &td); +void restoreTransitionOverride(obs_source_t *scene, const transitionData &td); +void switchScene(const sceneSwitchInfo &ssi); /****************************************************************************** * Main SwitcherData diff --git a/src/headers/macro-action-edit.hpp b/src/headers/macro-action-edit.hpp index cedf39a8..e6db7f35 100644 --- a/src/headers/macro-action-edit.hpp +++ b/src/headers/macro-action-edit.hpp @@ -20,12 +20,12 @@ struct MacroActionInfo { class MacroActionFactory { public: MacroActionFactory() = delete; - static bool Register(std::string id, MacroActionInfo); - static std::shared_ptr Create(const std::string id); - static QWidget *CreateWidget(const std::string id, QWidget *parent, + static bool Register(const std::string &id, MacroActionInfo); + static std::shared_ptr Create(const std::string &id); + static QWidget *CreateWidget(const std::string &id, QWidget *parent, std::shared_ptr action); static auto GetActionTypes() { return _methods; } - static std::string GetActionName(const std::string id); + static std::string GetActionName(const std::string &id); static std::string GetIdByName(const QString &name); private: @@ -38,9 +38,9 @@ class MacroActionEdit : public QWidget { public: MacroActionEdit(QWidget *parent = nullptr, std::shared_ptr * = nullptr, - std::string id = "scene_switch", + const std::string &id = "scene_switch", bool startCollapsed = false); - void UpdateEntryData(std::string id); + void UpdateEntryData(const std::string &id); void Collapse(bool collapsed); private slots: diff --git a/src/headers/macro-condition-edit.hpp b/src/headers/macro-condition-edit.hpp index 775ecf6c..2b05c238 100644 --- a/src/headers/macro-condition-edit.hpp +++ b/src/headers/macro-condition-edit.hpp @@ -21,7 +21,7 @@ class MacroConditionFactory { public: MacroConditionFactory() = delete; static bool Register(const std::string &, MacroConditionInfo); - static std::shared_ptr Create(const std::string); + static std::shared_ptr Create(const std::string &); static QWidget *CreateWidget(const std::string &id, QWidget *parent, std::shared_ptr); static auto GetConditionTypes() { return _methods; } diff --git a/src/headers/macro.hpp b/src/headers/macro.hpp index 8c2719f8..7468ee99 100644 --- a/src/headers/macro.hpp +++ b/src/headers/macro.hpp @@ -68,7 +68,7 @@ public: bool PerformAction(); bool Matched() { return _matched; } std::string Name() { return _name; } - void SetName(std::string name) { _name = name; } + void SetName(const std::string &name) { _name = name; } void SetPaused(bool pause = true) { _paused = pause; } bool Paused() { return _paused; } std::deque> &Conditions() diff --git a/src/headers/scene-group.hpp b/src/headers/scene-group.hpp index b29dc1ae..2e79f3e6 100644 --- a/src/headers/scene-group.hpp +++ b/src/headers/scene-group.hpp @@ -40,9 +40,9 @@ struct SceneGroup { int lastRandomScene = -1; inline SceneGroup(){}; - inline SceneGroup(std::string name_) : name(name_){}; - inline SceneGroup(std::string name_, AdvanceCondition type_, - std::vector scenes_, int count_, + inline SceneGroup(const std::string &name_) : name(name_){}; + inline SceneGroup(const std::string &name_, AdvanceCondition type_, + const std::vector &scenes_, int count_, double time_, bool repeat_) : name(name_), type(type_), diff --git a/src/headers/switcher-data-structs.hpp b/src/headers/switcher-data-structs.hpp index 64f13c0e..a9ac72cb 100644 --- a/src/headers/switcher-data-structs.hpp +++ b/src/headers/switcher-data-structs.hpp @@ -201,7 +201,7 @@ struct SwitcherData { void resetTabOrder(); void writeSceneInfoToFile(); - void writeToStatusFile(QString status); + void writeToStatusFile(const QString &msg); bool checkForMatch(OBSWeakSource &scene, OBSWeakSource &transition, int &linger, bool &setPreviousSceneAsMatch, @@ -254,7 +254,7 @@ struct SwitcherData { void saveNetworkSwitches(obs_data_t *obj); void saveGeneralSettings(obs_data_t *obj); void saveHotkeys(obs_data_t *obj); - void saveVersion(obs_data_t *obj, std::string currentVersion); + void saveVersion(obs_data_t *obj, const std::string ¤tVersion); void loadSettings(obs_data_t *obj); void loadMacros(obs_data_t *obj); diff --git a/src/headers/utility.hpp b/src/headers/utility.hpp index b427141b..f39835b8 100644 --- a/src/headers/utility.hpp +++ b/src/headers/utility.hpp @@ -114,7 +114,7 @@ static inline OBSWeakSource GetWeakFilterByQString(OBSWeakSource source, } static inline std::string -getNextDelim(std::string text, +getNextDelim(const std::string &text, std::unordered_map placeholders) { size_t pos = std::string::npos; @@ -214,7 +214,7 @@ static inline bool compareIgnoringLineEnding(QString &s1, QString &s2) return true; } -static inline bool DisplayMessage(QString msg, bool question = false) +static inline bool DisplayMessage(const QString &msg, bool question = false) { if (question) { QMessageBox::StandardButton reply; diff --git a/src/linux/advanced-scene-switcher-nix.cpp b/src/linux/advanced-scene-switcher-nix.cpp index 9f1c1db3..297ea2b3 100644 --- a/src/linux/advanced-scene-switcher-nix.cpp +++ b/src/linux/advanced-scene-switcher-nix.cpp @@ -253,7 +253,7 @@ std::pair getCursorPos() return pos; } -bool isMaximized(std::string &title) +bool isMaximized(const std::string &title) { if (!ewmhIsSupported()) return false; @@ -302,7 +302,7 @@ bool isMaximized(std::string &title) return false; } -bool isFullscreen(std::string &title) +bool isFullscreen(const std::string &title) { if (!ewmhIsSupported()) return false; diff --git a/src/macro-action-edit.cpp b/src/macro-action-edit.cpp index 08475b49..eb61f550 100644 --- a/src/macro-action-edit.cpp +++ b/src/macro-action-edit.cpp @@ -5,7 +5,7 @@ std::map MacroActionFactory::_methods; -bool MacroActionFactory::Register(std::string id, MacroActionInfo info) +bool MacroActionFactory::Register(const std::string &id, MacroActionInfo info) { if (auto it = _methods.find(id); it == _methods.end()) { _methods[id] = info; @@ -14,7 +14,7 @@ bool MacroActionFactory::Register(std::string id, MacroActionInfo info) return false; } -std::shared_ptr MacroActionFactory::Create(const std::string id) +std::shared_ptr MacroActionFactory::Create(const std::string &id) { if (auto it = _methods.find(id); it != _methods.end()) return it->second._createFunc(); @@ -22,7 +22,8 @@ std::shared_ptr MacroActionFactory::Create(const std::string id) return nullptr; } -QWidget *MacroActionFactory::CreateWidget(const std::string id, QWidget *parent, +QWidget *MacroActionFactory::CreateWidget(const std::string &id, + QWidget *parent, std::shared_ptr action) { if (auto it = _methods.find(id); it != _methods.end()) @@ -31,7 +32,7 @@ QWidget *MacroActionFactory::CreateWidget(const std::string id, QWidget *parent, return nullptr; } -std::string MacroActionFactory::GetActionName(const std::string id) +std::string MacroActionFactory::GetActionName(const std::string &id) { if (auto it = _methods.find(id); it != _methods.end()) { return it->second._name; @@ -58,7 +59,7 @@ static inline void populateActionSelection(QComboBox *list) MacroActionEdit::MacroActionEdit(QWidget *parent, std::shared_ptr *entryData, - std::string id, bool startCollapsed) + const std::string &id, bool startCollapsed) : QWidget(parent) { _actionSelection = new QComboBox(); @@ -100,7 +101,7 @@ void MacroActionEdit::ActionSelectionChanged(const QString &text) _section->Collapse(false); } -void MacroActionEdit::UpdateEntryData(std::string id) +void MacroActionEdit::UpdateEntryData(const std::string &id) { _actionSelection->setCurrentText( obs_module_text(MacroActionFactory::GetActionName(id).c_str())); diff --git a/src/macro-condition-edit.cpp b/src/macro-condition-edit.cpp index 488797f8..71c77c1b 100644 --- a/src/macro-condition-edit.cpp +++ b/src/macro-condition-edit.cpp @@ -14,7 +14,7 @@ bool MacroConditionFactory::Register(const std::string &id, } std::shared_ptr -MacroConditionFactory::Create(const std::string id) +MacroConditionFactory::Create(const std::string &id) { if (auto it = _methods.find(id); it != _methods.end()) return it->second._createFunc(); diff --git a/src/osx/advanced-scene-switcher-osx.mm b/src/osx/advanced-scene-switcher-osx.mm index d5cdebdd..9cb9ddd8 100644 --- a/src/osx/advanced-scene-switcher-osx.mm +++ b/src/osx/advanced-scene-switcher-osx.mm @@ -155,7 +155,7 @@ bool nameMachesPattern(std::string windowName, std::string pattern) .contains(QRegularExpression(QString::fromStdString(pattern))); } -bool isMaximized(std::string &title) +bool isMaximized(const std::string &title) { @autoreleasepool { NSArray *screens = [NSScreen screens]; @@ -204,7 +204,7 @@ bool isWindowFullscreenOnScreen(NSDictionary *app, NSScreen *screen) return NSEqualSizes(windowBounds.size, screenFrame.size); } -bool isFullscreen(std::string &title) +bool isFullscreen(const std::string &title) { @autoreleasepool { NSArray *screens = [NSScreen screens]; diff --git a/src/switch-file.cpp b/src/switch-file.cpp index da050bb2..f144f3b7 100644 --- a/src/switch-file.cpp +++ b/src/switch-file.cpp @@ -101,7 +101,7 @@ void SwitcherData::writeSceneInfoToFile() obs_source_release(currentSource); } -void SwitcherData::writeToStatusFile(QString msg) +void SwitcherData::writeToStatusFile(const QString &msg) { if (!fileIO.writeEnabled || fileIO.writePath.empty()) { return; diff --git a/src/switch-transitions.cpp b/src/switch-transitions.cpp index 494804de..221b8ca8 100644 --- a/src/switch-transitions.cpp +++ b/src/switch-transitions.cpp @@ -240,7 +240,7 @@ std::pair getNextTransition(obs_weak_source_t *scene1, return std::make_pair(ws, duration); } -void overwriteTransitionOverride(sceneSwitchInfo ssi, transitionData &td) +void overwriteTransitionOverride(const sceneSwitchInfo &ssi, transitionData &td) { obs_source_t *scene = obs_weak_source_get_source(ssi.scene); obs_data_t *data = obs_source_get_private_settings(scene); @@ -257,7 +257,7 @@ void overwriteTransitionOverride(sceneSwitchInfo ssi, transitionData &td) obs_source_release(scene); } -void restoreTransitionOverride(obs_source_t *scene, transitionData td) +void restoreTransitionOverride(obs_source_t *scene, const transitionData &td) { obs_data_t *data = obs_source_get_private_settings(scene); @@ -267,7 +267,7 @@ void restoreTransitionOverride(obs_source_t *scene, transitionData td) obs_data_release(data); } -void setNextTransition(sceneSwitchInfo &sceneSwitch, +void setNextTransition(const sceneSwitchInfo &sceneSwitch, obs_source_t *currentSource, transitionData &td) { // Priority: diff --git a/src/switcher-data-structs.cpp b/src/switcher-data-structs.cpp index b889bd69..b892494f 100644 --- a/src/switcher-data-structs.cpp +++ b/src/switcher-data-structs.cpp @@ -124,7 +124,8 @@ bool SwitcherData::versionChanged(obs_data_t *obj, std::string currentVersion) return previousVersion != currentVersion; } -void SwitcherData::saveVersion(obs_data_t *obj, std::string currentVersion) +void SwitcherData::saveVersion(obs_data_t *obj, + const std::string ¤tVersion) { obs_data_set_string(obj, "version", currentVersion.c_str()); } diff --git a/src/win/advanced-scene-switcher-win.cpp b/src/win/advanced-scene-switcher-win.cpp index 02e64712..13f4c247 100644 --- a/src/win/advanced-scene-switcher-win.cpp +++ b/src/win/advanced-scene-switcher-win.cpp @@ -142,7 +142,7 @@ HWND getHWNDfromTitle(std::string title) return hwnd; } -bool isMaximized(std::string &title) +bool isMaximized(const std::string &title) { RECT appBounds; MONITORINFO monitorInfo = {0}; @@ -172,7 +172,7 @@ bool isMaximized(std::string &title) return false; } -bool isFullscreen(std::string &title) +bool isFullscreen(const std::string &title) { RECT appBounds; MONITORINFO monitorInfo = {0};