a6b8531d
Peter M. Groen
Implemented the V...
|
1
|
#pragma once
|
de402313
Peter M. Groen
Implementation of...
|
2
|
|
a6b8531d
Peter M. Groen
Implemented the V...
|
3
|
#include <cstdint>
|
de402313
Peter M. Groen
Implementation of...
|
4
|
#include <string>
|
a6b8531d
Peter M. Groen
Implemented the V...
|
5
6
|
#include <variant>
|
de402313
Peter M. Groen
Implementation of...
|
7
|
namespace osdev::components {
|
a6b8531d
Peter M. Groen
Implemented the V...
|
8
|
|
de402313
Peter M. Groen
Implementation of...
|
9
10
11
12
13
14
|
class Variant
{
public:
enum Type {
Invalid, // Unknown
Bool, // bool
|
de402313
Peter M. Groen
Implementation of...
|
15
16
17
18
19
20
|
Double, // double
Float, // float
Char, // char
String, // std::string
UInt8, // uint8_t
UInt16, // uint16_t
|
de402313
Peter M. Groen
Implementation of...
|
21
|
UInt64, // uint64_t
|
a6b8531d
Peter M. Groen
Implemented the V...
|
22
|
Int // int -->> Size determined by platform and compiler
|
de402313
Peter M. Groen
Implementation of...
|
23
24
25
|
};
/*!
|
a6b8531d
Peter M. Groen
Implemented the V...
|
26
27
|
* All Constructors available.
* The type of the argument determines the internal type of the variant
|
de402313
Peter M. Groen
Implementation of...
|
28
|
*/
|
a6b8531d
Peter M. Groen
Implemented the V...
|
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
|
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;
|
de402313
Peter M. Groen
Implementation of...
|
67
68
|
};
|
a6b8531d
Peter M. Groen
Implemented the V...
|
69
|
} /* End namespace osdev::components */
|