21#include <RogueConfig.h>
34 #include <boost/python.hpp>
35namespace bp = boost::python;
38const char rogue::Version::_version[] = ROGUE_VERSION;
39std::atomic<uint32_t> rogue::Version::_major{0};
40std::atomic<uint32_t> rogue::Version::_minor{0};
41std::atomic<uint32_t> rogue::Version::_maint{0};
42std::atomic<uint32_t> rogue::Version::_devel{0};
44void rogue::Version::init() {
45 static std::once_flag flag_;
47 std::call_once(flag_, []() {
50 uint32_t maj = 0, min = 0, mnt = 0, dev = 0;
51 int32_t ret = sscanf(_version,
52 "%c%" SCNu32
".%" SCNu32
".%" SCNu32
"-%" SCNu32
"-%99s",
60 if ((ret != 4 && ret != 6) || (lead !=
'v' && lead !=
'V'))
70void rogue::Version::extract(
const std::string& compare, uint32_t* major, uint32_t* minor, uint32_t* maint) {
71 if (sscanf(compare.c_str(),
"%" PRIu32
".%" PRIu32
".%" PRIu32, major, minor, maint) != 3)
76 std::string ret = _version;
81 uint32_t cmajor, cminor, cmaint;
83 extract(compare, &cmajor, &cminor, &cmaint);
84 if (cmajor != _major)
return (_major > cmajor);
85 if (cminor != _minor)
return (_minor > cminor);
86 if (cmaint != _maint)
return (_maint > cmaint);
91 uint32_t cmajor, cminor, cmaint;
93 extract(compare, &cmajor, &cminor, &cmaint);
94 if (cmajor != _major)
return (_major > cmajor);
95 if (cminor != _minor)
return (_minor > cminor);
96 if (cmaint != _maint)
return (_maint > cmaint);
101 uint32_t cmajor, cminor, cmaint;
103 extract(compare, &cmajor, &cminor, &cmaint);
104 if (cmajor != _major)
return (_major < cmajor);
105 if (cminor != _minor)
return (_minor < cminor);
106 if (cmaint != _maint)
return (_maint < cmaint);
111 uint32_t cmajor, cminor, cmaint;
113 extract(compare, &cmajor, &cminor, &cmaint);
114 if (cmajor != _major)
return (_major < cmajor);
115 if (cminor != _minor)
return (_minor < cminor);
116 if (cmaint != _maint)
return (_maint < cmaint);
121 if (lessThan(compare))
122 throw(
rogue::GeneralError(
"Version:minVersion",
"Installed rogue is less than minimum version"));
126 if (greaterThan(compare))
127 throw(
rogue::GeneralError(
"Version:maxVersion",
"Installed rogue is greater than maximum version"));
131 if (lessThan(compare) || greaterThan(compare))
132 throw(
rogue::GeneralError(
"Version:exactVersion",
"Installed rogue is not exact version"));
157 std::stringstream ret;
159 ret << std::dec << _major;
160 ret <<
"." << std::dec << _minor;
161 ret <<
"." << std::dec << _maint;
163 if (_devel > 0) ret <<
".dev" << std::dec << _devel;
179 bp::class_<rogue::Version, boost::noncopyable>(
"Version", bp::no_init)
181 .staticmethod(
"current")
183 .staticmethod(
"greaterThanEqual")
185 .staticmethod(
"greaterThan")
187 .staticmethod(
"lessThanEqual")
189 .staticmethod(
"lessThan")
191 .staticmethod(
"minVersion")
193 .staticmethod(
"maxVersion")
195 .staticmethod(
"exactVersion")
197 .staticmethod(
"major")
199 .staticmethod(
"minor")
201 .staticmethod(
"maint")
203 .staticmethod(
"devel")
205 .staticmethod(
"pythonVersion")
207 .staticmethod(
"sleep")
209 .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.