Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-01 08:35:23

0001 #ifndef EDM4HEP_VERSION_H
0002 #define EDM4HEP_VERSION_H
0003 
0004 #include <cstdint>
0005 #include <ostream>
0006 // Some preprocessor constants and macros for the use cases where they might be
0007 // necessary
0008 
0009 /// Define a version to be used in edm4hep.
0010 #define EDM4HEP_VERSION(major, minor, patch) ((UINT64_C(major) << 32) | (UINT64_C(minor) << 16) | (UINT64_C(patch)))
0011 /// Get the major version from a preprocessor defined version
0012 #define EDM4HEP_MAJOR_VERSION(v) (((v) & (-1UL >> 16)) >> 32)
0013 /// Get the minor version from a preprocessor defined version
0014 #define EDM4HEP_MINOR_VERSION(v) (((v) & (-1UL >> 32)) >> 16)
0015 /// Get the patch version from a preprocessor defined version
0016 #define EDM4HEP_PATCH_VERSION(v) ((v) & (-1UL >> 48))
0017 
0018 // Some helper constants that are populated by the cmake configure step
0019 #define EDM4HEP_VERSION_MAJOR 0
0020 #define EDM4HEP_VERSION_MINOR 99
0021 #define EDM4HEP_VERSION_PATCH 1
0022 #define edm4hep_VERSION EDM4HEP_VERSION(EDM4HEP_VERSION_MAJOR, EDM4HEP_VERSION_MINOR, EDM4HEP_VERSION_PATCH)
0023 
0024 /// The encoded version with which edm4hep has been built
0025 #define EDM4HEP_BUILD_VERSION EDM4HEP_VERSION(EDM4HEP_VERSION_MAJOR, EDM4HEP_VERSION_MINOR, EDM4HEP_VERSION_PATCH)
0026 
0027 namespace edm4hep::version {
0028 
0029   /**
0030    * Version class consisting of 3 16 bit unsigned integers to hold the major,
0031    * minor and patch version. Provides constexpr comparison operators that allow
0032    * to use this class in constexpr-if clauses.
0033    */
0034   struct Version {
0035     uint16_t major{0};
0036     uint16_t minor{0};
0037     uint16_t patch{0};
0038 
0039     auto operator<=>(const Version&) const = default;
0040 
0041     friend std::ostream& operator<<(std::ostream&, const Version& v);
0042   };
0043 
0044   inline std::ostream& operator<<(std::ostream& os, const Version& v) {
0045     return os << v.major << "." << v.minor << "." << v.patch;
0046   }
0047 
0048   /**
0049    * The current build version
0050    */
0051   static constexpr Version build_version{EDM4HEP_VERSION_MAJOR, EDM4HEP_VERSION_MINOR, EDM4HEP_VERSION_PATCH};
0052 
0053   /**
0054    * Decode a version from a 64 bit unsigned
0055    */
0056   static constexpr Version decode_version(uint64_t version) noexcept {
0057     return Version{
0058       (uint16_t) EDM4HEP_MAJOR_VERSION(version),
0059       (uint16_t) EDM4HEP_MINOR_VERSION(version),
0060       (uint16_t) EDM4HEP_PATCH_VERSION(version)
0061     };
0062   }
0063 }
0064 
0065 
0066 #endif