exntend version class to allow add info
This commit is contained in:
parent
5ac88f2b15
commit
8c6c8ad3c0
@ -11,12 +11,24 @@
|
||||
#undef minor
|
||||
#endif
|
||||
|
||||
const fsfw::Version fsfw::FSFW_VERSION = {FSFW_VERSION_MAJOR, FSFW_VERSION_MINOR,
|
||||
FSFW_VERSION_REVISION};
|
||||
const Version fsfw::FSFW_VERSION = {FSFW_VERSION_MAJOR, FSFW_VERSION_MINOR, FSFW_VERSION_REVISION};
|
||||
|
||||
fsfw::Version::Version(uint32_t major, uint32_t minor, uint32_t revision)
|
||||
: major(major), minor(minor), revision(revision) {}
|
||||
Version::Version(uint32_t major, uint32_t minor, uint32_t revision, const char* addInfo)
|
||||
: major(major), minor(minor), revision(revision), addInfo(addInfo) {}
|
||||
|
||||
void fsfw::Version::getVersion(char* str, size_t maxLen) const {
|
||||
snprintf(str, maxLen, "%d.%d.%d", major, minor, revision);
|
||||
void Version::getVersion(char* str, size_t maxLen) const {
|
||||
size_t len = snprintf(str, maxLen, "%d.%d.%d", major, minor, revision);
|
||||
if (addInfo != nullptr) {
|
||||
snprintf(str + len, maxLen - len, "-%s", addInfo);
|
||||
}
|
||||
}
|
||||
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
std::ostream& operator<<(std::ostream& os, const Version& v) {
|
||||
os << v.major << "." << v.minor << "." << v.revision;
|
||||
if (v.addInfo != nullptr) {
|
||||
os << "-" << v.addInfo;
|
||||
}
|
||||
return os;
|
||||
}
|
||||
#endif
|
||||
|
@ -8,15 +8,16 @@
|
||||
#endif
|
||||
#include <cstdint>
|
||||
|
||||
namespace fsfw {
|
||||
|
||||
class Version {
|
||||
public:
|
||||
Version(uint32_t major, uint32_t minor, uint32_t revision);
|
||||
Version(uint32_t major, uint32_t minor, uint32_t revision, const char* addInfo = nullptr);
|
||||
uint32_t major = 0;
|
||||
uint32_t minor = 0;
|
||||
uint32_t revision = 0;
|
||||
|
||||
// Additional information, e.g. a git SHA hash
|
||||
const char* addInfo = nullptr;
|
||||
|
||||
friend bool operator==(const Version& v1, const Version& v2) {
|
||||
return (v1.major == v2.major and v1.minor == v2.minor and v1.revision == v2.revision);
|
||||
}
|
||||
@ -43,10 +44,7 @@ class Version {
|
||||
* @param v
|
||||
* @return
|
||||
*/
|
||||
friend std::ostream& operator<<(std::ostream& os, const Version& v) {
|
||||
os << v.major << "." << v.minor << "." << v.revision;
|
||||
return os;
|
||||
}
|
||||
friend std::ostream& operator<<(std::ostream& os, const Version& v);
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -57,7 +55,9 @@ class Version {
|
||||
void getVersion(char* str, size_t maxLen) const;
|
||||
};
|
||||
|
||||
extern const fsfw::Version FSFW_VERSION;
|
||||
namespace fsfw {
|
||||
|
||||
extern const Version FSFW_VERSION;
|
||||
|
||||
} // namespace fsfw
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user