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