2018-08-27 11:09:25 +02:00
|
|
|
/** Version.
|
|
|
|
*
|
|
|
|
* @author Steffen Vogel <github@daniel-krebs.net>
|
2022-03-15 09:05:42 -04:00
|
|
|
* @copyright 2014-2022, Institute for Automation of Complex Power Systems, EONERC
|
2022-05-19 17:40:10 +02:00
|
|
|
* @license Apache License 2.0
|
2018-08-27 11:09:25 +02:00
|
|
|
*********************************************************************************/
|
|
|
|
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include <villas/log.hpp>
|
|
|
|
#include <villas/utils.hpp>
|
|
|
|
#include <villas/version.hpp>
|
|
|
|
|
|
|
|
using namespace villas::utils;
|
|
|
|
|
|
|
|
Version::Version(const std::string &str)
|
|
|
|
{
|
|
|
|
size_t endpos;
|
|
|
|
|
|
|
|
auto comp = tokenize(str, ".");
|
|
|
|
|
|
|
|
if (comp.size() > 3)
|
2018-12-02 02:47:55 +01:00
|
|
|
throw std::invalid_argument("Not a valid version string");
|
2018-08-27 11:09:25 +02:00
|
|
|
|
|
|
|
for (unsigned i = 0; i < 3; i++) {
|
|
|
|
if (i < comp.size()) {
|
|
|
|
components[i] = std::stoi(comp[i], &endpos, 10);
|
|
|
|
|
|
|
|
if (comp[i].begin() + endpos != comp[i].end())
|
2018-12-02 02:47:55 +01:00
|
|
|
throw std::invalid_argument("Not a valid version string");
|
2018-08-27 11:09:25 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
components[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Version::Version(int maj, int min, int pat) :
|
|
|
|
components{maj, min, pat}
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-06-14 21:53:18 +02:00
|
|
|
int Version::cmp(const Version &lhs, const Version &rhs)
|
2018-08-27 11:09:25 +02:00
|
|
|
{
|
|
|
|
int d;
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
d = lhs.components[i] - rhs.components[i];
|
|
|
|
if (d)
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|