mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-15 09:43:07 -07:00
Tweak CachedSettingValue
* Add another constructor to save a call to proxyFunc when its not needed note that this call is a virtual function call * Pass in proxyFunc by const reference * Move get methods together
This commit is contained in:
parent
a2d5d48aff
commit
3fb8ff281f
1 changed files with 14 additions and 7 deletions
|
@ -40,8 +40,15 @@ class CachedSettingValue
|
||||||
using ProxyFunc = std::function<T (const T&)>;
|
using ProxyFunc = std::function<T (const T&)>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CachedSettingValue(const char *keyName, const T &defaultValue = T()
|
explicit CachedSettingValue(const char *keyName, const T &defaultValue = T())
|
||||||
, ProxyFunc proxyFunc = [](const T &value) { return value; })
|
: m_keyName(QLatin1String(keyName))
|
||||||
|
, m_value(SettingsStorage::instance()->loadValue(
|
||||||
|
m_keyName, defaultValue).template value<T>())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit CachedSettingValue(const char *keyName, const T &defaultValue
|
||||||
|
, const ProxyFunc &proxyFunc)
|
||||||
: m_keyName(QLatin1String(keyName))
|
: m_keyName(QLatin1String(keyName))
|
||||||
, m_value(proxyFunc(SettingsStorage::instance()->loadValue(
|
, m_value(proxyFunc(SettingsStorage::instance()->loadValue(
|
||||||
m_keyName, defaultValue).template value<T>()))
|
m_keyName, defaultValue).template value<T>()))
|
||||||
|
@ -53,6 +60,11 @@ public:
|
||||||
return m_value;
|
return m_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
operator T() const
|
||||||
|
{
|
||||||
|
return value();
|
||||||
|
}
|
||||||
|
|
||||||
CachedSettingValue<T> &operator=(const T &newValue)
|
CachedSettingValue<T> &operator=(const T &newValue)
|
||||||
{
|
{
|
||||||
m_value = newValue;
|
m_value = newValue;
|
||||||
|
@ -60,11 +72,6 @@ public:
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
operator T() const
|
|
||||||
{
|
|
||||||
return value();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const QString m_keyName;
|
const QString m_keyName;
|
||||||
T m_value;
|
T m_value;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue