diff --git a/examples/02_msgcallback_example/mailbox.h b/examples/02_msgcallback_example/mailbox.h index 387a9204763a1c6a6e3871dfad5d894ccf5fb885..f40a1d8a94165d3911b9a0a9162e06374fa81c6d 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 0ec1615876ce5813df3dbe8845d8416225039328..7647d41886e5b6787ee81c1b899455c793c126eb 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 ca94c150d945aeb9dd60076437ad912e74ee7024..de994198890e9b676cea137dd71d4e5162946d7e 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 f6681384b775dcd4273c6ddf8b20819c3afd4a5a..556c608b965ce5db192563355c0f7c78e6ca73f2 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; }