mirror-chatterino2/src/common/ChatterinoSetting.hpp

54 lines
1.4 KiB
C++
Raw Normal View History

2017-12-31 00:50:07 +01:00
#pragma once
#include <QString>
#include <pajlada/settings.hpp>
2017-12-31 00:50:07 +01:00
namespace chatterino {
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);
}
ChatterinoSetting(const std::string &path, const Type &defaultValue)
: pajlada::Settings::Setting<Type>(path, defaultValue)
2017-12-31 00:50:07 +01:00
{
_registerSetting(this->data);
}
template <typename T2>
ChatterinoSetting &operator=(const T2 &newValue)
{
this->setValue(newValue);
return *this;
}
ChatterinoSetting &operator=(Type &&newValue) noexcept
{
2018-04-22 14:09:38 +02:00
pajlada::Settings::Setting<Type>::operator=(newValue);
2017-12-31 00:50:07 +01:00
return *this;
}
2018-04-22 14:09:38 +02:00
using pajlada::Settings::Setting<Type>::operator==;
using pajlada::Settings::Setting<Type>::operator!=;
2017-12-31 00:50:07 +01:00
2018-04-22 14:09:38 +02:00
using pajlada::Settings::Setting<Type>::operator const Type;
2017-12-31 00:50:07 +01:00
};
using BoolSetting = ChatterinoSetting<bool>;
using FloatSetting = ChatterinoSetting<float>;
using IntSetting = ChatterinoSetting<int>;
using StringSetting = ChatterinoSetting<std::string>;
using QStringSetting = ChatterinoSetting<QString>;
} // namespace chatterino