summaryrefslogtreecommitdiffstats
path: root/api/logic/DefaultVariable.h
blob: 38d7ecc2928c95f6862526a8ea42baffa46a56ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#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;
};