From 213fdbf5aa4c70b404eb40e7177ab44697b4bef8 Mon Sep 17 00:00:00 2001 From: codeboss <2422523675@qq.com> Date: Sat, 16 Nov 2024 19:55:32 +0800 Subject: [PATCH] update --- PenetrateBasic/validation.h | 160 ++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 PenetrateBasic/validation.h diff --git a/PenetrateBasic/validation.h b/PenetrateBasic/validation.h new file mode 100644 index 0000000..bc2f359 --- /dev/null +++ b/PenetrateBasic/validation.h @@ -0,0 +1,160 @@ +#pragma once + +#include +#include +#include +#include + + +namespace validate { + template class validator { + public: + virtual bool check(T value) const { + return false; + } + }; + template class validator_receiver { + public: + virtual void append(validator inst) { } + }; + + + + + template struct check_delegation; + template<> struct check_delegation<> { + + void prest() { + std::cout << "ends" << std::endl; + } + }; + template + struct check_delegation : public check_delegation { + private: + QList> validator_list; + + public: + void add(validator vinst) { + validator_list << vinst; + } + bool check(head_type value) { + for (auto u : validator_list) + if (!u.check(value)) + return false; + return true; + } + + void prest() { + std::cout << "[-]" << validator_list.size() << std::endl; + check_delegation::prest(); + } + }; + + + + + template struct elm_pos; + + template + struct elm_pos<0, check_delegation> { + using value_type = head_type; + using templet_type = check_delegation; + }; + template + struct elm_pos> { + using value_type = typename elm_pos>::value_type; + using templet_type = typename elm_pos>::templet_type; + }; + + template + void __validator_insert_helper(check_delegation& target, + validator>::value_type> inst) { + using templet_type = typename elm_pos>::templet_type; + target.templet_type::add(inst); + } + + + + + template class slice_position; + + template class slice_validator : public validator { + private: + std::function _proc_conv; + validator _sub_validator; + + public: + slice_validator(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 args_position + : public validator_receiver>::value_type> { + public: + using param_type = typename elm_pos>::value_type; + + args_position(check_delegation& target) :_templet_bind(target) { } + + args_position& operator&(validator vinst) { + append(vinst); + return *this; + } + + template + slice_position> + slice(std::function slice_fun) { + return slice_position>(*this, slice_fun); + } + + // validator_receiver + virtual void append(validator inst) { + __validator_insert_helper(_templet_bind, inst); + } + + private: + check_delegation& _templet_bind; + }; + template + class slice_position> : public validator_receiver { + public: + slice_position(validator_receiver& host, std::function func) + :_conv_func(func), _prev_bind(host) { } + + slice_position>& operator&(validator vinst) { + append(vinst); + return *this; + } + + template + slice_position> + slice(std::function slice_fun) { + return slice_position>(*this, slice_fun); + } + + // validator_receiver + virtual void append(validator inst) { + slice_validator mid_validator(_conv_func, inst); + _prev_bind.append(mid_validator); + } + + private: + std::function _conv_func; + validator_receiver& _prev_bind; + }; + + + + + template struct validate_helper; + template + struct validate_helper : public check_delegation { + template args_position pos() { + return args_position(*this); + } + }; + +} \ No newline at end of file