C11NotifyTimerDelegate.hpp 1.4 KB

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