Variant.h
1.91 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
#pragma once
#include <cstdint>
#include <string>
#include <variant>
namespace osdev::components {
class Variant
{
public:
enum Type {
Invalid, // Unknown
Bool, // bool
Double, // double
Float, // float
Char, // char
String, // std::string
UInt8, // uint8_t
UInt16, // uint16_t
UInt64, // uint64_t
Int // int -->> Size determined by platform and compiler
};
/*!
* All Constructors available.
* The type of the argument determines the internal type of the variant
*/
Variant() : m_variable() {};
Variant(bool value) : m_variable(value) {};
Variant(int value) : m_variable(value) {};
Variant(double value) : m_variable(value) {};
Variant(float value) : m_variable(value) {};
Variant(char value) : m_variable(value) {};
Variant(std::string value) : m_variable(value) {};
Variant(uint8_t value) : m_variable(value) {};
Variant(uint16_t value) : m_variable(value) {};
Variant(uint64_t value) : m_variable(value) {};
/// Return the type of the value stored in this variant
Variant::Type getType();
/// Check to see if the value can be converted to the desired type.
/// @param - The requested type as an enum
/// @return - true if the conversion can happen. False if not.
bool CanConvert(Variant::Type typeWanted);
bool toBool();
double toDouble();
float toFloat();
char toChar();
std::string toString();
int toInt();
uint8_t toUInt8();
uint16_t toUInt16();
uint64_t toUInt64();
private:
std::variant<bool, int,
double, float,
char, std::string,
uint8_t, uint16_t,
uint64_t> m_variable;
};
} /* End namespace osdev::components */