Initial commit
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
#ifndef RANGE_LIMITER_H
|
||||
#define RANGE_LIMITER_H
|
||||
|
||||
#include <QDebug>
|
||||
#include <QRandomGenerator>
|
||||
|
||||
class RangeLimiter {
|
||||
private:
|
||||
mutable QRandomGenerator gen_;
|
||||
|
||||
public:
|
||||
inline RangeLimiter();
|
||||
|
||||
template <typename T> inline T bounded(T highest) const noexcept;
|
||||
template <typename T> inline T bounded(T lowest, T highest) const noexcept;
|
||||
};
|
||||
|
||||
RangeLimiter::RangeLimiter() : gen_(QRandomGenerator::securelySeeded()) {}
|
||||
|
||||
template <typename T> T RangeLimiter::bounded(T highest) const noexcept {
|
||||
return gen_.bounded(highest);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T RangeLimiter::bounded(T lowest, T highest) const noexcept {
|
||||
if (lowest >= highest) {
|
||||
QString errorMessage =
|
||||
"Lowest value (%1) is greater than highest value (%2) or equal to it";
|
||||
qFatal().noquote() << errorMessage.arg(lowest).arg(highest);
|
||||
}
|
||||
return gen_.bounded(lowest, highest);
|
||||
}
|
||||
|
||||
#endif // RANGE_LIMITER_H
|
||||
Reference in New Issue
Block a user