summaryrefslogtreecommitdiffstats
path: root/api/logic/DefaultVariable.h
blob: 5c069bd38544974cbdb8f6c0be7c34a95777a289 (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;
};