From 43a56c8ec8985d73ee7025b87f8d002d2ecbc5eb Mon Sep 17 00:00:00 2001 From: WarmUpTill Date: Tue, 2 May 2023 00:05:17 +0200 Subject: [PATCH] Resolve variables even when calling const functions This is done to ensure that logs printed before actions are executed contain the correct parameter values instead of potentially outdated ones. --- src/utils/variable-string.cpp | 6 +++--- src/utils/variable-string.hpp | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/utils/variable-string.cpp b/src/utils/variable-string.cpp index 938bbdd8..6d7dc422 100644 --- a/src/utils/variable-string.cpp +++ b/src/utils/variable-string.cpp @@ -4,7 +4,7 @@ namespace advss { -void StringVariable::Resolve() +void StringVariable::Resolve() const { if (switcher->variables.empty()) { _resolvedValue = _value; @@ -17,7 +17,7 @@ void StringVariable::Resolve() _lastResolve = GetLastVariableChangeTime(); } -StringVariable::operator std::string() +StringVariable::operator std::string() const { Resolve(); return _resolvedValue; @@ -59,7 +59,7 @@ const char *StringVariable::c_str() const char *StringVariable::c_str() const { - // Just assume that the value was previously resolved already + Resolve(); return _resolvedValue.c_str(); } diff --git a/src/utils/variable-string.hpp b/src/utils/variable-string.hpp index a0f07190..d8a63d61 100644 --- a/src/utils/variable-string.hpp +++ b/src/utils/variable-string.hpp @@ -14,7 +14,7 @@ public: StringVariable() : _value(""){}; StringVariable(std::string str) : _value(std::move(str)){}; StringVariable(const char *str) : _value(str){}; - operator std::string(); + operator std::string() const; operator QVariant() const; void operator=(std::string); void operator=(const char *value); @@ -27,15 +27,15 @@ public: void Save(obs_data_t *obj, const char *name) const; private: - void Resolve(); + void Resolve() const; std::string _value = ""; - std::string _resolvedValue = ""; - std::chrono::high_resolution_clock::time_point _lastResolve{}; + mutable std::string _resolvedValue = ""; + mutable std::chrono::high_resolution_clock::time_point _lastResolve{}; }; std::string SubstitueVariables(std::string str); } // namespace advss -Q_DECLARE_METATYPE(advss::StringVariable); \ No newline at end of file +Q_DECLARE_METATYPE(advss::StringVariable);