This repository has been archived by the owner on Jul 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.cpp
166 lines (134 loc) · 3.84 KB
/
version.cpp
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include "version.h"
VRCE::Version VRCE::Version::Parse(const std::string &versionString)
{
if (versionString.empty())
{
throw "Invalid version number" + versionString;
}
int major = 0;
int minor = 0;
int build = 0;
VersionType versionType = VersionType::Final;
int typeNumber = 0;
std::size_t idx = 0;
while (true) {
if (idx >= versionString.size()) {
throw "Invalid version format";
}
char c = versionString[idx++];
if (c == '.') {
break;
}
major = major * 10 + (int)(c - '0');
}
while (true) {
if (idx >= versionString.size()) {
break;
}
char c = versionString[idx++];
if (c == '.') {
break;
}
minor = minor * 10 + (int)(c - '0');
}
while (true) {
if (idx >= versionString.size()) {
break;
}
char c = versionString[idx++];
if (c >= '0' && c <= '9') {
build = build * 10 + (int)(c - '0');
}
else
{
switch (c)
{
case 'a':
versionType = VersionType::Alpha;
break;
case 'b':
versionType = VersionType::Beta;
break;
case 'p':
versionType = VersionType::Patch;
break;
case 'f':
versionType = VersionType::Final;
break;
default:
{
std::string err;
err.resize(40);
snprintf(err.data(), err.size(), "Unsupported version type %c for version ", c);
throw err + versionString;
}
}
break;
}
}
while (true) {
if (idx >= versionString.size()) {
break;
}
char c = versionString[idx++];
typeNumber = typeNumber * 10 + (int)(c - '0');
}
return Version(major, minor, build, versionType, typeNumber);
}
VRCE::Version::Version()
: m_data(0)
{
}
VRCE::Version::Version(std::uint16_t major)
: m_data((std::uint64_t)major << 48)
{
}
VRCE::Version::Version(std::uint16_t major, std::uint8_t minor)
: m_data(((std::uint64_t)major << 48) | ((std::uint64_t)minor << 40))
{
}
VRCE::Version::Version(std::uint16_t major, std::uint8_t minor, std::uint8_t build)
: m_data(((std::uint64_t)major << 48) | ((std::uint64_t)minor << 40) | ((std::uint64_t)build << 32))
{
}
VRCE::Version::Version(std::uint16_t major, std::uint8_t minor, std::uint8_t build, VersionType type)
: m_data(((std::uint64_t)major << 48) | ((std::uint64_t)minor << 40) | ((std::uint64_t)build << 32) | ((std::uint64_t)type << 24))
{
}
VRCE::Version::Version(std::uint16_t major, std::uint8_t minor, std::uint8_t build, VersionType type, std::uint8_t typeNumber)
: m_data(((std::uint64_t)major << 48) | ((std::uint64_t)minor << 40) | ((std::uint64_t)build << 32) | ((std::uint64_t)type << 24) | ((std::uint64_t)typeNumber << 16))
{
}
VRCE::Version::Version(const VRCE::Version& other)
: m_data(other.m_data)
{
}
std::uint16_t VRCE::Version::major() const noexcept
{
return (m_data >> 48) & 0xFFFFull;
}
std::uint8_t VRCE::Version::minor() const noexcept
{
return (m_data >> 40) & 0xFFull;
}
std::uint8_t VRCE::Version::build() const noexcept
{
return (m_data >> 32) & 0xFFull;
}
VRCE::VersionType VRCE::Version::type() const noexcept
{
return (VersionType)((m_data >> 24) & 0xFFull);
}
std::uint8_t VRCE::Version::typeNumber() const noexcept
{
return (m_data >> 16) & 0xFFull;
}
std::string VRCE::Version::toString() const
{
return "";
}
VRCE::Version& VRCE::Version::operator=(const VRCE::Version& other)
{
m_data = other.m_data;
return *this;
}