-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalue.h
More file actions
48 lines (43 loc) · 879 Bytes
/
value.h
File metadata and controls
48 lines (43 loc) · 879 Bytes
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
#ifndef VALUE_H
#define VALUE_H
class Value {
public:
enum Type {
NUL, NUM, STRING, BOOL
};
Value(double d) : val{ d }, valType{ Type::NUM }
{ }
Value(std::string s) : val{ s }, valType{ Type::STRING }
{ }
Value(bool b) : val{ b }, valType{ Type::BOOL }
{ }
Value() : val{ std::monostate{} }, valType{ Type::NUL }
{ }
auto getVal() {
return val;
}
Type getType() {
return valType;
}
friend std::ostream& operator<<(std::ostream& out, Value val) {
switch (val.getType()) {
case Type::NUM:
out << std::get<double>(val.getVal());
break;
case Type::STRING:
out << std::get<std::string>(val.getVal());
break;
case Type::NUL:
out << "NULL";
break;
case Type::BOOL:
out << std::get<bool>(val.getVal());
break;
}
return out;
}
private:
std::variant<std::monostate, double, std::string, bool> val;
Type valType;
};
#endif