Back to home page

EIC code displayed by LXR

 
 

    


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 // Some preprocessor constants and macros for the use cases where they might be
0013 // necessary
0014 
0015 /// Define a version to be used in podio.
0016 #define PODIO_VERSION(major, minor, patch)                                                                             \
0017   ((UINT64_C(major) << 32) | (UINT64_C(minor) << 16) | UINT64_C(patch))
0018 /// Get the major version from a preprocessor defined version
0019 #define PODIO_MAJOR_VERSION(v) (((v) & (-1UL >> 16)) >> 32)
0020 /// Get the minor version from a preprocessor defined version
0021 #define PODIO_MINOR_VERSION(v) (((v) & (-1UL >> 32)) >> 16)
0022 /// Get the patch version from a preprocessor defined version
0023 #define PODIO_PATCH_VERSION(v) ((v) & (-1UL >> 48))
0024 
0025 // Some helper constants that are populated by the cmake configure step
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 /// The encoded version with which podio has been built
0032 #define PODIO_BUILD_VERSION PODIO_VERSION(podio_VERSION_MAJOR, podio_VERSION_MINOR, podio_VERSION_PATCH)
0033 
0034 namespace podio::version {
0035 
0036 /// Version class consisting of three 16 bit unsigned integers to hold the major,
0037 /// minor and patch version. Provides constexpr comparison operators that allow
0038 /// one to use this class in constexpr-if clauses.
0039 struct Version {
0040   uint16_t major{0};
0041   uint16_t minor{0};
0042   uint16_t patch{0};
0043 
0044   // We explicitly define these here instead of using the default spaceship
0045   // operator because cppyy does not recognize that yet and we want the
0046   // comparisons to work in python as well
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 /// The current build version
0075 static constexpr Version build_version{podio_VERSION_MAJOR, podio_VERSION_MINOR, podio_VERSION_PATCH};
0076 
0077 /// Decode a version from a 64 bit unsigned
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 } // namespace podio::version
0084 
0085 #endif