File indexing completed on 2025-01-18 09:55:35
0001 #ifndef EDM4HEP_VERSION_H
0002 #define EDM4HEP_VERSION_H
0003
0004 #include <cstdint>
0005 #include <tuple>
0006 #include <ostream>
0007 #if __cplusplus >= 202002L
0008 #include <compare>
0009 #endif
0010
0011
0012
0013
0014
0015 #define EDM4HEP_VERSION(major, minor, patch) ((UINT64_C(major) << 32) | (UINT64_C(minor) << 16) | (UINT64_C(patch)))
0016
0017 #define EDM4HEP_MAJOR_VERSION(v) (((v) & (-1UL >> 16)) >> 32)
0018
0019 #define EDM4HEP_MINOR_VERSION(v) (((v) & (-1UL >> 32)) >> 16)
0020
0021 #define EDM4HEP_PATCH_VERSION(v) ((v) & (-1UL >> 48))
0022
0023
0024 #define EDM4HEP_VERSION_MAJOR 0
0025 #define EDM4HEP_VERSION_MINOR 10
0026 #define EDM4HEP_VERSION_PATCH 5
0027 #define edm4hep_VERSION EDM4HEP_VERSION(EDM4HEP_VERSION_MAJOR, EDM4HEP_VERSION_MINOR, EDM4HEP_VERSION_PATCH)
0028
0029
0030 #define EDM4HEP_BUILD_VERSION EDM4HEP_VERSION(EDM4HEP_VERSION_MAJOR, EDM4HEP_VERSION_MINOR, EDM4HEP_VERSION_PATCH)
0031
0032 namespace edm4hep::version {
0033
0034
0035
0036
0037
0038
0039 struct Version {
0040 uint16_t major{0};
0041 uint16_t minor{0};
0042 uint16_t patch{0};
0043
0044 #if __cplusplus >= 202002L
0045 auto operator<=>(const Version&) const = default;
0046 #else
0047
0048 #define DEFINE_COMP_OPERATOR(OP) \
0049 constexpr bool operator OP(const Version& o) const noexcept { \
0050 return std::tie(major, minor, patch) OP std::tie(o.major, o.minor, o.patch); \
0051 }
0052
0053 DEFINE_COMP_OPERATOR(<)
0054 DEFINE_COMP_OPERATOR(<=)
0055 DEFINE_COMP_OPERATOR(>)
0056 DEFINE_COMP_OPERATOR(>=)
0057 DEFINE_COMP_OPERATOR(==)
0058 DEFINE_COMP_OPERATOR(!=)
0059
0060 #undef DEFINE_COMP_OPERATOR
0061 #endif
0062
0063 friend std::ostream& operator<<(std::ostream&, const Version& v);
0064 };
0065
0066 inline std::ostream& operator<<(std::ostream& os, const Version& v) {
0067 return os << v.major << "." << v.minor << "." << v.patch;
0068 }
0069
0070
0071
0072
0073 static constexpr Version build_version{EDM4HEP_VERSION_MAJOR, EDM4HEP_VERSION_MINOR, EDM4HEP_VERSION_PATCH};
0074
0075
0076
0077
0078 static constexpr Version decode_version(uint64_t version) noexcept {
0079 return Version{
0080 (uint16_t) EDM4HEP_MAJOR_VERSION(version),
0081 (uint16_t) EDM4HEP_MINOR_VERSION(version),
0082 (uint16_t) EDM4HEP_PATCH_VERSION(version)
0083 };
0084 }
0085 }
0086
0087
0088 #endif