fsfw/src/fsfw/version.h

65 lines
1.7 KiB
C
Raw Permalink Normal View History

2022-03-08 10:05:18 +01:00
#ifndef FSFW_SRC_FSFW_VERSION_H_
#define FSFW_SRC_FSFW_VERSION_H_
2022-03-10 09:34:29 +01:00
#include "fsfw/FSFW.h"
#if FSFW_CPP_OSTREAM_ENABLED == 1
#include <iostream>
#endif
2022-03-08 10:05:18 +01:00
#include <cstdint>
2022-05-09 11:06:45 +02:00
namespace fsfw {
2022-03-09 19:05:07 +01:00
class Version {
public:
Version(int major, int minor, int revision, const char* addInfo = nullptr);
int major = -1;
int minor = -1;
int revision = -1;
2022-03-09 19:05:07 +01:00
// Additional information, e.g. a git SHA hash
const char* addInfo = nullptr;
2022-03-09 19:05:07 +01:00
friend bool operator==(const Version& v1, const Version& v2) {
return (v1.major == v2.major and v1.minor == v2.minor and v1.revision == v2.revision);
}
friend bool operator!=(const Version& v1, const Version& v2) { return not(v1 == v2); }
friend bool operator<(const Version& v1, const Version& v2) {
return ((v1.major < v2.major) or (v1.major == v2.major and v1.minor < v2.minor) or
(v1.major == v2.major and v1.minor == v2.minor and v1.revision < v2.revision));
}
2022-03-14 14:37:41 +01:00
friend bool operator>(const Version& v1, const Version& v2) {
2022-04-22 14:04:30 +02:00
return not(v1 < v2) and not(v1 == v2);
2022-03-14 14:37:41 +01:00
}
2022-03-09 19:05:07 +01:00
friend bool operator<=(const Version& v1, const Version& v2) { return ((v1 == v2) or (v1 < v2)); }
friend bool operator>=(const Version& v1, const Version& v2) { return ((v1 == v2) or (v1 > v2)); }
2022-03-10 09:34:29 +01:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
/**
* Print format to given ostream using format "major.minor.revision"
* @param os
* @param v
* @return
*/
friend std::ostream& operator<<(std::ostream& os, const Version& v);
2022-03-10 09:34:29 +01:00
#endif
/**
* Get version as format "major.minor.revision"
* @param str
* @param maxLen
*/
2022-03-10 09:58:37 +01:00
void getVersion(char* str, size_t maxLen) const;
2022-03-08 10:05:18 +01:00
};
extern const Version FSFW_VERSION;
2022-03-09 19:05:07 +01:00
} // namespace fsfw
2022-03-08 10:05:18 +01:00
#endif /* FSFW_SRC_FSFW_VERSION_H_ */