replaced type unsafe wxHash with hash_map<>

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@17687 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2002-11-03 21:03:02 +00:00
parent e1e57f73b3
commit caaff22c06
2 changed files with 46 additions and 35 deletions

View File

@@ -25,7 +25,7 @@
#if wxUSE_DYNAMIC_LOADER #if wxUSE_DYNAMIC_LOADER
#include "wx/hash.h" #include "wx/hashmap.h"
#include "wx/module.h" #include "wx/module.h"
// FIXME: can this go in private.h or something too?? // FIXME: can this go in private.h or something too??
@@ -38,11 +38,10 @@
#include "wx/msw/private.h" #include "wx/msw/private.h"
#endif #endif
// Ugh, I'd much rather this was typesafe, but no time class WXDLLEXPORT wxPluginLibrary;
// to rewrite wxHashTable right now..
typedef wxHashTable wxDLManifest; WX_DECLARE_EXPORTED_STRING_HASH_MAP(wxPluginLibrary *, wxDLManifest);
typedef wxHashTable wxDLImports; typedef wxDLManifest wxDLImports;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// conditional compilation // conditional compilation
@@ -257,7 +256,7 @@ public:
// Instance methods. // Instance methods.
wxPluginManager() : m_entry(0) {}; wxPluginManager() : m_entry(NULL) {};
wxPluginManager(const wxString &libname, int flags = wxDL_DEFAULT) wxPluginManager(const wxString &libname, int flags = wxDL_DEFAULT)
{ {
Load(libname, flags); Load(libname, flags);
@@ -277,13 +276,20 @@ public:
static void ClearManifest() { delete ms_manifest; ms_manifest = NULL; } static void ClearManifest() { delete ms_manifest; ms_manifest = NULL; }
private: private:
// return the pointer to the entry for the library with given name in
// ms_manifest or NULL if none
static wxPluginLibrary *FindByName(const wxString& name)
{
const wxDLManifest::iterator i = ms_manifest->find(name);
return i == ms_manifest->end() ? NULL : i->second;
}
static wxDLManifest* ms_manifest; // Static hash of loaded libs. static wxDLManifest* ms_manifest; // Static hash of loaded libs.
wxPluginLibrary* m_entry; // Cache our entry in the manifest. wxPluginLibrary* m_entry; // Cache our entry in the manifest.
// We could allow this class to be copied if we really // We could allow this class to be copied if we really
// wanted to, but not without modification. // wanted to, but not without modification.
DECLARE_NO_COPY_CLASS(wxPluginManager) DECLARE_NO_COPY_CLASS(wxPluginManager)
}; };

View File

