Blame view

src/Variant.cpp 2.85 KB
de402313   Peter M. Groen   Implementation of...
1
2
3
4
  #include "Variant.h"
  
  using namespace osdev::components;
  
a6b8531d   Peter M. Groen   Implemented the V...
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
  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;
      }
de402313   Peter M. Groen   Implementation of...
43
  
a6b8531d   Peter M. Groen   Implemented the V...
44
      return Variant::Type::Invalid;
de402313   Peter M. Groen   Implementation of...
45
46
  }
  
a6b8531d   Peter M. Groen   Implemented the V...
47
  bool Variant::CanConvert(Variant::Type typeWanted)
de402313   Peter M. Groen   Implementation of...
48
  {
a6b8531d   Peter M. Groen   Implemented the V...
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
      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;
de402313   Peter M. Groen   Implementation of...
93
94
  }
  
a6b8531d   Peter M. Groen   Implemented the V...
95
  bool Variant::toBool()
de402313   Peter M. Groen   Implementation of...
96
  {
a6b8531d   Peter M. Groen   Implemented the V...
97
      return std::get<bool>(m_variable);
de402313   Peter M. Groen   Implementation of...
98
99
  }
  
a6b8531d   Peter M. Groen   Implemented the V...
100
  int Variant::toInt()
de402313   Peter M. Groen   Implementation of...
101
  {
a6b8531d   Peter M. Groen   Implemented the V...
102
      return std::get<int>(m_variable);
de402313   Peter M. Groen   Implementation of...
103
104
  }
  
a6b8531d   Peter M. Groen   Implemented the V...
105
  double Variant::toDouble()
de402313   Peter M. Groen   Implementation of...
106
  {
a6b8531d   Peter M. Groen   Implemented the V...
107
      return std::get<double>(m_variable);
de402313   Peter M. Groen   Implementation of...
108
109
  }
  
a6b8531d   Peter M. Groen   Implemented the V...
110
  float Variant::toFloat()
de402313   Peter M. Groen   Implementation of...
111
  {
a6b8531d   Peter M. Groen   Implemented the V...
112
      return std::get<float>(m_variable);
de402313   Peter M. Groen   Implementation of...
113
114
  }
  
a6b8531d   Peter M. Groen   Implemented the V...
115
  char Variant::toChar()
de402313   Peter M. Groen   Implementation of...
116
  {
a6b8531d   Peter M. Groen   Implemented the V...
117
      return std::get<char>(m_variable);
de402313   Peter M. Groen   Implementation of...
118
119
  }
  
a6b8531d   Peter M. Groen   Implemented the V...
120
  std::string Variant::toString()
de402313   Peter M. Groen   Implementation of...
121
  {
a6b8531d   Peter M. Groen   Implemented the V...
122
      return std::get<std::string>(m_variable);
de402313   Peter M. Groen   Implementation of...
123
124
  }
  
a6b8531d   Peter M. Groen   Implemented the V...
125
  uint8_t Variant::toUInt8()
de402313   Peter M. Groen   Implementation of...
126
  {
a6b8531d   Peter M. Groen   Implemented the V...
127
      return std::get<uint8_t>(m_variable);
de402313   Peter M. Groen   Implementation of...
128
129
  }
  
a6b8531d   Peter M. Groen   Implemented the V...
130
  uint16_t Variant::toUInt16()
de402313   Peter M. Groen   Implementation of...
131
  {
a6b8531d   Peter M. Groen   Implemented the V...
132
      return std::get<uint16_t>(m_variable);
de402313   Peter M. Groen   Implementation of...
133
134
  }
  
a6b8531d   Peter M. Groen   Implemented the V...
135
  uint64_t Variant::toUInt64()
de402313   Peter M. Groen   Implementation of...
136
  {
a6b8531d   Peter M. Groen   Implemented the V...
137
      return std::get<uint64_t>(m_variable);
de402313   Peter M. Groen   Implementation of...
138
  }