JustEnoughMod
Loading...
Searching...
No Matches
Version.hpp
1#ifndef UTIL_VERSION_HPP
2#define UTIL_VERSION_HPP
3
4#include <util/Util.hpp>
5
6#include <string>
7
8namespace JEM {
9 class Version {
10 public:
11 explicit operator std::string() const {
12 return std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(patch);
13 }
14
15 Version() = default;
16
17 Version(int maj, int min, int pat) : major(maj), minor(min), patch(pat) {}
18
19 consteval explicit Version(const char *str) : major(0), minor(0), patch(0) {
20
21 const char *token = str;
22 if (*token == '\0') {
23 return;
24 }
25
26 major = atoi(token);
27
28 do {
29 ++token;
30 if (*token == '\0') {
31 return;
32 }
33 } while (*(token - 1) != '.');
34
35 minor = atoi(token);
36
37 do {
38 ++token;
39 if (*token == '\0') {
40 return;
41 }
42 } while (*(token - 1) != '.');
43
44 patch = atoi(token);
45 }
46
47 private:
48 int major;
49 int minor;
50 int patch;
51 };
52} // namespace JEM
53
54#endif
Definition Version.hpp:9
Definition Queue.hpp:11