mirror of
https://github.com/MultiMC/MultiMC5.git
synced 2024-11-20 08:10:11 +00:00
36 lines
687 B
C++
36 lines
687 B
C++
#pragma once
|
|
|
|
template <typename T>
|
|
class DefaultVariable
|
|
{
|
|
public:
|
|
DefaultVariable(const T & value)
|
|
{
|
|
defaultValue = value;
|
|
}
|
|
DefaultVariable<T> & operator =(const T & value)
|
|
{
|
|
currentValue = value;
|
|
is_default = currentValue == defaultValue;
|
|
is_explicit = true;
|
|
return *this;
|
|
}
|
|
operator const T &() const
|
|
{
|
|
return is_default ? defaultValue : currentValue;
|
|
}
|
|
bool isDefault() const
|
|
{
|
|
return is_default;
|
|
}
|
|
bool isExplicit() const
|
|
{
|
|
return is_explicit;
|
|
}
|
|
private:
|
|
T currentValue;
|
|
T defaultValue;
|
|
bool is_default = true;
|
|
bool is_explicit = false;
|
|
};
|