#pragma once #include "componentbasic_global.h" #include #include /// /// 消息处理单元基类 /// /// 输入类型 /// 输出类型 template class WsRespond { public: using SelfType = WsRespond; virtual ~WsRespond() = default; /// /// Respond的类型签名 /// /// static WsRespondSignatureType signature() { return std::make_pair(MsgA().topicString(), MsgB().topicString()); } /// /// 子类中实际处理函数 /// /// /// virtual void execute(std::shared_ptr map, std::shared_ptr in, QList>& out) = 0; /// /// WsRespond构造函数 /// /// 注册函数 explicit WsRespond(QHash& map) { WsRespondEntry ins = [=](std::shared_ptr map, std::shared_ptr in, QList>& out) { QList> o_ptrs; this->execute(map, std::static_pointer_cast(in), o_ptrs); std::transform(o_ptrs.begin(), o_ptrs.end(), std::back_inserter(out), [](std::shared_ptr v) { return std::static_pointer_cast(v); }); }; map[SelfType::signature()] = ins; } }; template struct _ProcRoute_; template <> struct COMPONENTBASIC_EXPORT _ProcRoute_<> { QHash _execute_map; _ProcRoute_() = default; }; template struct _ProcRoute_ : public _ProcRoute_, public ProcSig { _ProcRoute_() : _ProcRoute_(), ProcSig(_ProcRoute_<>::_execute_map) {} }; template struct ProcList : public _ProcRoute_, public WsComponent { using SuperType = ProcList; ProcList() : _ProcRoute_() {} // 通过 WsComponent 继承 QList inputTypes() const override { QList list; for (auto key : _ProcRoute_<>::_execute_map.keys()) { list.append(key.first); } return list; } QList getEntryWithSignature(const WsRespondSignatureType& t) const override { QList list; for (auto key : _ProcRoute_<>::_execute_map.keys()) { if (key == t) list.append(_ProcRoute_<>::_execute_map[key]); } return list; } QList getEntrysWithInType(const QString& msg_type) const override { QList list; for (auto key : _ProcRoute_<>::_execute_map.keys()) { if (key.first == msg_type) list.append(_ProcRoute_<>::_execute_map[key]); } return list; } };