1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- #ifndef AFUN_MSG_HPP
- #define AFUN_MSG_HPP
- #include "tool.hpp"
- #include "aFunCoreExport.h"
- namespace aFuncore {
- class MessageStream;
- class Message {
- std::string type; // 消息类型标注
- Message *next; // 下一条消息
- friend class MessageStream;
- friend class UpMessage;
- friend class DownMessage;
- public:
- AFUN_CORE_EXPORT explicit Message(const std::string &type_) : type {type_}, next {nullptr} {};
- AFUN_CORE_EXPORT virtual ~Message() = default;
- [[nodiscard]] const std::string &getType() const {return type;}
- };
- class MessageStream {
- protected:
- Message *stream;
- [[nodiscard]] AFUN_CORE_EXPORT virtual Message *_getMessage(const std::string &type) const;
- public:
- AFUN_CORE_EXPORT MessageStream();
- AFUN_CORE_EXPORT virtual ~MessageStream();
- template<class T>
- [[nodiscard]] T *getMessage(const std::string &type) const {
- Message *msg = this->_getMessage(type);
- T *ret = dynamic_cast<T*>(msg);
- return ret;
- }
- virtual AFUN_CORE_EXPORT Message *popMessage(const std::string &type);
- AFUN_CORE_EXPORT void pushMessage(Message *msg);
- };
- class UpMessage : public MessageStream {
- protected:
- Message *old;
- public:
- AFUN_CORE_EXPORT explicit UpMessage(const UpMessage *old=nullptr);
- AFUN_CORE_EXPORT ~UpMessage() override;
- AFUN_CORE_EXPORT Message *popMessage(const std::string &type) override;
- };
- class DownMessage : public MessageStream {
- public:
- AFUN_CORE_EXPORT void joinMsg(DownMessage *msg);
- };
- }
- #endif //AFUN_MSG_HPP
|