PODIO v00-16-03
An Event-Data-Model Toolkit for High Energy Physics Experiments
Loading...
Searching...
No Matches
podioVersion.in.h
Go to the documentation of this file.
1#ifndef PODIO_PODIOVERSION_H
2#define PODIO_PODIOVERSION_H
3
4#include <cstdint>
5#include <sstream>
6#include <ostream>
7#include <tuple>
8#if __cplusplus >= 202002L
9 #include <compare>
10#endif
11
12// Some preprocessor constants and macros for the use cases where they might be
13// necessary
14
15/// Define a version to be used in podio.
16#define PODIO_VERSION(major, minor, patch) \
17 ((UINT64_C(major) << 32) | (UINT64_C(minor) << 16) | UINT64_C(patch))
18/// Get the major version from a preprocessor defined version
19#define PODIO_MAJOR_VERSION(v) (((v) & (-1UL >> 16)) >> 32)
20/// Get the minor version from a preprocessor defined version
21#define PODIO_MINOR_VERSION(v) (((v) & (-1UL >> 32)) >> 16)
22/// Get the patch version from a preprocessor defined version
23#define PODIO_PATCH_VERSION(v) ((v) & (-1UL >> 48))
24
25// Some helper constants that are populated by the cmake configure step
26#define podio_VERSION_MAJOR @podio_VERSION_MAJOR@
27#define podio_VERSION_MINOR @podio_VERSION_MINOR@
28#define podio_VERSION_PATCH @podio_VERSION_PATCH@
29#define podio_VERSION PODIO_VERSION(podio_VERSION_MAJOR, podio_VERSION_MINOR, podio_VERSION_PATCH)
30
31/// The encoded version with which podio has been built
32#define PODIO_BUILD_VERSION PODIO_VERSION(podio_VERSION_MAJOR, podio_VERSION_MINOR, podio_VERSION_PATCH)
33
34namespace podio::version {
35
36/**
37 * Version class consisting of 3 16 bit unsigned integers to hold the major,
38 * minor and patch version. Provides constexpr comparison operators that allow
39 * to use this class in constexpr-if clauses.
40 */
41struct Version {
42 uint16_t major{0};
43 uint16_t minor{0};
44 uint16_t patch{0};
45
46#if __cplusplus >= 202002L
47 auto operator<=>(const Version&) const = default;
48#else
49 // No spaceship yet in c++17
50 #define DEFINE_COMP_OPERATOR(OP) \
51 constexpr bool operator OP(const Version& o) const noexcept { \
52 return std::tie(major, minor, patch) OP std::tie(o.major, o.minor, o.patch); \
53 }
54
61
62 #undef DEFINE_COMP_OPERATOR
63#endif
64
65 explicit operator std::string() const {
66 std::stringstream ss;
67 ss << *this;
68 return ss.str();
69 };
70
71 friend std::ostream& operator<<(std::ostream&, const Version& v);
72};
73
74inline std::ostream& operator<<(std::ostream& os, const Version& v) {
75 return os << v.major << "." << v.minor << "." << v.patch;
76}
77
78/**
79 * The current build version
80 */
82
83/**
84 * Decode a version from a 64 bit unsigned
85 */
86static constexpr Version decode_version(unsigned long version) noexcept {
87 return Version{(uint16_t)PODIO_MAJOR_VERSION(version), (uint16_t)PODIO_MINOR_VERSION(version),
88 (uint16_t)PODIO_PATCH_VERSION(version)};
89}
90} // namespace podio::version
91
92#endif
std::ostream & operator<<(std::ostream &os, const Version &v)
#define podio_VERSION_MAJOR
#define podio_VERSION_MINOR
#define DEFINE_COMP_OPERATOR(OP)
#define PODIO_MAJOR_VERSION(v)
Get the major version from a preprocessor defined version.
#define podio_VERSION_PATCH
#define PODIO_PATCH_VERSION(v)
Get the patch version from a preprocessor defined version.
#define PODIO_MINOR_VERSION(v)
Get the minor version from a preprocessor defined version.
friend std::ostream & operator<<(std::ostream &, const Version &v)