-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathEDM4hepVersion.h.in
66 lines (53 loc) · 2.25 KB
/
EDM4hepVersion.h.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef EDM4HEP_VERSION_H
#define EDM4HEP_VERSION_H
#include <cstdint>
#include <ostream>
// Some preprocessor constants and macros for the use cases where they might be
// necessary
/// Define a version to be used in edm4hep.
#define EDM4HEP_VERSION(major, minor, patch) ((UINT64_C(major) << 32) | (UINT64_C(minor) << 16) | (UINT64_C(patch)))
/// Get the major version from a preprocessor defined version
#define EDM4HEP_MAJOR_VERSION(v) (((v) & (-1UL >> 16)) >> 32)
/// Get the minor version from a preprocessor defined version
#define EDM4HEP_MINOR_VERSION(v) (((v) & (-1UL >> 32)) >> 16)
/// Get the patch version from a preprocessor defined version
#define EDM4HEP_PATCH_VERSION(v) ((v) & (-1UL >> 48))
// Some helper constants that are populated by the cmake configure step
#define EDM4HEP_VERSION_MAJOR @EDM4HEP_VERSION_MAJOR@
#define EDM4HEP_VERSION_MINOR @EDM4HEP_VERSION_MINOR@
#define EDM4HEP_VERSION_PATCH @EDM4HEP_VERSION_PATCH@
#define edm4hep_VERSION EDM4HEP_VERSION(EDM4HEP_VERSION_MAJOR, EDM4HEP_VERSION_MINOR, EDM4HEP_VERSION_PATCH)
/// The encoded version with which edm4hep has been built
#define EDM4HEP_BUILD_VERSION EDM4HEP_VERSION(EDM4HEP_VERSION_MAJOR, EDM4HEP_VERSION_MINOR, EDM4HEP_VERSION_PATCH)
namespace edm4hep::version {
/**
* Version class consisting of 3 16 bit unsigned integers to hold the major,
* minor and patch version. Provides constexpr comparison operators that allow
* to use this class in constexpr-if clauses.
*/
struct Version {
uint16_t major{0};
uint16_t minor{0};
uint16_t patch{0};
auto operator<=>(const Version&) const = default;
friend std::ostream& operator<<(std::ostream&, const Version& v);
};
inline std::ostream& operator<<(std::ostream& os, const Version& v) {
return os << v.major << "." << v.minor << "." << v.patch;
}
/**
* The current build version
*/
static constexpr Version build_version{EDM4HEP_VERSION_MAJOR, EDM4HEP_VERSION_MINOR, EDM4HEP_VERSION_PATCH};
/**
* Decode a version from a 64 bit unsigned
*/
static constexpr Version decode_version(uint64_t version) noexcept {
return Version{
(uint16_t) EDM4HEP_MAJOR_VERSION(version),
(uint16_t) EDM4HEP_MINOR_VERSION(version),
(uint16_t) EDM4HEP_PATCH_VERSION(version)
};
}
}
#endif