update
This commit is contained in:
parent
036d94f7ca
commit
265c7ecbb0
|
@ -52,7 +52,7 @@ int main(int argc, char* argv[]) {
|
|||
|
||||
depict::ValidateDocObject doc;
|
||||
dispatch::Dispatch::unique()->getValidateDepict(doc);
|
||||
qDebug() << doc.toText();
|
||||
qDebug().noquote() << doc.toText();
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace validate {
|
|||
|
||||
|
||||
|
||||
template<typename... args_type> struct ValidateTemplet;
|
||||
template<typename... Args> struct ValidateTemplet;
|
||||
template<> struct ValidateTemplet<> {
|
||||
template<typename Ret>
|
||||
bool validateFor(Inlet::SignatureImpl<Ret>& value_sequence) const {
|
||||
|
@ -33,16 +33,16 @@ namespace validate {
|
|||
|
||||
virtual void getDepict(datas::IDataObject& self_description) const {}
|
||||
};
|
||||
template<typename head_type, typename... rest_type>
|
||||
struct ValidateTemplet<head_type, rest_type...> : public ValidateTemplet<rest_type...> {
|
||||
template<typename Head, typename... Rest>
|
||||
struct ValidateTemplet<Head, Rest...> : public ValidateTemplet<Rest...> {
|
||||
private:
|
||||
QList<Validator<head_type>*> validator_list;
|
||||
QList<Validator<Head>*> validator_list;
|
||||
|
||||
public:
|
||||
void add(Validator<head_type>* vinst) {
|
||||
void add(Validator<Head>* vinst) {
|
||||
validator_list << vinst;
|
||||
}
|
||||
bool check(head_type value) const {
|
||||
bool check(Head value) const {
|
||||
for (auto u : validator_list)
|
||||
if (!u->check(value))
|
||||
return false;
|
||||
|
@ -50,11 +50,11 @@ namespace validate {
|
|||
}
|
||||
|
||||
template<typename Ret>
|
||||
bool validateFor(Inlet::SignatureImpl<Ret, head_type, rest_type...>& value_sequence) const {
|
||||
head_type head_value = value_sequence.getArgs0();
|
||||
bool validateFor(Inlet::SignatureImpl<Ret, Head, Rest...>& value_sequence) const {
|
||||
Head head_value = value_sequence.getArgs0();
|
||||
if (!check(head_value))
|
||||
return false;
|
||||
return ValidateTemplet<rest_type...>::validateFor(value_sequence);
|
||||
return ValidateTemplet<Rest...>::validateFor(value_sequence);
|
||||
}
|
||||
|
||||
|
||||
|
@ -69,37 +69,37 @@ namespace validate {
|
|||
auto args_array = std::dynamic_pointer_cast<datas::IDataArray>(self_description.getChild(u8"ArgsList"));
|
||||
args_array->append(args_head);
|
||||
self_description.setChild(u8"ArgsList", args_array);
|
||||
ValidateTemplet<rest_type...>::getDepict(self_description);
|
||||
ValidateTemplet<Rest...>::getDepict(self_description);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
template<int idx, typename... args_type> struct ElmPos;
|
||||
template<int idx, typename... Args> 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<typename Head, typename... Rest>
|
||||
struct ElmPos<0, ValidateTemplet<Head, Rest...>> {
|
||||
using value_type = Head;
|
||||
using templet_type = ValidateTemplet<Head, Rest...>;
|
||||
};
|
||||
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, typename... Rest>
|
||||
struct ElmPos<idx, ValidateTemplet<Head, Rest...>> {
|
||||
using value_type = typename ElmPos<idx - 1, ValidateTemplet<Rest...>>::value_type;
|
||||
using templet_type = typename ElmPos<idx - 1, ValidateTemplet<Rest...>>::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;
|
||||
template<int idx, typename Head, typename... Rest>
|
||||
void __validator_insert_helper(ValidateTemplet<Head, Rest...>& target,
|
||||
Validator<typename ElmPos<idx, ValidateTemplet<Head, Rest...>>::value_type>* inst) {
|
||||
using templet_type = typename ElmPos<idx, ValidateTemplet<Head, Rest...>>::templet_type;
|
||||
target.templet_type::add(inst);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template<int n, typename... args_type> class SlicePosition;
|
||||
template<int n, typename... Args> class SlicePosition;
|
||||
|
||||
template<typename S, typename T> class SliceValidator : public Validator<S> {
|
||||
private:
|
||||
|
@ -115,58 +115,58 @@ namespace validate {
|
|||
return _sub_validator.check(t_value);
|
||||
}
|
||||
};
|
||||
template<int n, typename... args_type> class ArgsPosition
|
||||
: public ValidatorReceiver<typename ElmPos<n, ValidateTemplet<args_type...>>::value_type> {
|
||||
template<int n, typename... Args> class ArgsPosition
|
||||
: public ValidatorReceiver<typename ElmPos<n, ValidateTemplet<Args...>>::value_type> {
|
||||
public:
|
||||
using param_type = typename ElmPos<n, ValidateTemplet<args_type...>>::value_type;
|
||||
using Param = typename ElmPos<n, ValidateTemplet<Args...>>::value_type;
|
||||
|
||||
ArgsPosition(ValidateTemplet<args_type...>& target) :_templet_bind(target) { }
|
||||
ArgsPosition(ValidateTemplet<Args...>& target) :_templet_bind(target) { }
|
||||
|
||||
ArgsPosition<n, args_type...>& operator&(Validator<param_type>* vinst) {
|
||||
ArgsPosition<n, Args...>& operator&(Validator<Param>* 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);
|
||||
template<typename Slice>
|
||||
SlicePosition<n, Param, Slice, ArgsPosition<n, Args...>>
|
||||
slice(std::function<Slice(Param)> slice_fun) {
|
||||
return SlicePosition<n, Param, Slice, ArgsPosition<n, Args...>>(*this, slice_fun);
|
||||
}
|
||||
|
||||
// ValidatorReceiver
|
||||
virtual void append(Validator<param_type>* inst) {
|
||||
__validator_insert_helper<n, args_type...>(_templet_bind, inst);
|
||||
virtual void append(Validator<Param>* inst) {
|
||||
__validator_insert_helper<n, Args...>(_templet_bind, inst);
|
||||
}
|
||||
|
||||
private:
|
||||
ValidateTemplet<args_type...>& _templet_bind;
|
||||
ValidateTemplet<Args...>& _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> {
|
||||
template<int n, typename S, typename T, typename... Args>
|
||||
class SlicePosition<n, S, T, ArgsPosition<n, Args...>> : public ValidatorReceiver<T> {
|
||||
public:
|
||||
SlicePosition(ValidatorReceiver<s_type>& host, std::function<t_type(s_type)> func)
|
||||
SlicePosition(ValidatorReceiver<S>& host, std::function<T(S)> func)
|
||||
:_conv_func(func), _prev_bind(host) { }
|
||||
|
||||
SlicePosition<n, s_type, t_type, ArgsPosition<n, args_type...>>& operator&(Validator<t_type>* vinst) {
|
||||
SlicePosition<n, S, T, ArgsPosition<n, Args...>>& operator&(Validator<T>* 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);
|
||||
template<typename Slice>
|
||||
SlicePosition<n, T, Slice, ArgsPosition<n, Args...>>
|
||||
slice(std::function<Slice(T)> slice_fun) {
|
||||
return SlicePosition<n, T, Slice, ArgsPosition<n, Args...>>(*this, slice_fun);
|
||||
}
|
||||
|
||||
// ValidatorReceiver
|
||||
virtual void append(Validator<t_type>* inst) {
|
||||
SliceValidator<s_type, t_type> mid_validator(_conv_func, inst);
|
||||
virtual void append(Validator<T>* inst) {
|
||||
SliceValidator<S, T> mid_validator(_conv_func, inst);
|
||||
_prev_bind.append(mid_validator);
|
||||
}
|
||||
|
||||
private:
|
||||
std::function<t_type(s_type)> _conv_func;
|
||||
ValidatorReceiver<s_type>& _prev_bind;
|
||||
std::function<T(S)> _conv_func;
|
||||
ValidatorReceiver<S>& _prev_bind;
|
||||
};
|
||||
|
||||
|
||||
|
@ -179,20 +179,20 @@ namespace validate {
|
|||
};
|
||||
|
||||
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 {
|
||||
template<void* func, typename Ret, typename... Args>
|
||||
struct ValidateImpls<func, Ret, Args...> : public ValidateTemplet<Args...>, public IValidatorTemplet {
|
||||
quint64 address() const {
|
||||
return (quint64) func;
|
||||
}
|
||||
|
||||
template<int n> ArgsPosition<n, args_type...> pos() {
|
||||
return ArgsPosition<n, args_type...>(*this);
|
||||
template<int n> ArgsPosition<n, Args...> pos() {
|
||||
return ArgsPosition<n, Args...>(*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());
|
||||
auto valid_data = dynamic_cast<Inlet::CmdsImpl<func, Ret, Args...>*>(inst);
|
||||
return ValidateTemplet<Args...>::validateFor(valid_data->getArgSequence());
|
||||
}
|
||||
|
||||
virtual void getDepict(datas::IDataObject& self_description) const {
|
||||
|
@ -200,7 +200,7 @@ namespace validate {
|
|||
|
||||
auto array_l = self_description.newArray();
|
||||
self_description.setChild(u8"ArgsList", array_l);
|
||||
ValidateTemplet<args_type...>::getDepict(self_description);
|
||||
ValidateTemplet<Args...>::getDepict(self_description);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ namespace impls {
|
|||
_limit_max_times = static_cast<int64_t>(max * precision) + max_equal;
|
||||
}
|
||||
|
||||
virtual QString name() const{ return _name_store; }
|
||||
|
||||
virtual bool check(double value) const {
|
||||
auto value_times = static_cast<int>(value * precision);
|
||||
|
@ -51,6 +52,9 @@ namespace impls {
|
|||
}
|
||||
|
||||
|
||||
virtual QString name() const {
|
||||
return _name_store;
|
||||
}
|
||||
virtual bool check(int32_t value) const {
|
||||
return _limit_min_times < value && value < _limit_max_times;
|
||||
}
|
||||
|
@ -82,6 +86,9 @@ namespace impls {
|
|||
_limit_min_times = _limit_min - min_equal;
|
||||
}
|
||||
|
||||
virtual QString name() const {
|
||||
return _name_store;
|
||||
}
|
||||
|
||||
virtual bool check(int64_t value) const {
|
||||
return _limit_min_times < value && value < _limit_max_times;
|
||||
|
@ -109,6 +116,9 @@ namespace impls {
|
|||
EnumsValidator(const QString& name, const QList<int32_t>& list)
|
||||
:_name_store(name), _enum_options(list) { }
|
||||
|
||||
virtual QString name() const {
|
||||
return _name_store;
|
||||
}
|
||||
virtual bool check(int32_t value) const {
|
||||
return _enum_options.contains(value);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue