X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f5256c59dd7d9d2af9aaf5854b2bd39b87c7aafe..8aea37a9df3a2f5ca949ff466bbf698a4b2e3062:/src/common/object.cpp diff --git a/src/common/object.cpp b/src/common/object.cpp index 0fb4fae976..67e60c8551 100644 --- a/src/common/object.cpp +++ b/src/common/object.cpp @@ -21,6 +21,7 @@ #include "wx/object.h" #include "wx/hash.h" #include "wx/memory.h" + #include "wx/crt.h" #endif #include @@ -96,9 +97,9 @@ const bool wxFalse = false; // E.g. is wxWindow a kind of wxObject? // Go from this class to superclass, taking into account // two possible base classes. -bool wxObject::IsKindOf(wxClassInfo *info) const +bool wxObject::IsKindOf(const wxClassInfo *info) const { - wxClassInfo *thisInfo = GetClassInfo(); + const wxClassInfo *thisInfo = GetClassInfo(); return (thisInfo) ? thisInfo->IsKindOf(info) : false ; } @@ -187,7 +188,7 @@ wxClassInfo::~wxClassInfo() Unregister(); } -wxClassInfo *wxClassInfo::FindClass(const wxChar *className) +wxClassInfo *wxClassInfo::FindClass(const wxString& className) { if ( sm_classTable ) { @@ -197,7 +198,7 @@ wxClassInfo *wxClassInfo::FindClass(const wxChar *className) { for ( wxClassInfo *info = sm_first; info ; info = info->m_next ) { - if ( wxStrcmp(info->GetClassName(), className) == 0 ) + if ( className == info->GetClassName() ) return info; } @@ -224,9 +225,11 @@ void wxClassInfo::Register() sm_classTable = classTable; } +#ifdef __WXDEBUG__ // reentrance guard - see note above static int entry = 0; wxASSERT_MSG(++entry == 1, _T("wxClassInfo::Register() reentrance")); +#endif // Using IMPLEMENT_DYNAMIC_CLASS() macro twice (which may happen if you // link any object module twice mistakenly, or link twice against wx shared @@ -243,7 +246,9 @@ void wxClassInfo::Register() sm_classTable->Put(m_className, (wxObject *)this); +#ifdef __WXDEBUG__ --entry; +#endif } void wxClassInfo::Unregister() @@ -259,7 +264,7 @@ void wxClassInfo::Unregister() } } -wxObject *wxCreateDynamicObject(const wxChar *name) +wxObject *wxCreateDynamicObject(const wxString& name) { #if defined(__WXDEBUG__) || wxUSE_DEBUG_CONTEXT DEBUG_PRINTF(wxObject *wxCreateDynamicObject) @@ -284,6 +289,48 @@ wxObject *wxCreateDynamicObject(const wxChar *name) } } +// iterator interface +wxClassInfo::const_iterator::value_type +wxClassInfo::const_iterator::operator*() const +{ + return (wxClassInfo*)m_node->GetData(); +} + +wxClassInfo::const_iterator& wxClassInfo::const_iterator::operator++() +{ + m_node = m_table->Next(); + return *this; +} + +const wxClassInfo::const_iterator wxClassInfo::const_iterator::operator++(int) +{ + wxClassInfo::const_iterator tmp = *this; + m_node = m_table->Next(); + return tmp; +} + +wxClassInfo::const_iterator wxClassInfo::begin_classinfo() +{ + sm_classTable->BeginFind(); + + return const_iterator(sm_classTable->Next(), sm_classTable); +} + +wxClassInfo::const_iterator wxClassInfo::end_classinfo() +{ + return const_iterator(NULL, NULL); +} + +// ---------------------------------------------------------------------------- +// wxObjectRefData +// ---------------------------------------------------------------------------- + +void wxObjectRefData::DecRef() +{ + if ( --m_count == 0 ) + delete this; +} + // ---------------------------------------------------------------------------- // wxObject @@ -306,7 +353,7 @@ void wxObject::Ref(const wxObject& clone) if ( clone.m_refData ) { m_refData = clone.m_refData; - ++(m_refData->m_count); + m_refData->IncRef(); } } @@ -316,8 +363,7 @@ void wxObject::UnRef() { wxASSERT_MSG( m_refData->m_count > 0, _T("invalid ref data count") ); - if ( --m_refData->m_count == 0 ) - delete m_refData; + m_refData->DecRef(); m_refData = NULL; } }