#pragma once #include "componentbasic_global.h" #include /// /// 消息处理单元基类 /// /// 输入类型 /// 输出类型 template class WsRespond { public: using SelfType = WsRespond; virtual ~WsRespond() = default; /// /// Respond的类型签名 /// /// static WsRespondSignatureType signature() { return std::make_pair(MsgA().topicString(), MsgB().topicString()); } /// /// 子类中实际处理函数 /// /// /// virtual std::shared_ptr execute(std::shared_ptr in) = 0; /// /// WsRespond构造函数 /// /// 注册函数 explicit WsRespond(QHash& map) { WsRespondEntry ins = [=](std::shared_ptr in) -> std::shared_ptr { return this->execute(std::static_pointer_cast(in)); }; 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; } WsRespondEntry getEntryWithSignature(const WsRespondSignatureType& t) const override { for (auto key : _ProcRoute_<>::_execute_map.keys()) { if (key == t) return _ProcRoute_<>::_execute_map[key]; } } 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; } }; #include class COMPONENTBASIC_EXPORT Visible3DPlugin : public ProcList< WsRespond > { public: // 通过 ProcList 继承 std::shared_ptr execute(std::shared_ptr in) override; void recoveryFrom(const QJsonObject& obj) override; void saveTo(QJsonObject& obj) const override; std::shared_ptr defaultNew() const override; void bindEntity(uint64_t entity_id) override; QString name() const override; };