Compare commits
3 Commits
acfa763c62
...
93247b6231
Author | SHA1 | Date |
---|---|---|
|
93247b6231 | |
|
ab59a981fa | |
|
fec92a6702 |
|
@ -104,6 +104,7 @@
|
||||||
<ClInclude Include="msgs_types.h" />
|
<ClInclude Include="msgs_types.h" />
|
||||||
<ClInclude Include="validate_impl.h" />
|
<ClInclude Include="validate_impl.h" />
|
||||||
<ClInclude Include="validation.h" />
|
<ClInclude Include="validation.h" />
|
||||||
|
<ClInclude Include="validation_basic.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Condition="Exists('$(QtMsBuild)\qt.targets')">
|
<ImportGroup Condition="Exists('$(QtMsBuild)\qt.targets')">
|
||||||
|
|
|
@ -55,5 +55,8 @@
|
||||||
<ClInclude Include="validate_impl.h">
|
<ClInclude Include="validate_impl.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="validation_basic.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
|
@ -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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include "cmds_basic.h"
|
#include "cmds_basic.h"
|
||||||
#include "validation.h"
|
#include "validation_basic.h"
|
||||||
|
|
||||||
namespace dispatch {
|
namespace dispatch {
|
||||||
class IOutput {
|
class IOutput {
|
||||||
|
|
|
@ -4,11 +4,16 @@
|
||||||
#include "cmds_basic.h"
|
#include "cmds_basic.h"
|
||||||
#include "dispatch.h"
|
#include "dispatch.h"
|
||||||
#include "cmds.h"
|
#include "cmds.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;
|
||||||
|
auto args0 = vp_check.pos<0>() & new impls::Int32Limit<true, true>(u8"Hello World", 0, 3);
|
||||||
|
|
||||||
|
|
||||||
namespace xproc {
|
namespace xproc {
|
||||||
int xmp(int arg) {
|
int xmp(int arg) {
|
||||||
|
@ -16,11 +21,8 @@ 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");
|
||||||
#include "validation.h"
|
|
||||||
validate::ValidateHelper<(void*)vp, int, int> helper;
|
|
||||||
|
|
||||||
|
|
||||||
using namespace Inlet;
|
using namespace Inlet;
|
||||||
|
@ -36,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();
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "validation.h"
|
#include "validation_basic.h"
|
||||||
|
|
||||||
namespace impls {
|
namespace impls {
|
||||||
template<bool min_equal, bool max_equal, uint precision>
|
template<bool min_equal, bool max_equal, uint precision>
|
||||||
|
@ -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;
|
||||||
|
|
|
@ -1,182 +1,27 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QString>
|
#include "validation_basic.h"
|
||||||
#include <QList>
|
#include "dispatch.h"
|
||||||
#include <iostream>
|
|
||||||
#include <functional>
|
|
||||||
#include "data_types.h"
|
|
||||||
#include "cmds_basic.h"
|
|
||||||
|
|
||||||
|
namespace verify {
|
||||||
|
template<typename... Types> struct T;
|
||||||
|
|
||||||
namespace validate {
|
template<typename Ret, typename... Args>
|
||||||
template<typename T> class Validator {
|
struct T<Ret(Args...)> {
|
||||||
public:
|
template<Inlet::Callable<Ret, Args...> func>
|
||||||
virtual bool check(T value) const {
|
struct Validation {
|
||||||
return false;
|
private:
|
||||||
}
|
validate::ValidateImpls<(void*)func, Ret, Args...> _helper;
|
||||||
virtual void getDepict(datas::IDataObject& self_description) { }
|
|
||||||
|
public:
|
||||||
|
Validation() {
|
||||||
|
auto core = dispatch::Dispatch::unique();
|
||||||
|
core->setCmdValidator(_helper.address(), & _helper);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<int n> validate::ArgsPosition<n, Args...> pos() {
|
||||||
|
return _helper.pos<n>();
|
||||||
|
}
|
||||||
|
};
|
||||||
};
|
};
|
||||||
template<typename T> class ValidatorReceiver {
|
}
|
||||||
public:
|
|
||||||
virtual void append(Validator<T> inst) { }
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<typename... args_type> struct ValidateTemplet;
|
|
||||||
template<> struct ValidateTemplet<> {
|
|
||||||
|
|
||||||
template<typename Ret>
|
|
||||||
bool validateFor(Inlet::SignatureImpl<Ret>& value_sequence) const {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
template<typename head_type, typename... rest_type>
|
|
||||||
struct ValidateTemplet<head_type, rest_type...> : public ValidateTemplet<rest_type...> {
|
|
||||||
private:
|
|
||||||
QList<Validator<head_type>> validator_list;
|
|
||||||
|
|
||||||
public:
|
|
||||||
void add(Validator<head_type> vinst) {
|
|
||||||
validator_list << vinst;
|
|
||||||
}
|
|
||||||
bool check(head_type value) const {
|
|
||||||
for (auto u : validator_list)
|
|
||||||
if (!u.check(value))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Ret>
|
|
||||||
bool validateFor(Inlet::SignatureImpl<Ret, head_type, rest_type...>& value_sequence) const {
|
|
||||||
head_type head_value = value_sequence.getArgs0();
|
|
||||||
if (!check(head_value))
|
|
||||||
return false;
|
|
||||||
return ValidateTemplet<rest_type...>::validateFor(value_sequence);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<int idx, typename... args_type> struct ElmPos;
|
|
||||||
|
|
||||||
template<typename head_type, typename... rest_type>
|
|
||||||
struct ElmPos<0, ValidateTemplet<head_type, rest_type...>> {
|
|
||||||
using value_type = head_type;
|
|
||||||
using templet_type = ValidateTemplet<head_type, rest_type...>;
|
|
||||||
};
|
|
||||||
template<int idx, typename head_type, typename... rest_type>
|
|
||||||
struct ElmPos<idx, ValidateTemplet<head_type, rest_type...>> {
|
|
||||||
using value_type = typename ElmPos<idx - 1, ValidateTemplet<rest_type...>>::value_type;
|
|
||||||
using templet_type = typename ElmPos<idx - 1, ValidateTemplet<rest_type...>>::templet_type;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<int idx, typename head_type, typename... rest_type>
|
|
||||||
void __validator_insert_helper(ValidateTemplet<head_type, rest_type...>& target,
|
|
||||||
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;
|
|
||||||
target.templet_type::add(inst);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<int n, typename... args_type> class SlicePosition;
|
|
||||||
|
|
||||||
template<typename S, typename T> class SliceValidator : public Validator<S> {
|
|
||||||
private:
|
|
||||||
std::function<T(S)> _proc_conv;
|
|
||||||
Validator<T> _sub_validator;
|
|
||||||
|
|
||||||
public:
|
|
||||||
SliceValidator(std::function<T(S)> proc, Validator<T> vinst)
|
|
||||||
: _proc_conv(proc), _sub_validator(vinst) { }
|
|
||||||
|
|
||||||
virtual bool check(S value) const {
|
|
||||||
auto t_value = _proc_conv(value);
|
|
||||||
return _sub_validator.check(t_value);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
template<int n, typename... args_type> class ArgsPosition
|
|
||||||
: public ValidatorReceiver<typename ElmPos<n, ValidateTemplet<args_type...>>::value_type> {
|
|
||||||
public:
|
|
||||||
using param_type = typename ElmPos<n, ValidateTemplet<args_type...>>::value_type;
|
|
||||||
|
|
||||||
ArgsPosition(ValidateTemplet<args_type...>& target) :_templet_bind(target) { }
|
|
||||||
|
|
||||||
ArgsPosition<n, args_type...>& operator&(Validator<param_type> vinst) {
|
|
||||||
append(vinst);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename slice_type>
|
|
||||||
SlicePosition<n, param_type, slice_type, ArgsPosition<n, args_type...>>
|
|
||||||
slice(std::function<slice_type(param_type)> slice_fun) {
|
|
||||||
return SlicePosition<n, param_type, slice_type, ArgsPosition<n, args_type...>>(*this, slice_fun);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ValidatorReceiver
|
|
||||||
virtual void append(Validator<param_type> inst) {
|
|
||||||
__validator_insert_helper<n, args_type...>(_templet_bind, inst);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
ValidateTemplet<args_type...>& _templet_bind;
|
|
||||||
};
|
|
||||||
template<int n, typename s_type, typename t_type, typename... args_type>
|
|
||||||
class SlicePosition<n, s_type, t_type, ArgsPosition<n, args_type...>> : public ValidatorReceiver<t_type> {
|
|
||||||
public:
|
|
||||||
SlicePosition(ValidatorReceiver<s_type>& host, std::function<t_type(s_type)> func)
|
|
||||||
:_conv_func(func), _prev_bind(host) { }
|
|
||||||
|
|
||||||
SlicePosition<n, s_type, t_type, ArgsPosition<n, args_type...>>& operator&(Validator<t_type> vinst) {
|
|
||||||
append(vinst);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename slice_type>
|
|
||||||
SlicePosition<n, t_type, slice_type, ArgsPosition<n, args_type...>>
|
|
||||||
slice(std::function<slice_type(t_type)> slice_fun) {
|
|
||||||
return SlicePosition<n, t_type, slice_type, ArgsPosition<n, args_type...>>(*this, slice_fun);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ValidatorReceiver
|
|
||||||
virtual void append(Validator<t_type> inst) {
|
|
||||||
SliceValidator<s_type, t_type> mid_validator(_conv_func, inst);
|
|
||||||
_prev_bind.append(mid_validator);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::function<t_type(s_type)> _conv_func;
|
|
||||||
ValidatorReceiver<s_type>& _prev_bind;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class IValidatorTemplet {
|
|
||||||
public:
|
|
||||||
virtual bool doValidate(Inlet::IRunbase* inst) const = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<void* func, typename... types> struct ValidateHelper;
|
|
||||||
template<void* func, typename return_type, typename... args_type>
|
|
||||||
struct ValidateHelper<func, return_type, args_type...> : public ValidateTemplet<args_type...>, public IValidatorTemplet {
|
|
||||||
quint64 address() const {
|
|
||||||
return (quint64) func;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<int n> ArgsPosition<n, args_type...> pos() {
|
|
||||||
return ArgsPosition<n, args_type...>(*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ivalidatortemplet
|
|
||||||
virtual bool doValidate(Inlet::IRunbase* inst) const {
|
|
||||||
auto valid_data = dynamic_cast<Inlet::CmdsImpl<func, return_type, args_type...>*>(inst);
|
|
||||||
return ValidateTemplet<args_type...>::validateFor(valid_data->getArgSequence());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,178 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
#include <QList>
|
||||||
|
#include <functional>
|
||||||
|
#include "cmds_basic.h"
|
||||||
|
|
||||||
|
namespace validate {
|
||||||
|
template<typename T> class Validator {
|
||||||
|
public:
|
||||||
|
virtual bool check(T value) const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
virtual void getDepict(datas::IDataObject& self_description) { }
|
||||||
|
};
|
||||||
|
template<typename T> class ValidatorReceiver {
|
||||||
|
public:
|
||||||
|
virtual void append(Validator<T>* inst) { }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<typename... args_type> struct ValidateTemplet;
|
||||||
|
template<> struct ValidateTemplet<> {
|
||||||
|
|
||||||
|
template<typename Ret>
|
||||||
|
bool validateFor(Inlet::SignatureImpl<Ret>& value_sequence) const {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template<typename head_type, typename... rest_type>
|
||||||
|
struct ValidateTemplet<head_type, rest_type...> : public ValidateTemplet<rest_type...> {
|
||||||
|
private:
|
||||||
|
QList<Validator<head_type>*> validator_list;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void add(Validator<head_type>* vinst) {
|
||||||
|
validator_list << vinst;
|
||||||
|
}
|
||||||
|
bool check(head_type value) const {
|
||||||
|
for (auto u : validator_list)
|
||||||
|
if (!u->check(value))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Ret>
|
||||||
|
bool validateFor(Inlet::SignatureImpl<Ret, head_type, rest_type...>& value_sequence) const {
|
||||||
|
head_type head_value = value_sequence.getArgs0();
|
||||||
|
if (!check(head_value))
|
||||||
|
return false;
|
||||||
|
return ValidateTemplet<rest_type...>::validateFor(value_sequence);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<int idx, typename... args_type> struct ElmPos;
|
||||||
|
|
||||||
|
template<typename head_type, typename... rest_type>
|
||||||
|
struct ElmPos<0, ValidateTemplet<head_type, rest_type...>> {
|
||||||
|
using value_type = head_type;
|
||||||
|
using templet_type = ValidateTemplet<head_type, rest_type...>;
|
||||||
|
};
|
||||||
|
template<int idx, typename head_type, typename... rest_type>
|
||||||
|
struct ElmPos<idx, ValidateTemplet<head_type, rest_type...>> {
|
||||||
|
using value_type = typename ElmPos<idx - 1, ValidateTemplet<rest_type...>>::value_type;
|
||||||
|
using templet_type = typename ElmPos<idx - 1, ValidateTemplet<rest_type...>>::templet_type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<int idx, typename head_type, typename... rest_type>
|
||||||
|
void __validator_insert_helper(ValidateTemplet<head_type, rest_type...>& target,
|
||||||
|
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;
|
||||||
|
target.templet_type::add(inst);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<int n, typename... args_type> class SlicePosition;
|
||||||
|
|
||||||
|
template<typename S, typename T> class SliceValidator : public Validator<S> {
|
||||||
|
private:
|
||||||
|
std::function<T(S)> _proc_conv;
|
||||||
|
Validator<T> _sub_validator;
|
||||||
|
|
||||||
|
public:
|
||||||
|
SliceValidator(std::function<T(S)> proc, Validator<T> vinst)
|
||||||
|
: _proc_conv(proc), _sub_validator(vinst) { }
|
||||||
|
|
||||||
|
virtual bool check(S value) const {
|
||||||
|
auto t_value = _proc_conv(value);
|
||||||
|
return _sub_validator.check(t_value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template<int n, typename... args_type> class ArgsPosition
|
||||||
|
: public ValidatorReceiver<typename ElmPos<n, ValidateTemplet<args_type...>>::value_type> {
|
||||||
|
public:
|
||||||
|
using param_type = typename ElmPos<n, ValidateTemplet<args_type...>>::value_type;
|
||||||
|
|
||||||
|
ArgsPosition(ValidateTemplet<args_type...>& target) :_templet_bind(target) { }
|
||||||
|
|
||||||
|
ArgsPosition<n, args_type...>& operator&(Validator<param_type>* vinst) {
|
||||||
|
append(vinst);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename slice_type>
|
||||||
|
SlicePosition<n, param_type, slice_type, ArgsPosition<n, args_type...>>
|
||||||
|
slice(std::function<slice_type(param_type)> slice_fun) {
|
||||||
|
return SlicePosition<n, param_type, slice_type, ArgsPosition<n, args_type...>>(*this, slice_fun);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidatorReceiver
|
||||||
|
virtual void append(Validator<param_type>* inst) {
|
||||||
|
__validator_insert_helper<n, args_type...>(_templet_bind, inst);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
ValidateTemplet<args_type...>& _templet_bind;
|
||||||
|
};
|
||||||
|
template<int n, typename s_type, typename t_type, typename... args_type>
|
||||||
|
class SlicePosition<n, s_type, t_type, ArgsPosition<n, args_type...>> : public ValidatorReceiver<t_type> {
|
||||||
|
public:
|
||||||
|
SlicePosition(ValidatorReceiver<s_type>& host, std::function<t_type(s_type)> func)
|
||||||
|
:_conv_func(func), _prev_bind(host) { }
|
||||||
|
|
||||||
|
SlicePosition<n, s_type, t_type, ArgsPosition<n, args_type...>>& operator&(Validator<t_type>* vinst) {
|
||||||
|
append(vinst);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename slice_type>
|
||||||
|
SlicePosition<n, t_type, slice_type, ArgsPosition<n, args_type...>>
|
||||||
|
slice(std::function<slice_type(t_type)> slice_fun) {
|
||||||
|
return SlicePosition<n, t_type, slice_type, ArgsPosition<n, args_type...>>(*this, slice_fun);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidatorReceiver
|
||||||
|
virtual void append(Validator<t_type>* inst) {
|
||||||
|
SliceValidator<s_type, t_type> mid_validator(_conv_func, inst);
|
||||||
|
_prev_bind.append(mid_validator);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::function<t_type(s_type)> _conv_func;
|
||||||
|
ValidatorReceiver<s_type>& _prev_bind;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class IValidatorTemplet {
|
||||||
|
public:
|
||||||
|
virtual bool doValidate(Inlet::IRunbase* inst) const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<void* func, typename... types> struct ValidateImpls;
|
||||||
|
template<void* func, typename return_type, typename... args_type>
|
||||||
|
struct ValidateImpls<func, return_type, args_type...> : public ValidateTemplet<args_type...>, public IValidatorTemplet {
|
||||||
|
quint64 address() const {
|
||||||
|
return (quint64) func;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<int n> ArgsPosition<n, args_type...> pos() {
|
||||||
|
return ArgsPosition<n, args_type...>(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ivalidatortemplet
|
||||||
|
virtual bool doValidate(Inlet::IRunbase* inst) const {
|
||||||
|
auto valid_data = dynamic_cast<Inlet::CmdsImpl<func, return_type, args_type...>*>(inst);
|
||||||
|
return ValidateTemplet<args_type...>::validateFor(valid_data->getArgSequence());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in New Issue