validator勾连
This commit is contained in:
parent
fec92a6702
commit
ab59a981fa
|
@ -134,7 +134,6 @@ namespace Inlet {
|
||||||
};
|
};
|
||||||
template<void* addr, typename Ret, typename... Args> CmdsImpl<addr, Ret, Args...>* CmdsImpl<addr, Ret, Args...>::_unique_inst = nullptr;
|
template<void* addr, typename Ret, typename... Args> CmdsImpl<addr, Ret, Args...>* CmdsImpl<addr, Ret, Args...>::_unique_inst = nullptr;
|
||||||
|
|
||||||
|
|
||||||
template<void* addr, typename Ret, typename... Args> struct EventsImpl : public IRunbase {
|
template<void* addr, typename Ret, typename... Args> struct EventsImpl : public IRunbase {
|
||||||
private:
|
private:
|
||||||
Callable<Ret, Args...> _func = (Callable<Ret, Args...>)addr;
|
Callable<Ret, Args...> _func = (Callable<Ret, Args...>)addr;
|
||||||
|
@ -168,7 +167,5 @@ namespace Inlet {
|
||||||
_args_value.loadFrom(0, object);
|
_args_value.loadFrom(0, object);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<void* addr, typename Ret, typename... Args> EventsImpl<addr, Ret, Args...>* EventsImpl<addr, Ret, Args...>::_unique_inst = nullptr;
|
template<void* addr, typename Ret, typename... Args> EventsImpl<addr, Ret, Args...>* EventsImpl<addr, Ret, Args...>::_unique_inst = nullptr;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,15 @@
|
||||||
#include "dispatch.h"
|
#include "dispatch.h"
|
||||||
#include "cmds.h"
|
#include "cmds.h"
|
||||||
#include "validation.h"
|
#include "validation.h"
|
||||||
|
#include "validate_impl.h"
|
||||||
|
|
||||||
int vp(int c) {
|
int vp(int c) {
|
||||||
qDebug() << c;
|
qDebug() << c;
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
verify::T<int(int)>::Validation<vp> vp_check;
|
verify::T<int(int)>::Validation<vp> vp_check;
|
||||||
|
auto args0 = vp_check.pos<0>() & new impls::Int32Limit<true, true>(QString(u8"Hello World"), 0, 3);
|
||||||
|
|
||||||
|
|
||||||
namespace xproc {
|
namespace xproc {
|
||||||
int xmp(int arg) {
|
int xmp(int arg) {
|
||||||
|
@ -19,7 +21,6 @@ namespace xproc {
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cmds::T<int(int)>::Cmd<vp> entry("hello");
|
cmds::T<int(int)>::Cmd<vp> entry("hello");
|
||||||
cmds::T<int(int)>::Cmd<xproc::xmp> xvv("sfaf");
|
cmds::T<int(int)>::Cmd<xproc::xmp> xvv("sfaf");
|
||||||
|
|
||||||
|
@ -37,6 +38,9 @@ int main(int argc, char* argv[]) {
|
||||||
exec.execute(5);
|
exec.execute(5);
|
||||||
|
|
||||||
entry(50);
|
entry(50);
|
||||||
|
entry(2);
|
||||||
|
entry(0);
|
||||||
|
entry(3);
|
||||||
xvv(2);
|
xvv(2);
|
||||||
|
|
||||||
return a.exec();
|
return a.exec();
|
||||||
|
|
|
@ -37,14 +37,46 @@ namespace impls {
|
||||||
};
|
};
|
||||||
|
|
||||||
template<bool min_equal, bool max_equal>
|
template<bool min_equal, bool max_equal>
|
||||||
class IntegerLimit : public validate::Validator<int64_t> {
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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> {
|
||||||
private:
|
private:
|
||||||
QString _name_store;
|
QString _name_store;
|
||||||
int64_t _limit_max, _limit_min;
|
int64_t _limit_max, _limit_min;
|
||||||
int64_t _limit_max_times = 0, _limit_min_times = 0;
|
int64_t _limit_max_times = 0, _limit_min_times = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
IntegerLimit(const QString& name, int64_t min, int64_t max)
|
Int64Limit(const QString& name, int64_t min, int64_t max)
|
||||||
: _name_store(name), _limit_min(min), _limit_max(max) {
|
: _name_store(name), _limit_min(min), _limit_max(max) {
|
||||||
_limit_max_times = _limit_max + max_equal;
|
_limit_max_times = _limit_max + max_equal;
|
||||||
_limit_min_times = _limit_min - min_equal;
|
_limit_min_times = _limit_min - min_equal;
|
||||||
|
@ -67,6 +99,7 @@ namespace impls {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class EnumsValidator : public validate::Validator<int32_t> {
|
class EnumsValidator : public validate::Validator<int32_t> {
|
||||||
private:
|
private:
|
||||||
QString _name_store;
|
QString _name_store;
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace validate {
|
||||||
};
|
};
|
||||||
template<typename T> class ValidatorReceiver {
|
template<typename T> class ValidatorReceiver {
|
||||||
public:
|
public:
|
||||||
virtual void append(Validator<T> inst) { }
|
virtual void append(Validator<T>* inst) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,15 +32,15 @@ namespace validate {
|
||||||
template<typename head_type, typename... rest_type>
|
template<typename head_type, typename... rest_type>
|
||||||
struct ValidateTemplet<head_type, rest_type...> : public ValidateTemplet<rest_type...> {
|
struct ValidateTemplet<head_type, rest_type...> : public ValidateTemplet<rest_type...> {
|
||||||
private:
|
private:
|
||||||
QList<Validator<head_type>> validator_list;
|
QList<Validator<head_type>*> validator_list;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void add(Validator<head_type> vinst) {
|
void add(Validator<head_type>* vinst) {
|
||||||
validator_list << vinst;
|
validator_list << vinst;
|
||||||
}
|
}
|
||||||
bool check(head_type value) const {
|
bool check(head_type value) const {
|
||||||
for (auto u : validator_list)
|
for (auto u : validator_list)
|
||||||
if (!u.check(value))
|
if (!u->check(value))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ namespace validate {
|
||||||
|
|
||||||
template<int idx, typename head_type, typename... rest_type>
|
template<int idx, typename head_type, typename... rest_type>
|
||||||
void __validator_insert_helper(ValidateTemplet<head_type, rest_type...>& target,
|
void __validator_insert_helper(ValidateTemplet<head_type, rest_type...>& target,
|
||||||
Validator<typename ElmPos<idx, ValidateTemplet<head_type, rest_type...>>::value_type> inst) {
|
Validator<typename ElmPos<idx, ValidateTemplet<head_type, rest_type...>>::value_type>* inst) {
|
||||||
using templet_type = typename ElmPos<idx, ValidateTemplet<head_type, rest_type...>>::templet_type;
|
using templet_type = typename ElmPos<idx, ValidateTemplet<head_type, rest_type...>>::templet_type;
|
||||||
target.templet_type::add(inst);
|
target.templet_type::add(inst);
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ namespace validate {
|
||||||
|
|
||||||
ArgsPosition(ValidateTemplet<args_type...>& target) :_templet_bind(target) { }
|
ArgsPosition(ValidateTemplet<args_type...>& target) :_templet_bind(target) { }
|
||||||
|
|
||||||
ArgsPosition<n, args_type...>& operator&(Validator<param_type> vinst) {
|
ArgsPosition<n, args_type...>& operator&(Validator<param_type>* vinst) {
|
||||||
append(vinst);
|
append(vinst);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ namespace validate {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidatorReceiver
|
// ValidatorReceiver
|
||||||
virtual void append(Validator<param_type> inst) {
|
virtual void append(Validator<param_type>* inst) {
|
||||||
__validator_insert_helper<n, args_type...>(_templet_bind, inst);
|
__validator_insert_helper<n, args_type...>(_templet_bind, inst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ namespace validate {
|
||||||
SlicePosition(ValidatorReceiver<s_type>& host, std::function<t_type(s_type)> func)
|
SlicePosition(ValidatorReceiver<s_type>& host, std::function<t_type(s_type)> func)
|
||||||
:_conv_func(func), _prev_bind(host) { }
|
:_conv_func(func), _prev_bind(host) { }
|
||||||
|
|
||||||
SlicePosition<n, s_type, t_type, ArgsPosition<n, args_type...>>& operator&(Validator<t_type> vinst) {
|
SlicePosition<n, s_type, t_type, ArgsPosition<n, args_type...>>& operator&(Validator<t_type>* vinst) {
|
||||||
append(vinst);
|
append(vinst);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,7 @@ namespace validate {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidatorReceiver
|
// ValidatorReceiver
|
||||||
virtual void append(Validator<t_type> inst) {
|
virtual void append(Validator<t_type>* inst) {
|
||||||
SliceValidator<s_type, t_type> mid_validator(_conv_func, inst);
|
SliceValidator<s_type, t_type> mid_validator(_conv_func, inst);
|
||||||
_prev_bind.append(mid_validator);
|
_prev_bind.append(mid_validator);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue