msg.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #ifndef AFUN_MSG_H
  2. #define AFUN_MSG_H
  3. #include <list>
  4. #include <mutex>
  5. #include "aFuntool.h"
  6. #include "aFunCoreExport.h"
  7. #include "core.h"
  8. namespace aFuncore {
  9. class AFUN_CORE_EXPORT Message {
  10. friend class MessageStream;
  11. friend class UpMessage;
  12. friend class DownMessage;
  13. friend class InterMessage;
  14. Message *next; // 下一条消息
  15. public:
  16. const std::string type; // 消息类型标注
  17. explicit Message(const std::string &type_);
  18. virtual ~Message() = default;
  19. Message &operator=(const Message &)=delete;
  20. };
  21. class TopMessage : public Message {
  22. public:
  23. explicit TopMessage(const std::string &type_);
  24. virtual void topProgress() = 0;
  25. };
  26. class AFUN_CORE_EXPORT NormalMessage : public TopMessage {
  27. Object *obj;
  28. public:
  29. explicit NormalMessage(Object *obj_);
  30. ~NormalMessage() override;
  31. void topProgress() override;
  32. Object *getObject();
  33. };
  34. class AFUN_CORE_EXPORT ErrorMessage : public TopMessage {
  35. Inter &inter;
  36. std::string error_type;
  37. std::string error_info;
  38. struct TrackBack{
  39. const StringFilePath path;
  40. FileLine line;
  41. };
  42. std::list<TrackBack> trackback;
  43. public:
  44. explicit ErrorMessage(const std::string &error_type_, const std::string &error_info_, Activation *activation);
  45. void topProgress() override;
  46. std::string getErrorType();
  47. std::string getErrorInfo();
  48. };
  49. class AFUN_CORE_EXPORT MessageStream {
  50. protected:
  51. Message *stream;
  52. [[nodiscard]] virtual Message *_getMessage(const std::string &type) const;
  53. public:
  54. MessageStream();
  55. virtual ~MessageStream();
  56. MessageStream &operator=(const MessageStream &)=delete;
  57. template<class T>
  58. [[nodiscard]] T *getMessage(const std::string &type) const;
  59. virtual Message *popMessage(const std::string &type);
  60. void pushMessage(Message *msg);
  61. template <typename Callable, typename...T>
  62. void forEach(Callable func, T...arg);
  63. };
  64. class AFUN_CORE_EXPORT UpMessage : public MessageStream {
  65. protected:
  66. Message *old;
  67. public:
  68. explicit UpMessage(const UpMessage *old=nullptr);
  69. ~UpMessage() override;
  70. Message *popMessage(const std::string &type) override;
  71. };
  72. class AFUN_CORE_EXPORT DownMessage : public MessageStream {
  73. public:
  74. void joinMsg(DownMessage *msg);
  75. };
  76. class AFUN_CORE_EXPORT InterMessage : public MessageStream {
  77. std::mutex mutex;
  78. };
  79. }
  80. #include "msg.inline.h"
  81. #include "msg.template.h"
  82. #endif //AFUN_MSG_H