From edba18740759682ff9dfd07e75569f1222860a40 Mon Sep 17 00:00:00 2001 From: smalldy <743682730@qq.com> Date: Sun, 19 Jun 2022 21:22:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9easy=5Fmsg=E8=BF=9B=E8=A1=8C=E9=9D=99?= =?UTF-8?q?=E6=80=81=E5=88=86=E6=9E=90=20=E9=87=8D=E5=91=BD=E5=90=8D?= =?UTF-8?q?=E9=83=A8=E5=88=86=E6=A8=A1=E6=9D=BF=E7=B1=BB=E5=9E=8B=20;refor?= =?UTF-8?q?mat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/02_msgcallback_example/mailbox.h | 6 ++--- src/easymsg_callback.cpp | 2 +- src/include/easy_msg.h | 27 +++++++++++------------ src/include/easymsg_subscriber.h | 3 ++- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/examples/02_msgcallback_example/mailbox.h b/examples/02_msgcallback_example/mailbox.h index 387a920..f40a1d8 100644 --- a/examples/02_msgcallback_example/mailbox.h +++ b/examples/02_msgcallback_example/mailbox.h @@ -3,7 +3,7 @@ #include "easy_msg.h" #include "easymsg_subscriber.h" namespace test { -//项目中需要传递的结构体 +// 项目中需要传递的结构体 struct SomeMsg { std::string msg_str; }; @@ -23,8 +23,8 @@ public: void handleMsg(em::EasyMsg *easymsg); private: - em::EasyMsgSubscriber sub; //析构时自动取消订阅 + em::EasyMsgSubscriber sub; // 析构时自动取消订阅 }; -} +} // namespace test #endif // MAILBOX_H diff --git a/src/easymsg_callback.cpp b/src/easymsg_callback.cpp index 0ec1615..7647d41 100644 --- a/src/easymsg_callback.cpp +++ b/src/easymsg_callback.cpp @@ -1,7 +1,7 @@ #include "easymsg_callback.h" -#include #include "easy_msg.h" +#include namespace em { EasyMsgCallback::EasyMsgCallback(std::function func) { diff --git a/src/include/easy_msg.h b/src/include/easy_msg.h index ca94c15..de99419 100644 --- a/src/include/easy_msg.h +++ b/src/include/easy_msg.h @@ -7,13 +7,12 @@ #include #ifdef ENABLE_BOOST_SERIALIZATION -//add boost serialization +// add boost serialization #endif #include "easymsg_dispatcher.h" #include "easymsg_export.h" - namespace em { class EasyMsg; @@ -21,7 +20,7 @@ class EasyMsg; class EASYMSG_API EasyMsg { public: EasyMsg(); - virtual ~EasyMsg(){}; + virtual ~EasyMsg() = default; virtual std::string id() const = 0; template struct is_easymsg { @@ -32,13 +31,13 @@ public: // c++17 support constexpr if #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L) - template bool match() { - is_easymsg test_easymsg; + template bool match() { + is_easymsg test_easymsg; if constexpr (test_easymsg.value) { // c++17 - return id() == MSGID::value; + return id() == EASY_MSG_ID::value; } else { std::cerr << "匹配消息ID时发生错误,检查是否使用了未定义的消息? 检查:" - << typeid(MSGID).name() << std::endl; + << typeid(EASY_MSG_ID).name() << std::endl; return false; } } @@ -66,7 +65,7 @@ public: struct _MSG_##_MSG : public _MSG_, public em::EasyMsg { \ public: \ _MSG_##_MSG() = default; \ - _MSG_##_MSG(_MSG_ msg) : _MSG_{msg} {} \ + _MSG_##_MSG(_MSG_ msg) : _MSG_{std::move(msg)} {} \ std::string id() const { return MSG_ID_STR(_MSG_); } \ }; \ static const char *_MSG_ID_##helper{(char *)MSG_ID_STR(_MSG_)}; \ @@ -92,16 +91,16 @@ public: * 只对文件内可见,所以不会引发任何问题。 **/ -template -auto easymsg_cast(EasyMsg *msg) -> typename _MSG_ID::MsgType * { - return static_cast(msg); +template +auto easymsg_cast(EasyMsg *msg) -> typename EASY_MSG_ID::MsgType * { + return static_cast(msg); } extern EASYMSG_API EasyMsgDispatcher ___dispatcher; -template -void EASYMSG_API sendMsg(typename _MSG_ID::MsgType *msg) { - ___dispatcher.dispatchMsg<_MSG_ID>(msg); +template +void EASYMSG_API sendMsg(typename EASY_MSG_ID::MsgType *msg) { + ___dispatcher.dispatchMsg(msg); } } // namespace em diff --git a/src/include/easymsg_subscriber.h b/src/include/easymsg_subscriber.h index f668138..556c608 100644 --- a/src/include/easymsg_subscriber.h +++ b/src/include/easymsg_subscriber.h @@ -19,7 +19,8 @@ public: host_ptr = static_cast(hostObj); } - template void unSubscribe(HOST_OBJ *hostObj) { + template + void unSubscribe(HOST_OBJ *hostObj) { if (host_ptr != static_cast(hostObj)) { return; } -- Gitee