forked from qdtroy/DuiLib_Ultimate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request qdtroy#155 from nakkler/master
成员函数相等判断错误,主要出现在删除委托的时候
- Loading branch information
Showing
2 changed files
with
98 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,102 +1,102 @@ | ||
#include "StdAfx.h" | ||
|
||
namespace DuiLib { | ||
|
||
CDelegateBase::CDelegateBase(void* pObject, void* pFn) | ||
{ | ||
m_pObject = pObject; | ||
m_pFn = pFn; | ||
} | ||
|
||
CDelegateBase::CDelegateBase(const CDelegateBase& rhs) | ||
{ | ||
m_pObject = rhs.m_pObject; | ||
m_pFn = rhs.m_pFn; | ||
} | ||
|
||
CDelegateBase::~CDelegateBase() | ||
{ | ||
|
||
} | ||
|
||
bool CDelegateBase::Equals(const CDelegateBase& rhs) const | ||
{ | ||
return m_pObject == rhs.m_pObject && m_pFn == rhs.m_pFn; | ||
} | ||
|
||
bool CDelegateBase::operator() (void* param) | ||
{ | ||
return Invoke(param); | ||
} | ||
|
||
void* CDelegateBase::GetFn() | ||
{ | ||
return m_pFn; | ||
} | ||
|
||
void* CDelegateBase::GetObject() | ||
{ | ||
return m_pObject; | ||
} | ||
|
||
CEventSource::~CEventSource() | ||
{ | ||
for( int i = 0; i < m_aDelegates.GetSize(); i++ ) { | ||
CDelegateBase* pObject = static_cast<CDelegateBase*>(m_aDelegates[i]); | ||
if( pObject) delete pObject; | ||
} | ||
} | ||
|
||
CEventSource::operator bool() | ||
{ | ||
return m_aDelegates.GetSize() > 0; | ||
} | ||
|
||
void CEventSource::operator+= (const CDelegateBase& d) | ||
{ | ||
for( int i = 0; i < m_aDelegates.GetSize(); i++ ) { | ||
CDelegateBase* pObject = static_cast<CDelegateBase*>(m_aDelegates[i]); | ||
if( pObject && pObject->Equals(d) ) return; | ||
} | ||
|
||
m_aDelegates.Add(d.Copy()); | ||
} | ||
|
||
void CEventSource::operator+= (FnType pFn) | ||
{ | ||
(*this) += MakeDelegate(pFn); | ||
} | ||
|
||
void CEventSource::operator-= (const CDelegateBase& d) | ||
{ | ||
for( int i = 0; i < m_aDelegates.GetSize(); i++ ) { | ||
CDelegateBase* pObject = static_cast<CDelegateBase*>(m_aDelegates[i]); | ||
if( pObject && pObject->Equals(d) ) { | ||
delete pObject; | ||
m_aDelegates.Remove(i); | ||
return; | ||
} | ||
} | ||
} | ||
void CEventSource::operator-= (FnType pFn) | ||
{ | ||
(*this) -= MakeDelegate(pFn); | ||
} | ||
|
||
bool CEventSource::operator() (void* param) | ||
{ | ||
for( int i = 0; i < m_aDelegates.GetSize(); i++ ) { | ||
CDelegateBase* pObject = static_cast<CDelegateBase*>(m_aDelegates[i]); | ||
if( pObject && !(*pObject)(param) ) return false; | ||
} | ||
return true; | ||
} | ||
#include "StdAfx.h" | ||
|
||
namespace DuiLib { | ||
|
||
CDelegateBase::CDelegateBase(void* pObject, void* pFn) | ||
{ | ||
m_pObject = pObject; | ||
m_pFn = pFn; | ||
} | ||
|
||
CDelegateBase::CDelegateBase(const CDelegateBase& rhs) | ||
{ | ||
m_pObject = rhs.m_pObject; | ||
m_pFn = rhs.m_pFn; | ||
} | ||
|
||
CDelegateBase::~CDelegateBase() | ||
{ | ||
|
||
} | ||
|
||
bool CDelegateBase::Equals(const CDelegateBase& rhs) const | ||
{ | ||
return m_pObject == rhs.m_pObject && GetFn() == rhs.GetFn(); | ||
} | ||
|
||
bool CDelegateBase::operator() (void* param) | ||
{ | ||
return Invoke(param); | ||
} | ||
|
||
void* CDelegateBase::GetFn() const | ||
{ | ||
return m_pFn; | ||
} | ||
|
||
void* CDelegateBase::GetObject() | ||
{ | ||
return m_pObject; | ||
} | ||
|
||
CEventSource::~CEventSource() | ||
{ | ||
for( int i = 0; i < m_aDelegates.GetSize(); i++ ) { | ||
CDelegateBase* pObject = static_cast<CDelegateBase*>(m_aDelegates[i]); | ||
if( pObject) delete pObject; | ||
} | ||
} | ||
|
||
CEventSource::operator bool() | ||
{ | ||
return m_aDelegates.GetSize() > 0; | ||
} | ||
|
||
void CEventSource::operator+= (const CDelegateBase& d) | ||
{ | ||
for( int i = 0; i < m_aDelegates.GetSize(); i++ ) { | ||
CDelegateBase* pObject = static_cast<CDelegateBase*>(m_aDelegates[i]); | ||
if( pObject && pObject->Equals(d) ) return; | ||
} | ||
|
||
m_aDelegates.Add(d.Copy()); | ||
} | ||
|
||
void CEventSource::operator+= (FnType pFn) | ||
{ | ||
(*this) += MakeDelegate(pFn); | ||
} | ||
|
||
void CEventSource::operator-= (const CDelegateBase& d) | ||
{ | ||
for( int i = 0; i < m_aDelegates.GetSize(); i++ ) { | ||
CDelegateBase* pObject = static_cast<CDelegateBase*>(m_aDelegates[i]); | ||
if( pObject && pObject->Equals(d) ) { | ||
delete pObject; | ||
m_aDelegates.Remove(i); | ||
return; | ||
} | ||
} | ||
} | ||
void CEventSource::operator-= (FnType pFn) | ||
{ | ||
(*this) -= MakeDelegate(pFn); | ||
} | ||
|
||
bool CEventSource::operator() (void* param) | ||
{ | ||
for( int i = 0; i < m_aDelegates.GetSize(); i++ ) { | ||
CDelegateBase* pObject = static_cast<CDelegateBase*>(m_aDelegates[i]); | ||
if( pObject && !(*pObject)(param) ) return false; | ||
} | ||
return true; | ||
} | ||
void CEventSource::Clear() | ||
{ | ||
for( int i = 0; i < m_aDelegates.GetSize(); i++ ) { | ||
CDelegateBase* pObject = static_cast<CDelegateBase*>(m_aDelegates[i]); | ||
if( pObject) delete pObject; | ||
} | ||
m_aDelegates.Empty(); | ||
} | ||
} // namespace DuiLib | ||
} | ||
} // namespace DuiLib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters