diff --git a/include/wx/module.h b/include/wx/module.h index f139ddde12..41ef501e7e 100644 --- a/include/wx/module.h +++ b/include/wx/module.h @@ -12,18 +12,11 @@ #define _WX_MODULE_H_ #include "wx/object.h" -#include "wx/list.h" -#include "wx/arrstr.h" -#include "wx/dynarray.h" +#include "wx/vector.h" -// declare a linked list of modules -class WXDLLIMPEXP_FWD_BASE wxModule; -WX_DECLARE_USER_EXPORTED_LIST(wxModule, wxModuleList, WXDLLIMPEXP_BASE); - -// and an array of class info objects -WX_DEFINE_USER_EXPORTED_ARRAY_PTR(wxClassInfo *, wxArrayClassInfo, - class WXDLLIMPEXP_BASE); +class wxModule; +typedef wxVector wxModuleList; // declaring a class derived from wxModule will automatically create an // instance of this class on program startup, call its OnInit() method and call @@ -70,14 +63,14 @@ protected: { wxCHECK_RET( dep, wxT("NULL module dependency") ); - m_dependencies.Add(dep); + m_dependencies.push_back(dep); } // same as the version above except it will look up wxClassInfo by name on // its own. Note that className must be ASCII void AddDependency(const char *className) { - m_namedDependencies.Add(wxASCII_STR(className)); + m_namedDependencies.push_back(wxASCII_STR(className)); } @@ -98,11 +91,12 @@ private: // module dependencies: contains wxClassInfo pointers for all modules which // must be initialized before this one + typedef wxVector wxArrayClassInfo; wxArrayClassInfo m_dependencies; // and the named dependencies: those will be resolved during run-time and // added to m_dependencies - wxArrayString m_namedDependencies; + wxVector m_namedDependencies; // used internally while initializing/cleaning up modules enum diff --git a/src/common/module.cpp b/src/common/module.cpp index 45a05d35ff..f72956cf6d 100644 --- a/src/common/module.cpp +++ b/src/common/module.cpp @@ -20,12 +20,8 @@ #include "wx/log.h" #endif -#include "wx/listimpl.cpp" - #define TRACE_MODULE wxT("module") -WX_DEFINE_LIST(wxModuleList) - wxIMPLEMENT_ABSTRACT_CLASS(wxModule, wxObject) wxModuleList wxModule::ms_modules; @@ -33,12 +29,22 @@ wxModuleList wxModule::ms_modules; void wxModule::RegisterModule(wxModule* module) { module->m_state = State_Registered; - ms_modules.Append(module); + ms_modules.push_back(module); } void wxModule::UnregisterModule(wxModule* module) { - ms_modules.DeleteObject(module); + for ( wxModuleList::iterator it = ms_modules.begin(); + it != ms_modules.end(); + ++it ) + { + if ( *it == module ) + { + ms_modules.erase(it); + break; + } + } + delete module; } @@ -87,23 +93,25 @@ bool wxModule::DoInitializeModule(wxModule *module, wxClassInfo * cinfo = dependencies[i]; // Check if the module is already initialized - wxModuleList::compatibility_iterator node; - for ( node = initializedModules.GetFirst(); node; node = node->GetNext() ) + wxModuleList::const_iterator it; + for ( it = initializedModules.begin(); + it != initializedModules.end(); + ++it ) { - if ( node->GetData()->GetClassInfo() == cinfo ) + if ( (*it)->GetClassInfo() == cinfo ) break; } - if ( node ) + if ( it != initializedModules.end() ) { // this dependency is already initialized, nothing to do continue; } // find the module in the registered modules list - for ( node = ms_modules.GetFirst(); node; node = node->GetNext() ) + for ( it = ms_modules.begin(); it != ms_modules.end(); ++it ) { - wxModule *moduleDep = node->GetData(); + wxModule *moduleDep = *it; if ( moduleDep->GetClassInfo() == cinfo ) { if ( !DoInitializeModule(moduleDep, initializedModules ) ) @@ -116,7 +124,7 @@ bool wxModule::DoInitializeModule(wxModule *module, } } - if ( !node ) + if ( it == ms_modules.end() ) { wxLogError(_("Dependency \"%s\" of module \"%s\" doesn't exist."), cinfo->GetClassName(), @@ -136,7 +144,7 @@ bool wxModule::DoInitializeModule(wxModule *module, module->GetClassInfo()->GetClassName()); module->m_state = State_Initialized; - initializedModules.Append(module); + initializedModules.push_back(module); return true; } @@ -146,11 +154,11 @@ bool wxModule::InitializeModules() { wxModuleList initializedModules; - for ( wxModuleList::compatibility_iterator node = ms_modules.GetFirst(); - node; - node = node->GetNext() ) + for ( wxModuleList::const_iterator it = ms_modules.begin(); + it != ms_modules.end(); + ++it ) { - wxModule *module = node->GetData(); + wxModule *module = *it; // the module could have been already initialized as dependency of // another one @@ -178,14 +186,14 @@ void wxModule::DoCleanUpModules(const wxModuleList& modules) { // cleanup user-defined modules in the reverse order compared to their // initialization -- this ensures that dependencies are respected - for ( wxModuleList::compatibility_iterator node = modules.GetLast(); - node; - node = node->GetPrevious() ) + for ( wxModuleList::const_reverse_iterator rit = modules.rbegin(); + rit != modules.rend(); + ++rit ) { wxLogTrace(TRACE_MODULE, wxT("Cleanup module %s"), - node->GetData()->GetClassInfo()->GetClassName()); + (*rit)->GetClassInfo()->GetClassName()); - wxModule * module = node->GetData(); + wxModule * module = *rit; wxASSERT_MSG( module->m_state == State_Initialized, wxT("not initialized module being cleaned up") ); @@ -195,7 +203,14 @@ void wxModule::DoCleanUpModules(const wxModuleList& modules) } // clear all modules, even the non-initialized ones - WX_CLEAR_LIST(wxModuleList, ms_modules); + for ( wxModuleList::const_iterator it = ms_modules.begin(); + it != ms_modules.end(); + ++it ) + { + delete *it; + } + + ms_modules.clear(); } bool wxModule::ResolveNamedDependencies() @@ -214,7 +229,7 @@ bool wxModule::ResolveNamedDependencies() // add it even if it is not derived from wxModule because // DoInitializeModule() will make sure a module with the same class // info exists and fail if it doesn't - m_dependencies.Add(info); + m_dependencies.push_back(info); } return true;