SH4ZAM! 0.7.0
Fast math library for the Sega Dreamcast's SH4 CPU
Loading...
Searching...
No Matches
shz_version.hpp
Go to the documentation of this file.
1/*! \file
2 * \brief Compile-Time API Versioning
3 *
4 * This file provides the utility macros and constants needed for implementing
5 * compile/link-time version checking of the SH4ZAM library using C++.
6 *
7 * \author 2026 Falco Girgis
8 * \copyright MIT License
9 */
10
11#ifndef SHZ_VERSION_HPP
12#define SHZ_VERSION_HPP
13
14#include "shz_version.h"
15
16#include <string>
17
18namespace shz {
19
20 //! Class representing a full SH4ZAM API version.
21 class version {
22 shz_version_t value_; //!< Private packed value member.
23
24 public:
25 //! Constructs a version from the given full value.
26 constexpr version(shz_version_t value) noexcept:
27 value_(value) {}
28
29 //! Constructs a full version from the given component values.
30 constexpr version(uint8_t major, uint16_t minor, uint8_t patch) noexcept:
31 version(SHZ_VERSION_INIT(major, minor, patch)) {}
32
33 //! Compile-time version of SH4ZAM headers which are being included.
34 constexpr static version compiled() noexcept { return SHZ_VERSION; }
35
36 //! Link-time version of SH4ZAM library which was linked against.
37 static version linked() noexcept { return shz_version_linked(); }
38
39 //! Implicit conversion operator to make this class automatically comparable to a `uint32_t`.
40 constexpr operator shz_version_t() const noexcept { return value_; }
41
42 //! Assignment operator for assigning a version to a full version ID value.
43 constexpr version operator=(uint32_t rhs) noexcept { value_ = rhs; return *this; }
44
45 //! Extracts the major component value from a full version.
46 constexpr uint8_t major() const noexcept { return (value_ >> 24) & 0xff; }
47
48 //! Extracts the minor component value from a full version.
49 constexpr uint16_t minor() const noexcept { return (value_ >> 8) & 0xffff; }
50
51 //! Extracts the patch component value from a full version.
52 constexpr uint8_t patch() const noexcept { return value_ & 0xff; }
53 };
54
55 //! Alias for those who prefer POSIX-style.
56 using version_t = version;
57}
58
59#endif
Class representing a full SH4ZAM API version.
constexpr uint8_t major() const noexcept
Extracts the major component value from a full version.
static constexpr version compiled() noexcept
Compile-time version of SH4ZAM headers which are being included.
constexpr version operator=(uint32_t rhs) noexcept
Assignment operator for assigning a version to a full version ID value.
constexpr uint8_t patch() const noexcept
Extracts the patch component value from a full version.
constexpr operator shz_version_t() const noexcept
Implicit conversion operator to make this class automatically comparable to a uint32_t.
constexpr uint16_t minor() const noexcept
Extracts the minor component value from a full version.
static version linked() noexcept
Link-time version of SH4ZAM library which was linked against.
constexpr version(uint8_t major, uint16_t minor, uint8_t patch) noexcept
Constructs a full version from the given component values.
constexpr version(shz_version_t value) noexcept
Constructs a version from the given full value.
Namespace enclosing the SH4ZAM C++ API.
Definition shz_cdefs.hpp:21
#define SHZ_VERSION_INIT(major, minor, patch)
Packs values of individual version components into a SH4ZAM full version value.
Definition shz_version.h:44
#define SHZ_VERSION
Current SH4ZAM full compile-time version identifier, integer-compatible.
Definition shz_version.h:30
shz_version_t shz_version_linked(void)
Returns the full version of SH4ZAM that was linked against.
uint32_t shz_version_t
Integer-compatible value type containing a full SH4ZAM version.
Definition shz_version.h:55