MultiNotifyDelegate.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #pragma once
  2. // Define a dummy DelegateArg for notification
  3. class DelegateArgsNotifyDelegate : public DelegateArgs
  4. {
  5. };
  6. //
  7. // a Notify delegate, send notification when insert, remove, clear
  8. //
  9. class NotifyDelegate : public Delegate
  10. {
  11. public:
  12. inline NotifyDelegate ()
  13. {
  14. }
  15. inline NotifyDelegate (const char * DelegateID) : Delegate (DelegateID)
  16. {
  17. }
  18. inline virtual ~NotifyDelegate ()
  19. {
  20. }
  21. inline virtual void AddDelegateHandler (DelegateHandler * handler)
  22. {
  23. Delegate::AddDelegateHandler (handler);
  24. DelegateArgsNotifyDelegate e;
  25. m_Notify.Invoke (this, &e);
  26. }
  27. inline virtual void RemoveDelegateHandler (DelegateHandler * handler)
  28. {
  29. Delegate::RemoveDelegateHandler (handler);
  30. DelegateArgsNotifyDelegate e;
  31. m_Notify.Invoke (this, &e);
  32. }
  33. inline void RemoveAll ()
  34. {
  35. Delegate::RemoveAll ();
  36. DelegateArgsNotifyDelegate e;
  37. m_Notify.Invoke (this, &e);
  38. }
  39. inline virtual void AddFirst (DelegateHandler * handler)
  40. {
  41. Delegate::AddFirst (handler);
  42. DelegateArgsNotifyDelegate e;
  43. m_Notify.Invoke (this, &e);
  44. }
  45. inline virtual void AddLast (DelegateHandler * handler)
  46. {
  47. Delegate::AddLast (handler);
  48. DelegateArgsNotifyDelegate e;
  49. m_Notify.Invoke (this, &e);
  50. }
  51. inline int TransferTo (Delegate & toDelegate)
  52. {
  53. int rc = Delegate::TransferTo (toDelegate);
  54. DelegateArgsNotifyDelegate e;
  55. m_Notify.Invoke (this, &e);
  56. return rc;
  57. }
  58. inline int TransferFrom (Delegate & fromDelegate)
  59. {
  60. int rc = Delegate::TransferFrom (fromDelegate);
  61. DelegateArgsNotifyDelegate e;
  62. m_Notify.Invoke (this, &e);
  63. return rc;
  64. }
  65. inline int TransferTo (Array <DelegateHandler *> & toArray)
  66. {
  67. int rc = Delegate::TransferTo (toArray);
  68. DelegateArgsNotifyDelegate e;
  69. m_Notify.Invoke (this, &e);
  70. return rc;
  71. }
  72. inline int TransferFrom (Array <DelegateHandler *> & fromArray)
  73. {
  74. int rc = Delegate::TransferFrom (fromArray);
  75. DelegateArgsNotifyDelegate e;
  76. m_Notify.Invoke (this, &e);
  77. return rc;
  78. }
  79. public:
  80. Delegate m_Notify;
  81. };