@@ -33,6 +33,7 @@
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
#include "wx/log.h" #include "wx/log.h"
#include "wx/intl.h" #include "wx/intl.h"
#include "wx/hash.h"
#endif #endif
#include "wx/filename.h" // for SplitPath() #include "wx/filename.h" // for SplitPath()
@@ -416,9 +417,7 @@ void wxPluginLibrary::UpdateClassInfo()
// Hash all the class names into a local table too so // Hash all the class names into a local table too so
// we can quickly find the entry they correspond to. // we can quickly find the entry they correspond to.
(*ms_classes)[info->m_className] = this;
if( ms_classes->Get(info->m_className) == 0 )
ms_classes->Put(info->m_className, (wxObject *) this);
} }
} }
@@ -438,7 +437,7 @@ void wxPluginLibrary::RestoreClassInfo()
for(info = m_after; info != m_before; info = info->m_next) for(info = m_after; info != m_before; info = info->m_next)
{ {
wxClassInfo::sm_classTable->Delete(info->m_className); wxClassInfo::sm_classTable->Delete(info->m_className);
ms_classes->Delete(info->m_className); ms_classes->erase(ms_classes->find(info->m_className));
} }
if( wxClassInfo::sm_first == m_after ) if( wxClassInfo::sm_first == m_after )
@@ -549,7 +548,7 @@ wxPluginManager::LoadLibrary(const wxString &libname, int flags)
} }
else else
{ {
entry = (wxPluginLibrary*) ms_manifest->Get(realname); entry = FindByName(realname);
} }
if ( entry ) if ( entry )
@@ -565,7 +564,7 @@ wxPluginManager::LoadLibrary(const wxString &libname, int flags)
if ( entry->IsLoaded() ) if ( entry->IsLoaded() )
{ {
ms_manifest->Put(realname, (wxObject*) entry); (*ms_manifest)[realname] = entry;
wxLogTrace(_T("dll"), wxLogTrace(_T("dll"),
_T("LoadLibrary(%s): loaded ok."), realname.c_str()); _T("LoadLibrary(%s): loaded ok."), realname.c_str());
@@ -594,13 +593,13 @@ bool wxPluginManager::UnloadLibrary(const wxString& libname)
{ {
wxString realname = libname; wxString realname = libname;
wxPluginLibrary *entry = (wxPluginLibrary*) ms_manifest->Get(realname); wxPluginLibrary *entry = FindByName(realname);
if ( !entry ) if ( !entry )
{ {
realname += wxDynamicLibrary::GetDllExt(); realname += wxDynamicLibrary::GetDllExt();
entry = (wxPluginLibrary*) ms_manifest->Get(realname); entry = FindByName(realname);
} }
if ( !entry ) if ( !entry )
@@ -619,7 +618,7 @@ bool wxPluginManager::UnloadLibrary(const wxString& libname)
return FALSE; return FALSE;
} }
ms_manifest->Delete(realname); ms_manifest->erase(ms_manifest->find(realname));
return TRUE; return TRUE;
} }
@@ -627,12 +626,15 @@ bool wxPluginManager::UnloadLibrary(const wxString& libname)
#if WXWIN_COMPATIBILITY_2_2 #if WXWIN_COMPATIBILITY_2_2
wxPluginLibrary *wxPluginManager::GetObjectFromHandle(wxDllType handle) wxPluginLibrary *wxPluginManager::GetObjectFromHandle(wxDllType handle)
{ {
wxNode *node; for ( wxDLManifest::iterator i = ms_manifest->begin();
ms_manifest->BeginFind(); i != ms_manifest->end();
++i )
{
wxPluginLibrary * const lib = i->second;
for(node = ms_manifest->Next(); node; node = ms_manifest->Next()) if ( lib->GetLibHandle() == handle )
if( ((wxPluginLibrary*)node->GetData())->GetLibHandle() == handle ) return lib;
return (wxPluginLibrary*)node->GetData(); }
return NULL; return NULL;
} }
@@ -645,27 +647,30 @@ wxPluginLibrary *wxPluginManager::GetObjectFromHandle(wxDllType handle)
bool wxPluginManager::Load(const wxString &libname, int flags) bool wxPluginManager::Load(const wxString &libname, int flags)
{ {
m_entry = wxPluginManager::LoadLibrary(libname, flags); m_entry = wxPluginManager::LoadLibrary(libname, flags);
return IsLoaded(); return IsLoaded();
} }
void wxPluginManager::Unload() void wxPluginManager::Unload()
{ {
wxNode *node; wxCHECK_RET( m_entry, _T("unloading an invalid wxPluginManager?") );
ms_manifest->BeginFind();
// It's either this or store the name of the lib just to do this. for ( wxDLManifest::iterator i = ms_manifest->begin();
i != ms_manifest->end();
for(node = ms_manifest->Next(); node; node = ms_manifest->Next()) ++i )
if( (wxPluginLibrary*)node->GetData() == m_entry )
break;
if( m_entry && m_entry->UnrefLib() )
{ {
delete node; if ( i->second == m_entry )
m_entry = 0; {
ms_manifest->erase(i);
return;
} }
} }
m_entry->UnrefLib();
m_entry = NULL;
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// wxDllLoader (all these methods are static) // wxDllLoader (all these methods are static)
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------