2017-12-31 00:50:07 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
namespace chatterino {
|
2017-12-31 22:58:35 +01:00
|
|
|
namespace singletons {
|
2018-04-03 02:55:32 +02:00
|
|
|
|
2018-04-14 21:59:51 +02:00
|
|
|
void _registerSetting(std::weak_ptr<pajlada::Settings::ISettingData> setting);
|
2017-12-31 00:50:07 +01:00
|
|
|
|
|
|
|
template <typename Type>
|
|
|
|
class ChatterinoSetting : public pajlada::Settings::Setting<Type>
|
|
|
|
{
|
|
|
|
public:
|
2018-01-04 01:52:37 +01:00
|
|
|
ChatterinoSetting(const std::string &_path)
|
|
|
|
: pajlada::Settings::Setting<Type>(_path)
|
|
|
|
{
|
|
|
|
_registerSetting(this->data);
|
|
|
|
}
|
|
|
|
|
2017-12-31 00:50:07 +01:00
|
|
|
ChatterinoSetting(const std::string &_path, const Type &_defaultValue)
|
|
|
|
: pajlada::Settings::Setting<Type>(_path, _defaultValue)
|
|
|
|
{
|
|
|
|
_registerSetting(this->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
ChatterinoSetting &operator=(const Type &newValue)
|
|
|
|
{
|
|
|
|
assert(this->data != nullptr);
|
|
|
|
|
|
|
|
this->setValue(newValue);
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T2>
|
|
|
|
ChatterinoSetting &operator=(const T2 &newValue)
|
|
|
|
{
|
|
|
|
assert(this->data != nullptr);
|
|
|
|
|
|
|
|
this->setValue(newValue);
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
ChatterinoSetting &operator=(Type &&newValue) noexcept
|
|
|
|
{
|
|
|
|
assert(this->data != nullptr);
|
|
|
|
|
|
|
|
this->setValue(std::move(newValue));
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const Type &rhs) const
|
|
|
|
{
|
|
|
|
assert(this->data != nullptr);
|
|
|
|
|
|
|
|
return this->getValue() == rhs;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const Type &rhs) const
|
|
|
|
{
|
|
|
|
assert(this->data != nullptr);
|
|
|
|
|
|
|
|
return this->getValue() != rhs;
|
|
|
|
}
|
|
|
|
|
|
|
|
operator const Type() const
|
|
|
|
{
|
|
|
|
assert(this->data != nullptr);
|
|
|
|
|
|
|
|
return this->getValue();
|
|
|
|
}
|
|
|
|
};
|
2018-04-03 02:55:32 +02:00
|
|
|
|
|
|
|
} // namespace singletons
|
|
|
|
} // namespace chatterino
|