Back to home page

EIC code displayed by LXR

 
 

    


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 // Some preprocessor constants and macros for the use cases where they might be
0012 // necessary
0013 
0014 /// Define a version to be used in edm4hep.
0015 #define EDM4HEP_VERSION(major, minor, patch) ((UINT64_C(major) << 32) | (UINT64_C(minor) << 16) | (UINT64_C(patch)))
0016 /// Get the major version from a preprocessor defined version
0017 #define EDM4HEP_MAJOR_VERSION(v) (((v) & (-1UL >> 16)) >> 32)
0018 /// Get the minor version from a preprocessor defined version
0019 #define EDM4HEP_MINOR_VERSION(v) (((v) & (-1UL >> 32)) >> 16)
0020 /// Get the patch version from a preprocessor defined version
0021 #define EDM4HEP_PATCH_VERSION(v) ((v) & (-1UL >> 48))
0022 
0023 // Some helper constants that are populated by the cmake configure step
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 /// The encoded version with which edm4hep has been built
0030 #define EDM4HEP_BUILD_VERSION EDM4HEP_VERSION(EDM4HEP_VERSION_MAJOR, EDM4HEP_VERSION_MINOR, EDM4HEP_VERSION_PATCH)
0031 
0032 namespace edm4hep::version {
0033 
0034   /**
0035    * Version class consisting of 3 16 bit unsigned integers to hold the major,
0036    * minor and patch version. Provides constexpr comparison operators that allow
0037    * to use this class in constexpr-if clauses.
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 // No spaceship yet in c++17
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    * The current build version
0072    */
0073   static constexpr Version build_version{EDM4HEP_VERSION_MAJOR, EDM4HEP_VERSION_MINOR, EDM4HEP_VERSION_PATCH};
0074 
0075   /**
0076    * Decode a version from a 64 bit unsigned
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