Variant.cpp
2.85 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include "Variant.h"
using namespace osdev::components;
Variant::Type Variant::getType()
{
if(std::holds_alternative<bool>(m_variable))
{
return Variant::Type::Bool;
}
else if(std::holds_alternative<int>(m_variable))
{
return Variant::Type::Int;
}
else if(std::holds_alternative<double>(m_variable))
{
return Variant::Type::Double;
}
else if(std::holds_alternative<float>(m_variable))
{
return Variant::Type::Float;
}
else if(std::holds_alternative<char>(m_variable))
{
return Variant::Type::Char;
}
else if(std::holds_alternative<std::string>(m_variable))
{
return Variant::Type::String;
}
else if(std::holds_alternative<uint8_t>(m_variable))
{
return Variant::Type::UInt8;
}
else if(std::holds_alternative<uint16_t>(m_variable))
{
return Variant::Type::UInt16;
}
else if(std::holds_alternative<uint64_t>(m_variable))
{
return Variant::Type::UInt64;
}
return Variant::Type::Invalid;
}
bool Variant::CanConvert(Variant::Type typeWanted)
{
switch(typeWanted)
{
case Variant::Bool:
{
return std::holds_alternative<bool>(m_variable);
}
case Variant::Int:
{
return std::holds_alternative<int>(m_variable);
}
case Variant::Double:
{
return std::holds_alternative<double>(m_variable);
}
case Variant::Float:
{
return std::holds_alternative<float>(m_variable);
}
case Variant::Char:
{
return std::holds_alternative<char>(m_variable);
}
case Variant::String:
{
return std::holds_alternative<std::string>(m_variable);
}
case Variant::UInt8:
{
return std::holds_alternative<uint8_t>(m_variable);
}
case Variant::UInt16:
{
return std::holds_alternative<uint16_t>(m_variable);
}
case Variant::UInt64:
{
return std::holds_alternative<uint64_t>(m_variable);
}
case Variant::Invalid:
{
return false;
}
}
return false;
}
bool Variant::toBool()
{
return std::get<bool>(m_variable);
}
int Variant::toInt()
{
return std::get<int>(m_variable);
}
double Variant::toDouble()
{
return std::get<double>(m_variable);
}
float Variant::toFloat()
{
return std::get<float>(m_variable);
}
char Variant::toChar()
{
return std::get<char>(m_variable);
}
std::string Variant::toString()
{
return std::get<std::string>(m_variable);
}
uint8_t Variant::toUInt8()
{
return std::get<uint8_t>(m_variable);
}
uint16_t Variant::toUInt16()
{
return std::get<uint16_t>(m_variable);
}
uint64_t Variant::toUInt64()
{
return std::get<uint64_t>(m_variable);
}