2018-12-08 20:10:29 +05:00
|
|
|
#ifndef NETGEN_CORE_VERSION_HPP
|
|
|
|
#define NETGEN_CORE_VERSION_HPP
|
|
|
|
|
2019-01-23 14:19:43 +05:00
|
|
|
#include <ostream>
|
2018-12-08 20:10:29 +05:00
|
|
|
#include <string>
|
|
|
|
#include <tuple>
|
2018-12-05 18:20:24 +05:00
|
|
|
|
2018-12-10 18:37:27 +05:00
|
|
|
#include "ngcore_api.hpp"
|
|
|
|
|
2018-12-05 18:20:24 +05:00
|
|
|
namespace ngcore
|
|
|
|
{
|
|
|
|
class VersionInfo
|
|
|
|
{
|
|
|
|
private:
|
2018-12-10 15:49:38 +05:00
|
|
|
size_t mayor_{}, minor_{}, release{}, patch{};
|
|
|
|
std::string git_hash{};
|
2018-12-05 18:20:24 +05:00
|
|
|
public:
|
2018-12-10 15:49:38 +05:00
|
|
|
VersionInfo() = default;
|
2018-12-05 18:20:24 +05:00
|
|
|
VersionInfo(std::string vstring)
|
|
|
|
{
|
2018-12-07 15:45:39 +05:00
|
|
|
minor_ = release = patch = 0;
|
2018-12-05 18:20:24 +05:00
|
|
|
git_hash = "";
|
|
|
|
if(vstring.substr(0,1) == "v")
|
|
|
|
vstring = vstring.substr(1,vstring.size()-1);
|
2018-12-10 15:49:38 +05:00
|
|
|
auto dot = vstring.find('.');
|
2018-12-07 15:45:39 +05:00
|
|
|
mayor_ = std::stoi(vstring.substr(0,dot));
|
2018-12-05 18:20:24 +05:00
|
|
|
if(dot == size_t(-1)) vstring = "";
|
|
|
|
else vstring = vstring.substr(dot+1, vstring.size()-dot-1);
|
2018-12-10 15:49:38 +05:00
|
|
|
if(!vstring.empty())
|
2018-12-05 18:20:24 +05:00
|
|
|
{
|
2018-12-10 15:49:38 +05:00
|
|
|
dot = vstring.find('.');
|
2018-12-07 15:45:39 +05:00
|
|
|
minor_ = std::stoi(vstring.substr(0,dot));
|
2018-12-05 18:20:24 +05:00
|
|
|
if (dot == size_t(-1)) vstring = "";
|
|
|
|
else vstring = vstring.substr(dot+1, vstring.size()-dot-1);
|
2018-12-10 15:49:38 +05:00
|
|
|
if(!vstring.empty())
|
2018-12-05 18:20:24 +05:00
|
|
|
{
|
2018-12-10 15:49:38 +05:00
|
|
|
dot = vstring.find('-');
|
2018-12-06 21:53:44 +05:00
|
|
|
release = std::stoi(vstring.substr(0,dot));
|
2018-12-05 18:20:24 +05:00
|
|
|
if(dot == size_t(-1)) vstring = "";
|
|
|
|
else vstring = vstring.substr(dot+1,vstring.size()-dot-1);
|
2018-12-10 15:49:38 +05:00
|
|
|
if(!vstring.empty())
|
2018-12-05 18:20:24 +05:00
|
|
|
{
|
2018-12-10 15:49:38 +05:00
|
|
|
dot = vstring.find('-');
|
2018-12-06 21:53:44 +05:00
|
|
|
patch = std::stoi(vstring.substr(0,dot));
|
2018-12-05 18:20:24 +05:00
|
|
|
if(dot == size_t(-1)) vstring = "";
|
|
|
|
else vstring = vstring.substr(dot+1, vstring.size()-dot-1);
|
2018-12-10 15:49:38 +05:00
|
|
|
if(!vstring.empty())
|
2018-12-05 18:20:24 +05:00
|
|
|
git_hash = vstring;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
VersionInfo(const char* cstr) : VersionInfo(std::string(cstr)) { }
|
|
|
|
|
|
|
|
std::string to_string() const
|
2018-12-07 15:45:39 +05:00
|
|
|
{ std::string vstring = "v" + std::to_string(mayor_);
|
2018-12-10 14:52:00 +05:00
|
|
|
if(minor_ || release || patch || !git_hash.empty())
|
2018-12-05 18:20:24 +05:00
|
|
|
{
|
2018-12-07 15:45:39 +05:00
|
|
|
vstring += "." + std::to_string(minor_);
|
2018-12-10 14:52:00 +05:00
|
|
|
if(release || patch || !git_hash.empty())
|
2018-12-05 18:20:24 +05:00
|
|
|
{
|
2018-12-06 21:53:44 +05:00
|
|
|
vstring += "." + std::to_string(release);
|
2018-12-10 14:52:00 +05:00
|
|
|
if(patch || !git_hash.empty())
|
2018-12-05 18:20:24 +05:00
|
|
|
{
|
2018-12-06 21:53:44 +05:00
|
|
|
vstring += "-" + std::to_string(patch);
|
2018-12-10 14:52:00 +05:00
|
|
|
if(!git_hash.empty())
|
2018-12-05 18:20:24 +05:00
|
|
|
vstring += "-" + git_hash;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return vstring;
|
|
|
|
}
|
|
|
|
bool operator <(const VersionInfo& other) const
|
|
|
|
{
|
2018-12-07 15:45:39 +05:00
|
|
|
return std::tie(mayor_, minor_, release, patch) <
|
|
|
|
std::tie(other.mayor_, other.minor_, other.release, other.patch);
|
2018-12-05 18:20:24 +05:00
|
|
|
}
|
|
|
|
bool operator ==(const VersionInfo& other) const
|
|
|
|
{
|
2018-12-07 15:45:39 +05:00
|
|
|
return mayor_ == other.mayor_ && minor_ == other.minor_ && release == other.release
|
2018-12-06 21:53:44 +05:00
|
|
|
&& patch == other.patch;
|
2018-12-05 18:20:24 +05:00
|
|
|
}
|
2020-07-23 22:04:21 +05:00
|
|
|
bool operator !=(const VersionInfo& other) const
|
|
|
|
{
|
|
|
|
return !(*this==other);
|
|
|
|
}
|
2018-12-05 18:20:24 +05:00
|
|
|
bool operator >(const VersionInfo& other) const { return other < (*this); }
|
|
|
|
bool operator <=(const VersionInfo& other) const { return !((*this) > other); }
|
|
|
|
bool operator >=(const VersionInfo& other) const { return !((*this) < other); }
|
|
|
|
};
|
2019-01-23 14:19:43 +05:00
|
|
|
|
|
|
|
inline std::ostream& operator << (std::ostream& ost, const VersionInfo& version)
|
|
|
|
{
|
|
|
|
return ost << version.to_string();
|
|
|
|
}
|
2020-07-23 22:04:21 +05:00
|
|
|
|
|
|
|
NGCORE_API const VersionInfo& GetLibraryVersion(const std::string& library);
|
|
|
|
NGCORE_API const std::map<std::string, VersionInfo>& GetLibraryVersions();
|
|
|
|
NGCORE_API void SetLibraryVersion(const std::string& library, const VersionInfo& version);
|
2018-12-08 20:10:29 +05:00
|
|
|
} // namespace ngcore
|
|
|
|
|
|
|
|
#endif // NETGEN_CORE_VERSION_HPP
|