File indexing completed on 2025-09-16 08:52:44
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include <array>
0010 #include <cstdlib> // IWYU pragma: keep
0011 #include <iosfwd>
0012 #include <string>
0013 #include <string_view>
0014
0015
0016 #ifdef major
0017 # undef major
0018 #endif
0019 #ifdef minor
0020 # undef minor
0021 #endif
0022
0023 namespace celeritas
0024 {
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039 class Version
0040 {
0041 public:
0042
0043
0044 using size_type = unsigned int;
0045 using ArrayT = std::array<size_type, 3>;
0046
0047
0048 public:
0049
0050 static Version from_string(std::string_view sv);
0051
0052
0053 static inline constexpr Version from_hex_xxyyzz(size_type value);
0054
0055
0056 static inline constexpr Version from_dec_xyz(size_type value);
0057
0058
0059 inline constexpr Version(size_type major,
0060 size_type minor = 0,
0061 size_type patch = 0);
0062
0063
0064
0065
0066
0067 constexpr ArrayT const& value() const { return version_; }
0068
0069
0070 constexpr size_type major() const { return version_[0]; }
0071
0072
0073 constexpr size_type minor() const { return version_[1]; }
0074
0075
0076 constexpr size_type patch() const { return version_[2]; }
0077
0078
0079
0080 private:
0081 ArrayT version_;
0082 };
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093 constexpr Version Version::from_hex_xxyyzz(size_type value)
0094 {
0095 return {(value >> 16 & 0xffu), (value >> 8 & 0xffu), (value & 0xffu)};
0096 }
0097
0098
0099
0100
0101
0102
0103
0104 constexpr Version Version::from_dec_xyz(size_type value)
0105 {
0106 return {(value / 100), (value / 10) % 10, value % 10};
0107 }
0108
0109
0110
0111
0112
0113 constexpr Version::Version(size_type major, size_type minor, size_type patch)
0114 : version_{{major, minor, patch}}
0115 {
0116 }
0117
0118
0119
0120
0121
0122 #define CELER_DEFINE_VERSION_CMP(TOKEN) \
0123 inline bool operator TOKEN(Version const& lhs, Version const& rhs) \
0124 { \
0125 return lhs.value() TOKEN rhs.value(); \
0126 }
0127
0128 CELER_DEFINE_VERSION_CMP(==)
0129 CELER_DEFINE_VERSION_CMP(!=)
0130 CELER_DEFINE_VERSION_CMP(<)
0131 CELER_DEFINE_VERSION_CMP(>)
0132 CELER_DEFINE_VERSION_CMP(<=)
0133 CELER_DEFINE_VERSION_CMP(>=)
0134
0135 #undef CELER_DEFINE_VERSION_CMP
0136
0137
0138 std::ostream& operator<<(std::ostream&, Version const&);
0139
0140
0141 std::string to_string(Version const&);
0142
0143
0144 Version celer_version();
0145
0146
0147 }