Back to home page

EIC code displayed by LXR

 
 

    


Warning, /EDM4eic/EDM4eicVersion.h.in is written in an unsupported language. File is not indexed.

0001 // SPDX-License-Identifier: Apache-2.0
0002 // Ref: https://github.com/key4hep/EDM4hep/blob/e0762272e0f718df2811fc1bf4590af976bac70d/EDM4hepVersion.h.in
0003 
0004 #ifndef EDM4EIC_VERSION_H
0005 #define EDM4EIC_VERSION_H
0006 
0007 #include <cstdint>
0008 #include <tuple>
0009 #include <ostream>
0010 #if __cplusplus >= 202002L
0011 #include <compare>
0012 #endif
0013 
0014 // Some preprocessor constants and macros for the use cases where they might be
0015 // necessary
0016 
0017 /// Define a version to be used in edm4eic.
0018 #define EDM4EIC_VERSION(major, minor, patch) ((UINT64_C(major) << 32) | (UINT64_C(minor) << 16) | (UINT64_C(patch)))
0019 /// Get the major version from a preprocessor defined version
0020 #define EDM4EIC_MAJOR_VERSION(v) (((v) & (-1UL >> 16)) >> 32)
0021 /// Get the minor version from a preprocessor defined version
0022 #define EDM4EIC_MINOR_VERSION(v) (((v) & (-1UL >> 32)) >> 16)
0023 /// Get the patch version from a preprocessor defined version
0024 #define EDM4EIC_PATCH_VERSION(v) ((v) & (-1UL >> 48))
0025 
0026 // Some helper constants that are populated by the cmake configure step
0027 #define EDM4EIC_VERSION_MAJOR @EDM4EIC_VERSION_MAJOR@
0028 #define EDM4EIC_VERSION_MINOR @EDM4EIC_VERSION_MINOR@
0029 #define EDM4EIC_VERSION_PATCH @EDM4EIC_VERSION_PATCH@
0030 #define edm4eic_VERSION EDM4EIC_VERSION(EDM4EIC_VERSION_MAJOR, EDM4EIC_VERSION_MINOR, EDM4EIC_VERSION_PATCH)
0031 
0032 /// The encoded version with which EDM4EIC has been built
0033 #define EDM4EIC_BUILD_VERSION EDM4EIC_VERSION(EDM4EIC_VERSION_MAJOR, EDM4EIC_VERSION_MINOR, EDM4EIC_VERSION_PATCH)
0034 
0035 namespace edm4eic::version {
0036 
0037   /**
0038    * Version class consisting of 3 16 bit unsigned integers to hold the major,
0039    * minor and patch version. Provides constexpr comparison operators that allow
0040    * to use this class in constexpr-if clauses.
0041    */
0042   struct Version {
0043     uint16_t major{0};
0044     uint16_t minor{0};
0045     uint16_t patch{0};
0046 
0047 #if __cplusplus >= 202002L
0048     auto operator<=>(const Version&) const = default;
0049 #else
0050 // No spaceship yet in c++17
0051 #define DEFINE_COMP_OPERATOR(OP)                                                   \
0052     constexpr bool operator OP(const Version& o) const noexcept {                  \
0053       return std::tie(major, minor, patch) OP std::tie(o.major, o.minor, o.patch); \
0054     }
0055 
0056     DEFINE_COMP_OPERATOR(<)
0057     DEFINE_COMP_OPERATOR(<=)
0058     DEFINE_COMP_OPERATOR(>)
0059     DEFINE_COMP_OPERATOR(>=)
0060     DEFINE_COMP_OPERATOR(==)
0061     DEFINE_COMP_OPERATOR(!=)
0062 
0063 #undef DEFINE_COMP_OPERATOR
0064 #endif
0065 
0066     friend std::ostream& operator<<(std::ostream&, const Version& v);
0067   };
0068 
0069   inline std::ostream& operator<<(std::ostream& os, const Version& v) {
0070     return os << v.major << "." << v.minor << "." << v.patch;
0071   }
0072 
0073   /**
0074    * The current build version
0075    */
0076   static constexpr Version build_version{EDM4EIC_VERSION_MAJOR, EDM4EIC_VERSION_MINOR, EDM4EIC_VERSION_PATCH};
0077 
0078   /**
0079    * Decode a version from a 64 bit unsigned
0080    */
0081   static constexpr Version decode_version(uint64_t version) noexcept {
0082     return Version{
0083       (uint16_t) EDM4EIC_MAJOR_VERSION(version),
0084       (uint16_t) EDM4EIC_MINOR_VERSION(version),
0085       (uint16_t) EDM4EIC_PATCH_VERSION(version)
0086     };
0087   }
0088 }
0089 
0090 
0091 #endif