12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- #pragma once
- #include "C11UnsafeDelegate.hpp"
- //
- // a Notify delegate, send notification when insert, remove, clear
- //
- template <typename T>
- class _tNotifyUnsafeDelegate : public _tUnsafeDelegate <T>
- {
- typedef _tUnsafeDelegate <T> inherited;
- public:
- _tNotifyUnsafeDelegate () = default;
- _tNotifyUnsafeDelegate (_tNotifyUnsafeDelegate && from)
- {
- m_handlers.swap (from.m_handlers);
- m_Notify.swap (from.m_Notify);
- }
- _tNotifyUnsafeDelegate (const _tNotifyUnsafeDelegate &) = delete;
- _tNotifyUnsafeDelegate & operator == (const _tNotifyUnsafeDelegate &) = delete;
- _tNotifyUnsafeDelegate & operator == (_tNotifyUnsafeDelegate &&) = delete;
- inline virtual ~_tNotifyUnsafeDelegate () { }
- public:
- inline virtual void RemoveAll () override
- {
- inherited::RemoveAll ();
- m_Notify.Invoke (this, NULL);
- }
- protected:
- inline virtual void ForcePush (C11EventHandler && handler) override
- {
- inherited::ForcePush (std::move (handler));
- m_Notify.Invoke (this, NULL);
- }
- protected:
- // 按 Key 来删除
- inline virtual bool DoPop (const typename C11EventHandler::tKey key) override
- {
- auto rc = inherited::DoPop (key);
- m_Notify.Invoke (this, NULL);
- return rc;
- }
- // 按 Key + 类实例指针 来删除
- inline virtual bool DoPop (const typename C11EventHandler::tKey key, const void * pThis) override
- {
- auto rc = inherited::DoPop (key, pThis);
- m_Notify.Invoke (this, NULL);
- return rc;
- }
- public:
- UnsafeDelegate m_Notify;
- };
- using NotifyUnsafeDelegate = _tNotifyUnsafeDelegate <DelegateArgs>;
|