mirror-chatterino2/src/singletons/helper/chatterinosetting.hpp

76 lines
1.6 KiB
C++
Raw Normal View History

2017-12-31 00:50:07 +01:00
#pragma once
namespace chatterino {
2017-12-31 22:58:35 +01:00
namespace singletons {
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:
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();
}
};
} // namespace singletons
} // namespace chatterino