File indexing completed on 2025-01-18 10:06:09
0001 #ifndef PODIO_PODIOVERSION_H
0002 #define PODIO_PODIOVERSION_H
0003
0004 #include <cstdint>
0005 #include <ostream>
0006 #include <sstream>
0007 #include <tuple>
0008 #if __cplusplus >= 202002L
0009 #include <compare>
0010 #endif
0011
0012
0013
0014
0015
0016 #define PODIO_VERSION(major, minor, patch) \
0017 ((UINT64_C(major) << 32) | (UINT64_C(minor) << 16) | UINT64_C(patch))
0018
0019 #define PODIO_MAJOR_VERSION(v) (((v) & (-1UL >> 16)) >> 32)
0020
0021 #define PODIO_MINOR_VERSION(v) (((v) & (-1UL >> 32)) >> 16)
0022
0023 #define PODIO_PATCH_VERSION(v) ((v) & (-1UL >> 48))
0024
0025
0026 #define podio_VERSION_MAJOR 1
0027 #define podio_VERSION_MINOR 1
0028 #define podio_VERSION_PATCH 0
0029 #define podio_VERSION PODIO_VERSION(podio_VERSION_MAJOR, podio_VERSION_MINOR, podio_VERSION_PATCH)
0030
0031
0032 #define PODIO_BUILD_VERSION PODIO_VERSION(podio_VERSION_MAJOR, podio_VERSION_MINOR, podio_VERSION_PATCH)
0033
0034 namespace podio::version {
0035
0036
0037
0038
0039 struct Version {
0040 uint16_t major{0};
0041 uint16_t minor{0};
0042 uint16_t patch{0};
0043
0044
0045
0046
0047 #define DEFINE_COMP_OPERATOR(OP) \
0048 constexpr bool operator OP(const Version& o) const noexcept { \
0049 return std::tie(major, minor, patch) OP std::tie(o.major, o.minor, o.patch); \
0050 }
0051
0052 DEFINE_COMP_OPERATOR(<)
0053 DEFINE_COMP_OPERATOR(<=)
0054 DEFINE_COMP_OPERATOR(>)
0055 DEFINE_COMP_OPERATOR(>=)
0056 DEFINE_COMP_OPERATOR(==)
0057 DEFINE_COMP_OPERATOR(!=)
0058
0059 #undef DEFINE_COMP_OPERATOR
0060
0061 explicit operator std::string() const {
0062 std::stringstream ss;
0063 ss << *this;
0064 return ss.str();
0065 }
0066
0067 friend std::ostream& operator<<(std::ostream&, const Version& v);
0068 };
0069
0070 inline std::ostream& operator<<(std::ostream& os, const Version& v) {
0071 return os << v.major << "." << v.minor << "." << v.patch;
0072 }
0073
0074
0075 static constexpr Version build_version{podio_VERSION_MAJOR, podio_VERSION_MINOR, podio_VERSION_PATCH};
0076
0077
0078 static constexpr Version decode_version(unsigned long version) noexcept {
0079 return Version{static_cast<uint16_t>(PODIO_MAJOR_VERSION(version)),
0080 static_cast<uint16_t>(PODIO_MINOR_VERSION(version)),
0081 static_cast<uint16_t>(PODIO_PATCH_VERSION(version))};
0082 }
0083 }
0084
0085 #endif