2024-11-16 13:37:42 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
2024-11-17 15:36:43 +00:00
|
|
|
|
#include "validate_basic.h"
|
2024-11-16 13:37:42 +00:00
|
|
|
|
|
|
|
|
|
namespace impls {
|
|
|
|
|
template<bool min_equal, bool max_equal, uint precision>
|
|
|
|
|
class DoubleLimit : public validate::Validator<double> {
|
|
|
|
|
private:
|
|
|
|
|
QString _name_store;
|
|
|
|
|
double _limit_max, _limit_min;
|
|
|
|
|
int64_t _limit_max_times = 0, _limit_min_times = 0;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
DoubleLimit(const QString& name, double min, double max)
|
|
|
|
|
: _name_store(name), _limit_max(max), _limit_min(min) {
|
|
|
|
|
_limit_min_times = static_cast<int64_t>(min * precision) - min_equal;
|
|
|
|
|
_limit_max_times = static_cast<int64_t>(max * precision) + max_equal;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-19 14:52:59 +00:00
|
|
|
|
virtual QString name() const{ return _name_store; }
|
2024-11-16 13:37:42 +00:00
|
|
|
|
|
|
|
|
|
virtual bool check(double value) const {
|
|
|
|
|
auto value_times = static_cast<int>(value * precision);
|
|
|
|
|
return _limit_min_times < value_times && value_times < _limit_max_times;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void getDepict(datas::IDataObject& self_description) {
|
|
|
|
|
self_description.setString(u8"ValidatorName", _name_store);
|
|
|
|
|
self_description.setString(u8"ValueType", u8"Double");
|
|
|
|
|
self_description.setInt64(u8"Precision", precision);
|
|
|
|
|
self_description.setDouble(u8"MinValue", _limit_min);
|
|
|
|
|
self_description.setDouble(u8"MaxValue", _limit_max);
|
|
|
|
|
|
|
|
|
|
auto description = QString(u8"%1 %3 value %4 %2").arg(_limit_min).arg(_limit_max);
|
|
|
|
|
description = description.arg(min_equal ? u8"<=" : u8"<", max_equal ? u8"<=" : u8"<");
|
|
|
|
|
self_description.setString(u8"Description", description);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<bool min_equal, bool max_equal>
|
2024-11-17 15:03:54 +00:00
|
|
|
|
class Int32Limit : public validate::Validator<int32_t> {
|
|
|
|
|
private:
|
|
|
|
|
QString _name_store;
|
|
|
|
|
int32_t _limit_max, _limit_min;
|
|
|
|
|
int32_t _limit_max_times = 0, _limit_min_times = 0;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
Int32Limit(const QString& name, int32_t min, int32_t max)
|
|
|
|
|
: _name_store(name), _limit_min(min), _limit_max(max) {
|
|
|
|
|
_limit_max_times = _limit_max + max_equal;
|
|
|
|
|
_limit_min_times = _limit_min - min_equal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-11-19 14:52:59 +00:00
|
|
|
|
virtual QString name() const {
|
|
|
|
|
return _name_store;
|
|
|
|
|
}
|
2024-11-17 15:03:54 +00:00
|
|
|
|
virtual bool check(int32_t value) const {
|
|
|
|
|
return _limit_min_times < value && value < _limit_max_times;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void getDepict(datas::IDataObject& self_description) {
|
|
|
|
|
self_description.setString(u8"ValidatorName", _name_store);
|
|
|
|
|
self_description.setString(u8"ValueType", u8"Integer");
|
|
|
|
|
self_description.setInt32(u8"MinValue", _limit_min);
|
|
|
|
|
self_description.setInt32(u8"MaxValue", _limit_max);
|
|
|
|
|
|
|
|
|
|
auto description = QString(u8"%1 %3 value %4 %2").arg(_limit_min).arg(_limit_max);
|
|
|
|
|
description = description.arg(min_equal ? u8"<=" : u8"<", max_equal ? u8"<=" : u8"<");
|
|
|
|
|
self_description.setString(u8"Description", description);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<bool min_equal, bool max_equal>
|
|
|
|
|
class Int64Limit : public validate::Validator<int64_t> {
|
2024-11-16 13:37:42 +00:00
|
|
|
|
private:
|
|
|
|
|
QString _name_store;
|
|
|
|
|
int64_t _limit_max, _limit_min;
|
|
|
|
|
int64_t _limit_max_times = 0, _limit_min_times = 0;
|
|
|
|
|
|
|
|
|
|
public:
|
2024-11-17 15:03:54 +00:00
|
|
|
|
Int64Limit(const QString& name, int64_t min, int64_t max)
|
2024-11-16 13:37:42 +00:00
|
|
|
|
: _name_store(name), _limit_min(min), _limit_max(max) {
|
|
|
|
|
_limit_max_times = _limit_max + max_equal;
|
|
|
|
|
_limit_min_times = _limit_min - min_equal;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-19 14:52:59 +00:00
|
|
|
|
virtual QString name() const {
|
|
|
|
|
return _name_store;
|
|
|
|
|
}
|
2024-11-16 13:37:42 +00:00
|
|
|
|
|
|
|
|
|
virtual bool check(int64_t value) const {
|
|
|
|
|
return _limit_min_times < value && value < _limit_max_times;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void getDepict(datas::IDataObject& self_description) {
|
|
|
|
|
self_description.setString(u8"ValidatorName", _name_store);
|
|
|
|
|
self_description.setString(u8"ValueType", u8"Integer");
|
|
|
|
|
self_description.setInt64(u8"MinValue", _limit_min);
|
|
|
|
|
self_description.setInt64(u8"MaxValue", _limit_max);
|
|
|
|
|
|
|
|
|
|
auto description = QString(u8"%1 %3 value %4 %2").arg(_limit_min).arg(_limit_max);
|
|
|
|
|
description = description.arg(min_equal ? u8"<=" : u8"<", max_equal ? u8"<=" : u8"<");
|
|
|
|
|
self_description.setString(u8"Description", description);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2024-11-17 15:03:54 +00:00
|
|
|
|
|
2024-11-16 13:37:42 +00:00
|
|
|
|
class EnumsValidator : public validate::Validator<int32_t> {
|
|
|
|
|
private:
|
|
|
|
|
QString _name_store;
|
|
|
|
|
QList<int32_t> _enum_options;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
EnumsValidator(const QString& name, const QList<int32_t>& list)
|
|
|
|
|
:_name_store(name), _enum_options(list) { }
|
|
|
|
|
|
2024-11-19 14:52:59 +00:00
|
|
|
|
virtual QString name() const {
|
|
|
|
|
return _name_store;
|
|
|
|
|
}
|
2024-11-16 13:37:42 +00:00
|
|
|
|
virtual bool check(int32_t value) const {
|
|
|
|
|
return _enum_options.contains(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void getDepict(datas::IDataObject& self_description) {
|
|
|
|
|
self_description.setString(u8"ValidatorName", _name_store);
|
|
|
|
|
self_description.setString(u8"ValueType", u8"Enum");
|
|
|
|
|
|
|
|
|
|
QStringList options;
|
|
|
|
|
std::transform(_enum_options.begin(), _enum_options.end(), std::back_inserter(options), [](int32_t v) {return QString::number(v); });
|
|
|
|
|
self_description.setString(u8"Values", options.join(u8","));
|
|
|
|
|
self_description.setString(u8"Description", QString("value <20><> { %1 }").arg(options.join(u8",")));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|