diff --git a/PenetrateBasic/PenetrateBasic.vcxproj b/PenetrateBasic/PenetrateBasic.vcxproj index 381ea67..ba7ecd8 100644 --- a/PenetrateBasic/PenetrateBasic.vcxproj +++ b/PenetrateBasic/PenetrateBasic.vcxproj @@ -104,6 +104,7 @@ + diff --git a/PenetrateBasic/PenetrateBasic.vcxproj.filters b/PenetrateBasic/PenetrateBasic.vcxproj.filters index 01c677c..912a0f4 100644 --- a/PenetrateBasic/PenetrateBasic.vcxproj.filters +++ b/PenetrateBasic/PenetrateBasic.vcxproj.filters @@ -55,5 +55,8 @@ Header Files + + Header Files + \ No newline at end of file diff --git a/PenetrateBasic/dispatch.h b/PenetrateBasic/dispatch.h index 23d5b82..ad2222d 100644 --- a/PenetrateBasic/dispatch.h +++ b/PenetrateBasic/dispatch.h @@ -3,7 +3,7 @@ #include #include #include "cmds_basic.h" -#include "validation.h" +#include "validation_basic.h" namespace dispatch { class IOutput { diff --git a/PenetrateBasic/main.cpp b/PenetrateBasic/main.cpp index 39a207b..fa1381e 100644 --- a/PenetrateBasic/main.cpp +++ b/PenetrateBasic/main.cpp @@ -4,12 +4,15 @@ #include "cmds_basic.h" #include "dispatch.h" #include "cmds.h" +#include "validation.h" int vp(int c) { qDebug() << c; return c; } +verify::T::Validation vp_check; + namespace xproc { int xmp(int arg) { qDebug() << "xmp"; @@ -19,8 +22,6 @@ namespace xproc { cmds::T::Cmd entry("hello"); cmds::T::Cmd xvv("sfaf"); -#include "validation.h" -validate::ValidateHelper<(void*)vp, int, int> helper; using namespace Inlet; diff --git a/PenetrateBasic/validation.h b/PenetrateBasic/validation.h index 70b4c95..b35c494 100644 --- a/PenetrateBasic/validation.h +++ b/PenetrateBasic/validation.h @@ -1,182 +1,27 @@ #pragma once -#include -#include -#include -#include -#include "data_types.h" -#include "cmds_basic.h" +#include "validation_basic.h" +#include "dispatch.h" +namespace verify { + template struct T; -namespace validate { - template class Validator { - public: - virtual bool check(T value) const { - return false; - } - virtual void getDepict(datas::IDataObject& self_description) { } + template + struct T { + template func> + struct Validation { + private: + validate::ValidateImpls<(void*)func, Ret, Args...> _helper; + + public: + Validation() { + auto core = dispatch::Dispatch::unique(); + core->setCmdValidator(_helper.address(), & _helper); + } + + template validate::ArgsPosition pos() { + return _helper.pos(); + } + }; }; - template class ValidatorReceiver { - public: - virtual void append(Validator inst) { } - }; - - - - - template struct ValidateTemplet; - template<> struct ValidateTemplet<> { - - template - bool validateFor(Inlet::SignatureImpl& value_sequence) const { - return true; - } - }; - template - struct ValidateTemplet : public ValidateTemplet { - private: - QList> validator_list; - - public: - void add(Validator vinst) { - validator_list << vinst; - } - bool check(head_type value) const { - for (auto u : validator_list) - if (!u.check(value)) - return false; - return true; - } - - template - bool validateFor(Inlet::SignatureImpl& value_sequence) const { - head_type head_value = value_sequence.getArgs0(); - if (!check(head_value)) - return false; - return ValidateTemplet::validateFor(value_sequence); - } - }; - - - - - template struct ElmPos; - - template - struct ElmPos<0, ValidateTemplet> { - using value_type = head_type; - using templet_type = ValidateTemplet; - }; - template - struct ElmPos> { - using value_type = typename ElmPos>::value_type; - using templet_type = typename ElmPos>::templet_type; - }; - - template - void __validator_insert_helper(ValidateTemplet& target, - Validator>::value_type> inst) { - using templet_type = typename ElmPos>::templet_type; - target.templet_type::add(inst); - } - - - - - template class SlicePosition; - - template class SliceValidator : public Validator { - private: - std::function _proc_conv; - Validator _sub_validator; - - public: - SliceValidator(std::function proc, Validator 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 class ArgsPosition - : public ValidatorReceiver>::value_type> { - public: - using param_type = typename ElmPos>::value_type; - - ArgsPosition(ValidateTemplet& target) :_templet_bind(target) { } - - ArgsPosition& operator&(Validator vinst) { - append(vinst); - return *this; - } - - template - SlicePosition> - slice(std::function slice_fun) { - return SlicePosition>(*this, slice_fun); - } - - // ValidatorReceiver - virtual void append(Validator inst) { - __validator_insert_helper(_templet_bind, inst); - } - - private: - ValidateTemplet& _templet_bind; - }; - template - class SlicePosition> : public ValidatorReceiver { - public: - SlicePosition(ValidatorReceiver& host, std::function func) - :_conv_func(func), _prev_bind(host) { } - - SlicePosition>& operator&(Validator vinst) { - append(vinst); - return *this; - } - - template - SlicePosition> - slice(std::function slice_fun) { - return SlicePosition>(*this, slice_fun); - } - - // ValidatorReceiver - virtual void append(Validator inst) { - SliceValidator mid_validator(_conv_func, inst); - _prev_bind.append(mid_validator); - } - - private: - std::function _conv_func; - ValidatorReceiver& _prev_bind; - }; - - - - - class IValidatorTemplet { - public: - virtual bool doValidate(Inlet::IRunbase* inst) const = 0; - }; - - template struct ValidateHelper; - template - struct ValidateHelper : public ValidateTemplet, public IValidatorTemplet { - quint64 address() const { - return (quint64) func; - } - - template ArgsPosition pos() { - return ArgsPosition(*this); - } - - // Ivalidatortemplet - virtual bool doValidate(Inlet::IRunbase* inst) const { - auto valid_data = dynamic_cast*>(inst); - return ValidateTemplet::validateFor(valid_data->getArgSequence()); - } - }; - -} \ No newline at end of file +} diff --git a/PenetrateBasic/validation_basic.h b/PenetrateBasic/validation_basic.h new file mode 100644 index 0000000..ef412c2 --- /dev/null +++ b/PenetrateBasic/validation_basic.h @@ -0,0 +1,178 @@ +#pragma once + +#include +#include +#include +#include "cmds_basic.h" + +namespace validate { + template class Validator { + public: + virtual bool check(T value) const { + return false; + } + virtual void getDepict(datas::IDataObject& self_description) { } + }; + template class ValidatorReceiver { + public: + virtual void append(Validator inst) { } + }; + + + + + template struct ValidateTemplet; + template<> struct ValidateTemplet<> { + + template + bool validateFor(Inlet::SignatureImpl& value_sequence) const { + return true; + } + }; + template + struct ValidateTemplet : public ValidateTemplet { + private: + QList> validator_list; + + public: + void add(Validator vinst) { + validator_list << vinst; + } + bool check(head_type value) const { + for (auto u : validator_list) + if (!u.check(value)) + return false; + return true; + } + + template + bool validateFor(Inlet::SignatureImpl& value_sequence) const { + head_type head_value = value_sequence.getArgs0(); + if (!check(head_value)) + return false; + return ValidateTemplet::validateFor(value_sequence); + } + }; + + + + + template struct ElmPos; + + template + struct ElmPos<0, ValidateTemplet> { + using value_type = head_type; + using templet_type = ValidateTemplet; + }; + template + struct ElmPos> { + using value_type = typename ElmPos>::value_type; + using templet_type = typename ElmPos>::templet_type; + }; + + template + void __validator_insert_helper(ValidateTemplet& target, + Validator>::value_type> inst) { + using templet_type = typename ElmPos>::templet_type; + target.templet_type::add(inst); + } + + + + + template class SlicePosition; + + template class SliceValidator : public Validator { + private: + std::function _proc_conv; + Validator _sub_validator; + + public: + SliceValidator(std::function proc, Validator 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 class ArgsPosition + : public ValidatorReceiver>::value_type> { + public: + using param_type = typename ElmPos>::value_type; + + ArgsPosition(ValidateTemplet& target) :_templet_bind(target) { } + + ArgsPosition& operator&(Validator vinst) { + append(vinst); + return *this; + } + + template + SlicePosition> + slice(std::function slice_fun) { + return SlicePosition>(*this, slice_fun); + } + + // ValidatorReceiver + virtual void append(Validator inst) { + __validator_insert_helper(_templet_bind, inst); + } + + private: + ValidateTemplet& _templet_bind; + }; + template + class SlicePosition> : public ValidatorReceiver { + public: + SlicePosition(ValidatorReceiver& host, std::function func) + :_conv_func(func), _prev_bind(host) { } + + SlicePosition>& operator&(Validator vinst) { + append(vinst); + return *this; + } + + template + SlicePosition> + slice(std::function slice_fun) { + return SlicePosition>(*this, slice_fun); + } + + // ValidatorReceiver + virtual void append(Validator inst) { + SliceValidator mid_validator(_conv_func, inst); + _prev_bind.append(mid_validator); + } + + private: + std::function _conv_func; + ValidatorReceiver& _prev_bind; + }; + + + + + class IValidatorTemplet { + public: + virtual bool doValidate(Inlet::IRunbase* inst) const = 0; + }; + + template struct ValidateImpls; + template + struct ValidateImpls : public ValidateTemplet, public IValidatorTemplet { + quint64 address() const { + return (quint64) func; + } + + template ArgsPosition pos() { + return ArgsPosition(*this); + } + + // Ivalidatortemplet + virtual bool doValidate(Inlet::IRunbase* inst) const { + auto valid_data = dynamic_cast*>(inst); + return ValidateTemplet::validateFor(valid_data->getArgSequence()); + } + }; +}