validator描述输出
This commit is contained in:
parent
f14020493b
commit
036d94f7ca
|
@ -47,6 +47,18 @@ void Dispatch::runWith(IRunbase* unit) {
|
|||
unit->run();
|
||||
}
|
||||
|
||||
void dispatch::Dispatch::getValidateDepict(datas::IDataObject& object) const {
|
||||
for (auto key : _cmds_validators.keys()) {
|
||||
if (_cmds_map.contains(key)) {
|
||||
auto alias = _cmds_map[key].first;
|
||||
auto vdesc = object.newObject();
|
||||
|
||||
_cmds_validators[key]->getDepict(*vdesc);
|
||||
object.setChild(alias, vdesc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QList<quint64> dispatch::Dispatch::allEvents() const {
|
||||
return _events_map.keys();
|
||||
}
|
||||
|
|
|
@ -35,6 +35,8 @@ namespace dispatch {
|
|||
QString getCmdDefault(quint64 addr) const;
|
||||
void runWith(Inlet::IRunbase* unit);
|
||||
|
||||
void getValidateDepict(datas::IDataObject &object) const;
|
||||
|
||||
QList<quint64> allEvents() const;
|
||||
void registerEvent(quint64 addr, Inlet::IRunbase* unit);
|
||||
void setEventAlias(quint64 addr, const QString& alias);
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "cmds.h"
|
||||
#include "validate.h"
|
||||
#include "validate_impl.h"
|
||||
#include "validate_depict.h"
|
||||
|
||||
int vp(int c) {
|
||||
qDebug() << c;
|
||||
|
@ -49,5 +50,9 @@ int main(int argc, char* argv[]) {
|
|||
entry(3);
|
||||
xvv(2);
|
||||
|
||||
depict::ValidateDocObject doc;
|
||||
dispatch::Dispatch::unique()->getValidateDepict(doc);
|
||||
qDebug() << doc.toText();
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
|
|
|
@ -8,6 +8,9 @@
|
|||
namespace validate {
|
||||
template<typename T> class Validator {
|
||||
public:
|
||||
virtual QString name() const {
|
||||
return QString();
|
||||
}
|
||||
virtual bool check(T value) const {
|
||||
return false;
|
||||
}
|
||||
|
@ -23,11 +26,12 @@ namespace validate {
|
|||
|
||||
template<typename... args_type> struct ValidateTemplet;
|
||||
template<> struct ValidateTemplet<> {
|
||||
|
||||
template<typename Ret>
|
||||
bool validateFor(Inlet::SignatureImpl<Ret>& value_sequence) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
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...> {
|
||||
|
@ -52,6 +56,21 @@ namespace validate {
|
|||
return false;
|
||||
return ValidateTemplet<rest_type...>::validateFor(value_sequence);
|
||||
}
|
||||
|
||||
|
||||
virtual void getDepict(datas::IDataObject& self_description) const {
|
||||
auto args_head = self_description.newObject();
|
||||
for (auto vinst : validator_list) {
|
||||
auto vdesc = self_description.newObject();
|
||||
vinst->getDepict(*vdesc);
|
||||
args_head->setChild(vinst->name(), vdesc);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
@ -156,6 +175,7 @@ namespace validate {
|
|||
class IValidatorTemplet {
|
||||
public:
|
||||
virtual bool doValidate(Inlet::IRunbase* inst) const = 0;
|
||||
virtual void getDepict(datas::IDataObject& self_description) const = 0;
|
||||
};
|
||||
|
||||
template<void* func, typename... types> struct ValidateImpls;
|
||||
|
@ -174,5 +194,13 @@ namespace validate {
|
|||
auto valid_data = dynamic_cast<Inlet::CmdsImpl<func, return_type, args_type...>*>(inst);
|
||||
return ValidateTemplet<args_type...>::validateFor(valid_data->getArgSequence());
|
||||
}
|
||||
|
||||
virtual void getDepict(datas::IDataObject& self_description) const {
|
||||
self_description.setString(u8"ValidateFor", QString::number((qulonglong)func));
|
||||
|
||||
auto array_l = self_description.newArray();
|
||||
self_description.setChild(u8"ArgsList", array_l);
|
||||
ValidateTemplet<args_type...>::getDepict(self_description);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -20,11 +20,11 @@ bool ValidateDocObject::isObject() const {
|
|||
}
|
||||
|
||||
std::shared_ptr<IDataArray> ValidateDocObject::newArray() const {
|
||||
return std::shared_ptr<IDataArray>();
|
||||
return std::make_shared<ValidateDocArray>();
|
||||
}
|
||||
|
||||
std::shared_ptr<IDataObject> ValidateDocObject::newObject() const {
|
||||
return std::shared_ptr<IDataObject>();
|
||||
return std::make_shared<ValidateDocObject>();
|
||||
}
|
||||
|
||||
std::shared_ptr<IDataComplex> ValidateDocObject::getChild(const QString& key) const {
|
||||
|
|
Loading…
Reference in New Issue