From 634b6b7af4631da444c602a48189ebcd5e94ee0b Mon Sep 17 00:00:00 2001 From: Jack-PC-SSD <1281261856@qq.com> Date: Thu, 2 Apr 2015 16:46:43 +0800 Subject: [PATCH] =?UTF-8?q?NotifyObservers=E4=B8=8D=E5=86=8D=E6=89=93?= =?UTF-8?q?=E5=8D=B0=E5=87=BD=E6=95=B0=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- global.h | 15 +++++++++++++-- observer_macro.h | 2 -- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/global.h b/global.h index 6f85336..8b3fe0a 100644 --- a/global.h +++ b/global.h @@ -32,6 +32,14 @@ private:\ classname& operator=(const classname&) {} // singleton +//class CSingletonClassReleaseHelper { +//public: +// CSingletonClassReleaseHelper() {} +// ~CSingletonClassReleaseHelper() {} +//private: +// +//}; + #define DECLARE_SINGLETON(class_name) \ private: \ class_name(); \ @@ -41,13 +49,16 @@ public: \ static class_name* GetInstance() { \ m_lock4Instance.Lock(); \ if (m_pInstance == NULL){ \ - static class_name obj; \ - m_pInstance = &obj; \ + m_pInstance = new class_name(); \ } \ m_lock4Instance.UnLock(); \ return m_pInstance; \ + } \ + static void ReleaseObject() { \ + if (m_pInstance) { delete m_pInstance; m_pInstance = NULL; } \ } + #define IMPLEMENT_SINGLETON(class_name) \ class_name* class_name::m_pInstance = NULL; \ CLock class_name::m_lock4Instance; diff --git a/observer_macro.h b/observer_macro.h index 609a095..f2ea220 100644 --- a/observer_macro.h +++ b/observer_macro.h @@ -48,7 +48,6 @@ void class_name::UnRegisterObserver(void* udata) \ } \ void class_name::NotifyObservers(_param_type param) \ { \ - AUTO_LOG_FUNCTION; \ _lock4ObserverList.Lock(); \ std::list<_callbackInfo *>::iterator iter = _observerList.begin(); \ while (iter != _observerList.end()) { \ @@ -62,7 +61,6 @@ void class_name::NotifyObservers(_param_type param) \ // place this macro in your class's destruct function. #define DESTROY_OBSERVER \ { \ - AUTO_LOG_FUNCTION; \ std::list<_callbackInfo *>::iterator iter = _observerList.begin(); \ while (iter != _observerList.end()) { \ _callbackInfo * observer = *iter++; \ -- 2.18.1