-
Notifications
You must be signed in to change notification settings - Fork 22
/
Value.hpp
74 lines (57 loc) · 1.52 KB
/
Value.hpp
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
#pragma once
#include <cstdint>
#include "StringTable.hpp"
namespace Pex {
/**
* @brief Types managed in the Value class.
*/
enum class ValueType : std::uint8_t
{
None = 0,
Identifier = 1,
String = 2,
Integer = 3,
Float = 4,
Bool = 5
};
/**
* @brief Variant class managing value.
*/
class Value
{
public:
Value();
explicit Value(const StringTable::Index& value, bool id = false);
explicit Value(std::int32_t value);
explicit Value(float value);
explicit Value(bool value);
~Value();
ValueType getType() const;
bool isNone() const;
void clear();
StringTable::Index getId() const;
void setId(const StringTable::Index& value);
StringTable::Index getString() const;
void set(const StringTable::Index& value);
std::int32_t getInteger() const;
void set(std::int32_t value);
float getFloat() const;
void set(float value);
bool getBool() const;
void set(bool value);
bool operator==(const Value& rhs) const;
std::string toString() const;
protected:
ValueType m_Type;
union {
struct {
const StringTable* table;
std::uint16_t index;
} string;
std::int32_t integer;
float real;
bool boolean;
} m_Value;
void ensureType(ValueType type) const;
};
}