libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal_version.hpp
1#ifndef GIMBAL_VERSION_HPP
2#define GIMBAL_VERSION_HPP
3
5
6namespace gbl {
7
8class Version {
9private:
10 GblVersion version_ = 0;
11
12public:
13 constexpr Version(uint8_t major = 0,
14 uint16_t minor = 0,
15 uint8_t patch = 0) noexcept:
16 version_(GBL_VERSION_MAKE_(major, minor, patch)) {}
17
18 constexpr Version(GblVersion version) noexcept:
19 version_(version) {}
20
21 Version(const char* pString) {
22 // check for errors, throw exception
23 version_ = GblVersion_parse(pString);
24 }
25
26 constexpr uint8_t major() const noexcept { return (version_ >> GBL_VERSION_MAJOR_BITPOS) & GBL_VERSION_MAJOR_MASK; }
27 constexpr uint16_t minor() const noexcept { return (version_ >> GBL_VERSION_MINOR_BITPOS) & GBL_VERSION_MINOR_MASK; }
28 constexpr uint8_t patch() const noexcept { return (version_ >> GBL_VERSION_PATCH_BITPOS) & GBL_VERSION_PATCH_MASK; }
29
30 constexpr void setMajor(uint8_t major) noexcept {
32 version_ |= (major << GBL_VERSION_MAJOR_BITPOS);
33 }
34
35 constexpr void setMinor(uint16_t minor) noexcept {
37 version_ |= (minor << GBL_VERSION_MINOR_BITPOS);
38 }
39
40 constexpr void setPatch(uint16_t patch) noexcept {
42 version_ |= (patch << GBL_VERSION_PATCH_BITPOS);
43 }
44
45 constexpr operator GblVersion() const noexcept { return version_; }
46
47};
48
49static_assert(sizeof(Version) == sizeof(GblVersion),
50 "C++ Version incompatiblly sized with C version!");
51}
52
53#endif // GIMBAL_VERSION_HPP
#define GBL_VERSION_MINOR_BITPOS
Bit position of the MINOR field.
#define GBL_VERSION_MINOR_MASK
Bit mask of the MINOR field.
GblVersion GblVersion_parse(const char *pString)
Parses and returns a GblVersion from an encoded version string in the format "MAJOR....
#define GBL_VERSION_PATCH_MASK
Bit mask of the PATCH field.
#define GBL_VERSION_MAJOR_BITPOS
Bit position of the MAJOR field.
#define GBL_VERSION_MAJOR_MASK
Bit mask of the MAJOR field.
#define GBL_VERSION_PATCH_BITPOS
Bit position of the PATCH field.
uint32_t GblVersion
32-bit unsigned integer representing a packed version in the form (MAJOR.MINOR.PATCH)