21#include <RogueConfig.h>
33 #include <boost/python.hpp>
34namespace bp = boost::python;
37const char rogue::Version::_version[] = ROGUE_VERSION;
38uint32_t rogue::Version::_major = 0;
39uint32_t rogue::Version::_minor = 0;
40uint32_t rogue::Version::_maint = 0;
41uint32_t rogue::Version::_devel = 0;
43void rogue::Version::init() {
48 ret = sscanf(_version,
49 "%c%" SCNu32
".%" SCNu32
".%" SCNu32
"-%" SCNu32
"-%s",
57 if ((ret != 4 && ret != 6) || (lead !=
'v' && lead !=
'V'))
61void rogue::Version::extract(
const std::string& compare, uint32_t* major, uint32_t* minor, uint32_t* maint) {
62 if (sscanf(compare.c_str(),
"%" PRIu32
".%" PRIu32
".%" PRIu32, major, minor, maint) != 3)
67 std::string ret = _version;
72 uint32_t cmajor, cminor, cmaint;
74 extract(compare, &cmajor, &cminor, &cmaint);
75 if (cmajor != _major)
return (_major > cmajor);
76 if (cminor != _minor)
return (_minor > cminor);
77 if (cmaint != _maint)
return (_maint > cmaint);
82 uint32_t cmajor, cminor, cmaint;
84 extract(compare, &cmajor, &cminor, &cmaint);
85 if (cmajor != _major)
return (_major > cmajor);
86 if (cminor != _minor)
return (_minor > cminor);
87 if (cmaint != _maint)
return (_maint > cmaint);
92 uint32_t cmajor, cminor, cmaint;
94 extract(compare, &cmajor, &cminor, &cmaint);
95 if (cmajor != _major)
return (_major < cmajor);
96 if (cminor != _minor)
return (_minor < cminor);
97 if (cmaint != _maint)
return (_maint < cmaint);
102 uint32_t cmajor, cminor, cmaint;
104 extract(compare, &cmajor, &cminor, &cmaint);
105 if (cmajor != _major)
return (_major < cmajor);
106 if (cminor != _minor)
return (_minor < cminor);
107 if (cmaint != _maint)
return (_maint < cmaint);
112 if (lessThan(compare))
113 throw(
rogue::GeneralError(
"Version:minVersion",
"Installed rogue is less than minimum version"));
117 if (greaterThan(compare))
118 throw(
rogue::GeneralError(
"Version:maxVersion",
"Installed rogue is greater than maximum version"));
122 if (lessThan(compare) || greaterThan(compare))
123 throw(
rogue::GeneralError(
"Version:exactVersion",
"Installed rogue is not exact version"));
148 std::stringstream ret;
150 ret << std::dec << _major;
151 ret <<
"." << std::dec << _minor;
152 ret <<
"." << std::dec << _maint;
154 if (_devel > 0) ret <<
".dev" << std::dec << _devel;
170 bp::class_<rogue::Version, boost::noncopyable>(
"Version", bp::no_init)
172 .staticmethod(
"current")
174 .staticmethod(
"greaterThanEqual")
176 .staticmethod(
"greaterThan")
178 .staticmethod(
"lessThanEqual")
180 .staticmethod(
"lessThan")
182 .staticmethod(
"minVersion")
184 .staticmethod(
"maxVersion")
186 .staticmethod(
"exactVersion")
188 .staticmethod(
"major")
190 .staticmethod(
"minor")
192 .staticmethod(
"maint")
194 .staticmethod(
"devel")
196 .staticmethod(
"pythonVersion")
198 .staticmethod(
"sleep")
200 .staticmethod(
"usleep");
Generic Rogue exception type.
RAII helper that releases the Python GIL for a scope.
static bool lessThanEqual(const std::string &compare)
Returns whether current version is less than or equal to compare.
static void maxVersion(const std::string &compare)
Throws if current version is above allowed maximum.
static void minVersion(const std::string &compare)
Throws if current version is below required minimum.
static uint32_t getMinor()
Returns minor version component.
static std::string current()
Returns current Rogue version string.
static void setup_python()
Registers Python bindings for version helpers.
static bool greaterThanEqual(const std::string &compare)
Returns whether current version is greater than or equal to compare.
static std::string pythonVersion()
Returns Python runtime version string.
static uint32_t getMajor()
Returns major version component.
static uint32_t getDevel()
Returns development/build component.
static bool lessThan(const std::string &compare)
Returns whether current version is less than compare.
static bool greaterThan(const std::string &compare)
Returns whether current version is greater than compare.
static void exactVersion(const std::string &compare)
Throws unless current version exactly matches compare.
static uint32_t getMaint()
Returns maintenance/patch version component.
static void usleep(uint32_t useconds)
Microsecond sleep helper for testing/debug timing.
static void sleep(uint32_t seconds)
Sleep helper for testing/debug timing.