blob: 0112105a3bfa8429d0eade976bfda54d298885e7 (
plain) (
blame)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
#pragma once
#include "yql_panic.h"
#include <util/generic/maybe.h>
#include <util/generic/variant.h>
namespace NYql {
template <typename S, typename R>
class TResetableSettingBase {
protected:
using TSet = S;
using TReset = R;
public:
void Set(const TSet& value) {
Value.ConstructInPlace(value);
}
void Reset(const TReset& value) {
Value.ConstructInPlace(value);
}
bool Defined() const {
return Value.Defined();
}
explicit operator bool() const {
return Defined();
}
bool IsSet() const {
YQL_ENSURE(Defined());
return Value->index() == 0;
}
const TSet& GetValueSet() const {
YQL_ENSURE(IsSet());
return std::get<TSet>(*Value);
}
const TReset& GetValueReset() const {
YQL_ENSURE(!IsSet());
return std::get<TReset>(*Value);
}
private:
TMaybe<std::variant<TSet, TReset>> Value;
};
template <typename S, typename R>
class TResetableSetting: public TResetableSettingBase<S, R> {
};
template <typename S>
class TResetableSetting<S, void>: public TResetableSettingBase<S, TNothing> {
private:
const TNothing& GetValueReset() const;
public:
void Reset() {
TResetableSettingBase<S, TNothing>::Reset(Nothing());
}
};
}
|