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.
This commit is contained in:
WarmUpTill 2023-05-02 00:05:17 +02:00 committed by WarmUpTill
parent 3da90bfa97
commit 43a56c8ec8
2 changed files with 8 additions and 8 deletions

View File

@ -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();
}

View File

@ -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);
Q_DECLARE_METATYPE(advss::StringVariable);