Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-01 08:45:49

0001 #ifndef PODIO_PODIOVERSION_H
0002 #define PODIO_PODIOVERSION_H
0003 
0004 #include <cstdint>
0005 #include <ostream>
0006 #include <sstream>
0007 #include <tuple>
0008 
0009 // Some preprocessor constants and macros for the use cases where they might be
0010 // necessary
0011 
0012 /// Define a version to be used in podio.
0013 #define PODIO_VERSION(major, minor, patch)                                                                             \
0014   ((UINT64_C(major) << 32) | (UINT64_C(minor) << 16) | UINT64_C(patch))
0015 /// Get the major version from a preprocessor defined version
0016 #define PODIO_MAJOR_VERSION(v) (((v) & (-1UL >> 16)) >> 32)
0017 /// Get the minor version from a preprocessor defined version
0018 #define PODIO_MINOR_VERSION(v) (((v) & (-1UL >> 32)) >> 16)
0019 /// Get the patch version from a preprocessor defined version
0020 #define PODIO_PATCH_VERSION(v) ((v) & (-1UL >> 48))
0021 
0022 // Some helper constants that are populated by the cmake configure step
0023 #define podio_VERSION_MAJOR 1
0024 #define podio_VERSION_MINOR 2
0025 #define podio_VERSION_PATCH 0
0026 #define podio_VERSION PODIO_VERSION(podio_VERSION_MAJOR, podio_VERSION_MINOR, podio_VERSION_PATCH)
0027 
0028 /// The encoded version with which podio has been built
0029 #define PODIO_BUILD_VERSION PODIO_VERSION(podio_VERSION_MAJOR, podio_VERSION_MINOR, podio_VERSION_PATCH)
0030 
0031 namespace podio::version {
0032 
0033 /// Version class consisting of three 16 bit unsigned integers to hold the major,
0034 /// minor and patch version. Provides constexpr comparison operators that allow
0035 /// one to use this class in constexpr-if clauses.
0036 struct Version {
0037   uint16_t major{0};
0038   uint16_t minor{0};
0039   uint16_t patch{0};
0040 
0041   // We explicitly define these here instead of using the default spaceship
0042   // operator because cppyy does not recognize that yet and we want the
0043   // comparisons to work in python as well
0044   #define DEFINE_COMP_OPERATOR(OP)                                                                                     \
0045     constexpr bool operator OP(const Version& o) const noexcept {                                                      \
0046       return std::tie(major, minor, patch) OP std::tie(o.major, o.minor, o.patch);                                     \
0047     }
0048 
0049   DEFINE_COMP_OPERATOR(<)
0050   DEFINE_COMP_OPERATOR(<=)
0051   DEFINE_COMP_OPERATOR(>)
0052   DEFINE_COMP_OPERATOR(>=)
0053   DEFINE_COMP_OPERATOR(==)
0054   DEFINE_COMP_OPERATOR(!=)
0055 
0056   #undef DEFINE_COMP_OPERATOR
0057 
0058   explicit operator std::string() const {
0059     std::stringstream ss;
0060     ss << *this;
0061     return ss.str();
0062   }
0063 
0064   friend std::ostream& operator<<(std::ostream&, const Version& v);
0065 };
0066 
0067 inline std::ostream& operator<<(std::ostream& os, const Version& v) {
0068   return os << v.major << "." << v.minor << "." << v.patch;
0069 }
0070 
0071 /// The current build version
0072 static constexpr Version build_version{podio_VERSION_MAJOR, podio_VERSION_MINOR, podio_VERSION_PATCH};
0073 
0074 /// Decode a version from a 64 bit unsigned
0075 static constexpr Version decode_version(unsigned long version) noexcept {
0076   return Version{static_cast<uint16_t>(PODIO_MAJOR_VERSION(version)),
0077                  static_cast<uint16_t>(PODIO_MINOR_VERSION(version)),
0078                  static_cast<uint16_t>(PODIO_PATCH_VERSION(version))};
0079 }
0080 } // namespace podio::version
0081 
0082 #endif