C11NotifyUnsafeDelegate.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #pragma once
  2. #include "C11UnsafeDelegate.hpp"
  3. //
  4. // a Notify delegate, send notification when insert, remove, clear
  5. //
  6. template <typename T>
  7. class _tNotifyUnsafeDelegate : public _tUnsafeDelegate <T>
  8. {
  9. typedef _tUnsafeDelegate <T> inherited;
  10. public:
  11. _tNotifyUnsafeDelegate () = default;
  12. _tNotifyUnsafeDelegate (_tNotifyUnsafeDelegate && from)
  13. {
  14. m_handlers.swap (from.m_handlers);
  15. m_Notify.swap (from.m_Notify);
  16. }
  17. _tNotifyUnsafeDelegate (const _tNotifyUnsafeDelegate &) = delete;
  18. _tNotifyUnsafeDelegate & operator == (const _tNotifyUnsafeDelegate &) = delete;
  19. _tNotifyUnsafeDelegate & operator == (_tNotifyUnsafeDelegate &&) = delete;
  20. inline virtual ~_tNotifyUnsafeDelegate () { }
  21. public:
  22. inline virtual void RemoveAll () override
  23. {
  24. inherited::RemoveAll ();
  25. m_Notify.Invoke (this, NULL);
  26. }
  27. protected:
  28. inline virtual void ForcePush (C11EventHandler && handler) override
  29. {
  30. inherited::ForcePush (std::move (handler));
  31. m_Notify.Invoke (this, NULL);
  32. }
  33. protected:
  34. // 按 Key 来删除
  35. inline virtual bool DoPop (const typename C11EventHandler::tKey key) override
  36. {
  37. auto rc = inherited::DoPop (key);
  38. m_Notify.Invoke (this, NULL);
  39. return rc;
  40. }
  41. // 按 Key + 类实例指针 来删除
  42. inline virtual bool DoPop (const typename C11EventHandler::tKey key, const void * pThis) override
  43. {
  44. auto rc = inherited::DoPop (key, pThis);
  45. m_Notify.Invoke (this, NULL);
  46. return rc;
  47. }
  48. public:
  49. UnsafeDelegate m_Notify;
  50. };
  51. using NotifyUnsafeDelegate = _tNotifyUnsafeDelegate <DelegateArgs>;