msg.h 2.5 KB

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