From 644cb5372c67d2bd246729257b936bd0aa85b882 Mon Sep 17 00:00:00 2001 From: Mattia Barbon Date: Sun, 15 Apr 2007 11:43:37 +0000 Subject: [PATCH] Make wxClassInfo attributes private. Replace direct access to sm_classTable with a (const) iterator interface. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45478 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/dynload.h | 4 ++-- include/wx/hash.h | 2 ++ include/wx/mediactrl.h | 4 ++-- include/wx/object.h | 41 ++++++++++++++++++++++++++++++++++--- include/wx/xti.h | 8 +++++--- src/common/dynload.cpp | 10 ++++----- src/common/mediactrlcmn.cpp | 25 +++++++++++----------- src/common/memory.cpp | 12 +++++------ src/common/module.cpp | 17 +++++++-------- src/common/object.cpp | 31 ++++++++++++++++++++++++++++ 10 files changed, 109 insertions(+), 45 deletions(-) diff --git a/include/wx/dynload.h b/include/wx/dynload.h index b754dee03f..fbbf6f2e91 100644 --- a/include/wx/dynload.h +++ b/include/wx/dynload.h @@ -82,8 +82,8 @@ public: private: - wxClassInfo *m_before; // sm_first before loading this lib - wxClassInfo *m_after; // ..and after. + const wxClassInfo *m_before; // sm_first before loading this lib + const wxClassInfo *m_after; // ..and after. size_t m_linkcount; // Ref count of library link calls size_t m_objcount; // ..and (pluggable) object instantiations. diff --git a/include/wx/hash.h b/include/wx/hash.h index 890213f021..5cf258f5d2 100644 --- a/include/wx/hash.h +++ b/include/wx/hash.h @@ -335,6 +335,8 @@ private: #else // if wxUSE_OLD_HASH_TABLE +typedef wxNode wxHashTable_Node; + class WXDLLIMPEXP_BASE wxHashTable : public wxObject { public: diff --git a/include/wx/mediactrl.h b/include/wx/mediactrl.h index 4661bde448..d5223615a2 100644 --- a/include/wx/mediactrl.h +++ b/include/wx/mediactrl.h @@ -171,7 +171,7 @@ public: const wxValidator& validator = wxDefaultValidator, const wxString& name = wxT("mediaCtrl")); - bool DoCreate(wxClassInfo* instance, + bool DoCreate(const wxClassInfo* instance, wxWindow* parent, wxWindowID winid, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, @@ -213,7 +213,7 @@ public: { return Load(wxURI(fileName), wxURI(proxy)); } protected: - static wxClassInfo* NextBackend(); + static const wxClassInfo* NextBackend(wxClassInfo::const_iterator* it); void OnMediaFinished(wxMediaEvent& evt); virtual void DoMoveWindow(int x, int y, int w, int h); diff --git a/include/wx/object.h b/include/wx/object.h index a1d021fa91..4b70945219 100644 --- a/include/wx/object.h +++ b/include/wx/object.h @@ -25,6 +25,37 @@ class WXDLLIMPEXP_BASE wxObject; #define wxUSE_EXTENDED_RTTI 0 #endif +#define DECLARE_CLASS_INFO_ITERATORS() \ + class WXDLLIMPEXP_BASE const_iterator \ + { \ + typedef wxHashTable_Node Node; \ + public: \ + typedef const wxClassInfo* value_type; \ + typedef const value_type& const_reference; \ + typedef const_iterator itor; \ + typedef value_type* ptr_type; \ + \ + Node* m_node; \ + wxHashTable* m_table; \ + public: \ + typedef const_reference reference_type; \ + typedef ptr_type pointer_type; \ + \ + const_iterator(Node* node, wxHashTable* table) \ + : m_node(node), m_table(table) { } \ + const_iterator() : m_node(NULL), m_table(NULL) { } \ + value_type operator*() const; \ + itor& operator++(); \ + const itor operator++(int); \ + bool operator!=(const itor& it) const \ + { return it.m_node != m_node; } \ + bool operator==(const itor& it) const \ + { return it.m_node == m_node; } \ + }; \ + \ + static const_iterator begin_classinfo(); \ + static const_iterator end_classinfo(); + #if wxUSE_EXTENDED_RTTI #include "wx/xti.h" #else @@ -35,7 +66,10 @@ class WXDLLIMPEXP_BASE wxObject; class WXDLLIMPEXP_BASE wxClassInfo; class WXDLLIMPEXP_BASE wxHashTable; +class WXDLLIMPEXP_BASE wxObject; +class WXDLLIMPEXP_BASE wxPluginLibrary; class WXDLLIMPEXP_BASE wxObjectRefData; +class WXDLLIMPEXP_BASE wxHashTable_Node; // ---------------------------------------------------------------------------- // wxClassInfo @@ -45,6 +79,8 @@ typedef wxObject *(*wxObjectConstructorFn)(void); class WXDLLIMPEXP_BASE wxClassInfo { + friend class WXDLLIMPEXP_BASE wxObject; + friend wxObject *wxCreateDynamicObject(const wxChar *name); public: wxClassInfo( const wxChar *className, const wxClassInfo *baseInfo1, @@ -94,7 +130,8 @@ public: ( m_baseInfo2 && m_baseInfo2->IsKindOf(info) ) ); } -public: + DECLARE_CLASS_INFO_ITERATORS() +private: const wxChar *m_className; int m_objectSize; wxObjectConstructorFn m_objectConstructor; @@ -110,8 +147,6 @@ public: static wxClassInfo *sm_first; wxClassInfo *m_next; - // FIXME: this should be private (currently used directly by way too - // many clients) static wxHashTable *sm_classTable; protected: diff --git a/include/wx/xti.h b/include/wx/xti.h index 64d24b6dea..1d423fd1a7 100644 --- a/include/wx/xti.h +++ b/include/wx/xti.h @@ -84,6 +84,7 @@ class WXDLLIMPEXP_BASE wxObject; class WXDLLIMPEXP_BASE wxClassInfo; class WXDLLIMPEXP_BASE wxDynamicClassInfo; class WXDLLIMPEXP_BASE wxHashTable; +class WXDLLIMPEXP_BASE wxHashTable_Node; class WXDLLIMPEXP_BASE wxObjectRefData; class WXDLLIMPEXP_BASE wxEvent; class WXDLLIMPEXP_BASE wxEvtHandler; @@ -1601,6 +1602,7 @@ class WXDLLIMPEXP_BASE wxClassInfo { friend class WXDLLIMPEXP_BASE wxPropertyInfo ; friend class WXDLLIMPEXP_BASE wxHandlerInfo ; + friend wxObject *wxCreateDynamicObject(const wxChar *name); public: wxClassInfo(const wxClassInfo **_Parents, const wxChar *_UnitName, @@ -1718,6 +1720,8 @@ public: return false ; } + DECLARE_CLASS_INFO_ITERATORS() + // if there is a callback registered with that class it will be called // before this object will be written to disk, it can veto streaming out // this object by returning false, if this class has not registered a @@ -1788,7 +1792,7 @@ public: // puts all the properties of this class and its superclasses in the map, as long as there is not yet // an entry with the same name (overriding mechanism) void GetProperties( wxPropertyInfoMap &map ) const ; -public: +private: const wxChar *m_className; int m_objectSize; wxObjectConstructorFn m_objectConstructor; @@ -1799,8 +1803,6 @@ public: static wxClassInfo *sm_first; wxClassInfo *m_next; - // FIXME: this should be private (currently used directly by way too - // many clients) static wxHashTable *sm_classTable; protected : diff --git a/src/common/dynload.cpp b/src/common/dynload.cpp index 7759f6f8d1..ffb80f1af6 100644 --- a/src/common/dynload.cpp +++ b/src/common/dynload.cpp @@ -77,9 +77,9 @@ wxPluginLibrary::wxPluginLibrary(const wxString &libname, int flags) : m_linkcount(1) , m_objcount(0) { - m_before = wxClassInfo::sm_first; + m_before = wxClassInfo::GetFirst(); Load( libname, flags ); - m_after = wxClassInfo::sm_first; + m_after = wxClassInfo::GetFirst(); if( m_handle != 0 ) { @@ -131,7 +131,7 @@ bool wxPluginLibrary::UnrefLib() void wxPluginLibrary::UpdateClasses() { - for (wxClassInfo *info = m_after; info != m_before; info = info->m_next) + for (const wxClassInfo *info = m_after; info != m_before; info = info->GetNext()) { if( info->GetClassName() ) { @@ -148,7 +148,7 @@ void wxPluginLibrary::RestoreClasses() if (!ms_classes) return; - for(wxClassInfo *info = m_after; info != m_before; info = info->m_next) + for(const wxClassInfo *info = m_after; info != m_before; info = info->GetNext()) { ms_classes->erase(ms_classes->find(info->GetClassName())); } @@ -167,7 +167,7 @@ void wxPluginLibrary::RegisterModules() wxASSERT_MSG( m_linkcount == 1, _T("RegisterModules should only be called for the first load") ); - for ( wxClassInfo *info = m_after; info != m_before; info = info->m_next) + for ( const wxClassInfo *info = m_after; info != m_before; info = info->GetNext()) { if( info->IsKindOf(CLASSINFO(wxModule)) ) { diff --git a/src/common/mediactrlcmn.cpp b/src/common/mediactrlcmn.cpp index b0d93db7af..ba9d1c0d9b 100644 --- a/src/common/mediactrlcmn.cpp +++ b/src/common/mediactrlcmn.cpp @@ -120,12 +120,13 @@ bool wxMediaCtrl::Create(wxWindow* parent, wxWindowID id, } else { - wxClassInfo::sm_classTable->BeginFind(); + wxClassInfo::const_iterator it = wxClassInfo::begin_classinfo(); - wxClassInfo* classInfo; + const wxClassInfo* classInfo; - while((classInfo = NextBackend()) != NULL) + while((classInfo = NextBackend(&it)) != NULL) { + wxLogMessage( classInfo->GetClassName() ); if(!DoCreate(classInfo, parent, id, pos, size, style, validator, name)) continue; @@ -183,11 +184,11 @@ bool wxMediaCtrl::Create(wxWindow* parent, wxWindowID id, } else { - wxClassInfo::sm_classTable->BeginFind(); + wxClassInfo::const_iterator it = wxClassInfo::begin_classinfo(); - wxClassInfo* classInfo; + const wxClassInfo* classInfo; - while((classInfo = NextBackend()) != NULL) + while((classInfo = NextBackend(&it)) != NULL) { if(!DoCreate(classInfo, parent, id, pos, size, style, validator, name)) @@ -212,7 +213,7 @@ bool wxMediaCtrl::Create(wxWindow* parent, wxWindowID id, // // Attempts to create the control from a backend //--------------------------------------------------------------------------- -bool wxMediaCtrl::DoCreate(wxClassInfo* classInfo, +bool wxMediaCtrl::DoCreate(const wxClassInfo* classInfo, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, @@ -246,19 +247,17 @@ bool wxMediaCtrl::DoCreate(wxClassInfo* classInfo, // incompatible with the old 2.4 stable version - but since // we're in 2.5+ only we don't need to worry about the new version //--------------------------------------------------------------------------- -wxClassInfo* wxMediaCtrl::NextBackend() +const wxClassInfo* wxMediaCtrl::NextBackend(wxClassInfo::const_iterator* it) { - wxHashTable::compatibility_iterator - node = wxClassInfo::sm_classTable->Next(); - while (node) + for ( wxClassInfo::const_iterator end = wxClassInfo::end_classinfo(); + *it != end; ++(*it) ) { - wxClassInfo* classInfo = (wxClassInfo *)node->GetData(); + const wxClassInfo* classInfo = **it; if ( classInfo->IsKindOf(CLASSINFO(wxMediaBackend)) && classInfo != CLASSINFO(wxMediaBackend) ) { return classInfo; } - node = wxClassInfo::sm_classTable->Next(); } // diff --git a/src/common/memory.cpp b/src/common/memory.cpp index 72169f2735..9bf20f536b 100644 --- a/src/common/memory.cpp +++ b/src/common/memory.cpp @@ -746,14 +746,13 @@ bool wxDebugContext::PrintClasses(void) } int n = 0; - wxHashTable::compatibility_iterator node; - wxClassInfo *info; + const wxClassInfo *info; - wxClassInfo::sm_classTable->BeginFind(); - node = wxClassInfo::sm_classTable->Next(); - while (node) + for (wxClassInfo::const_iterator node = wxClassInfo::begin_classinfo(), + end = wxClassInfo::end_classinfo(); + node != end; ++node) { - info = (wxClassInfo *)node->GetData(); + info = *node; if (info->GetClassName()) { wxString msg(info->GetClassName()); @@ -776,7 +775,6 @@ bool wxDebugContext::PrintClasses(void) wxLogMessage(msg); } - node = wxClassInfo::sm_classTable->Next(); n ++; } wxLogMessage(wxEmptyString); diff --git a/src/common/module.cpp b/src/common/module.cpp index 9167848b89..9f867b4c25 100644 --- a/src/common/module.cpp +++ b/src/common/module.cpp @@ -50,23 +50,20 @@ void wxModule::UnregisterModule(wxModule* module) // and register them. void wxModule::RegisterModules() { - wxHashTable::compatibility_iterator node; - wxClassInfo* classInfo; - - wxClassInfo::sm_classTable->BeginFind(); - node = wxClassInfo::sm_classTable->Next(); - while (node) + for (wxClassInfo::const_iterator it = wxClassInfo::begin_classinfo(), + end = wxClassInfo::end_classinfo(); + it != end; ++it) { - classInfo = (wxClassInfo *)node->GetData(); + const wxClassInfo* classInfo = *it; + if ( classInfo->IsKindOf(CLASSINFO(wxModule)) && - (classInfo != (& (wxModule::ms_classInfo))) ) + (classInfo != (& (wxModule::ms_classInfo))) ) { wxLogTrace(TRACE_MODULE, wxT("Registering module %s"), classInfo->GetClassName()); wxModule* module = (wxModule *)classInfo->CreateObject(); - RegisterModule(module); + wxModule::RegisterModule(module); } - node = wxClassInfo::sm_classTable->Next(); } } diff --git a/src/common/object.cpp b/src/common/object.cpp index 0289fc2ec6..6b4d7e2ae9 100644 --- a/src/common/object.cpp +++ b/src/common/object.cpp @@ -288,6 +288,37 @@ 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 -- 2.45.2