X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d0fcccc41fc00ff24f09303fcc86eb71b45d02ea..7f7997442007946449b069d250da01f14cdff236:/include/wx/dynload.h?ds=sidebyside diff --git a/include/wx/dynload.h b/include/wx/dynload.h index 4e5c5c09fc..0f69c8e709 100644 --- a/include/wx/dynload.h +++ b/include/wx/dynload.h @@ -7,13 +7,13 @@ // Created: 03/12/01 // RCS-ID: $Id$ // Copyright: (c) 2001 Ron Lee -// Licence: wxWindows license +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifndef _WX_DYNAMICLOADER_H__ #define _WX_DYNAMICLOADER_H__ -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(__APPLE__) #pragma interface "dynload.h" #endif @@ -25,7 +25,7 @@ #if wxUSE_DYNAMIC_LOADER -#include "wx/hash.h" +#include "wx/hashmap.h" #include "wx/module.h" // FIXME: can this go in private.h or something too?? @@ -38,11 +38,10 @@ #include "wx/msw/private.h" #endif -// Ugh, I'd much rather this was typesafe, but no time -// to rewrite wxHashTable right now.. +class WXDLLIMPEXP_BASE wxPluginLibrary; -typedef wxHashTable wxDLManifest; -typedef wxHashTable wxDLImports; +WX_DECLARE_EXPORTED_STRING_HASH_MAP(wxPluginLibrary *, wxDLManifest); +typedef wxDLManifest wxDLImports; // ---------------------------------------------------------------------------- // conditional compilation @@ -98,8 +97,20 @@ enum wxDLFlags #endif }; +enum wxDynamicLibraryCategory +{ + wxDL_LIBRARY, // standard library + wxDL_MODULE, // loadable module/plugin +}; -class WXDLLEXPORT wxDynamicLibrary +enum wxPluginCategory +{ + wxDL_PLUGIN_GUI, // plugin that uses GUI classes + wxDL_PLUGIN_BASE, // wxBase-only plugin +}; + + +class WXDLLIMPEXP_BASE wxDynamicLibrary { public: @@ -129,6 +140,11 @@ public: bool Load(wxString libname, int flags = wxDL_DEFAULT); + // detach the library object from its handle, i.e. prevent the object + // from unloading the library in its dtor -- the caller is now + // responsible for doing this + wxDllType Detach() { wxDllType h = m_handle; m_handle = 0; return h; } + // unload the library, also done automatically in dtor void Unload(); @@ -155,6 +171,20 @@ public: operator bool() const { return IsLoaded(); } #endif + // return platform-specific name of dynamic library with proper extension + // and prefix (e.g. "foo.dll" on Windows or "libfoo.so" on Linux) + static wxString CanonicalizeName(const wxString& name, + wxDynamicLibraryCategory cat = wxDL_LIBRARY); + + // return name of wxWindows plugin (adds compiler and version info + // to the filename): + static wxString CanonicalizePluginName(const wxString& name, + wxPluginCategory cat); + + // return plugin directory on platforms where it makes sense and empty + // string on others: + static wxString GetPluginsDirectory(); + protected: // Platform specific shared lib suffix. @@ -168,7 +198,7 @@ protected: // no copy ctor/assignment operators // or we'd try to unload the library twice -DECLARE_NO_COPY_CLASS(wxDynamicLibrary) + DECLARE_NO_COPY_CLASS(wxDynamicLibrary) }; @@ -184,7 +214,7 @@ DECLARE_NO_COPY_CLASS(wxDynamicLibrary) // instantiate this class directly anyway, use wxPluginManager // instead. -class WXDLLEXPORT wxPluginLibrary : public wxDynamicLibrary +class WXDLLIMPEXP_BASE wxPluginLibrary : public wxDynamicLibrary { public: @@ -234,11 +264,11 @@ private: void RegisterModules(); // Init any wxModules in the lib. void UnregisterModules(); // Cleanup any wxModules we installed. -DECLARE_NO_COPY_CLASS(wxPluginLibrary) + DECLARE_NO_COPY_CLASS(wxPluginLibrary) }; -class WXDLLEXPORT wxPluginManager +class WXDLLIMPEXP_BASE wxPluginManager { public: @@ -257,7 +287,7 @@ public: // Instance methods. - wxPluginManager() : m_entry(0) {}; + wxPluginManager() : m_entry(NULL) {}; wxPluginManager(const wxString &libname, int flags = wxDL_DEFAULT) { Load(libname, flags); @@ -277,14 +307,21 @@ public: static void ClearManifest() { delete ms_manifest; ms_manifest = NULL; } 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. wxPluginLibrary* m_entry; // Cache our entry in the manifest. // We could allow this class to be copied if we really // wanted to, but not without modification. - -DECLARE_NO_COPY_CLASS(wxPluginManager) + DECLARE_NO_COPY_CLASS(wxPluginManager) }; @@ -297,11 +334,11 @@ DECLARE_NO_COPY_CLASS(wxPluginManager) // serves as a namespace for its static member functions. #if WXWIN_COMPATIBILITY_2_2 -class WXDLLEXPORT wxDllLoader +class WXDLLIMPEXP_BASE wxDllLoader { public: - static wxDllType LoadLibrary(const wxString& name); + static wxDllType LoadLibrary(const wxString& name, bool *success = NULL); static void UnloadLibrary(wxDllType dll); static wxDllType GetProgramHandle() { return wxDynamicLibrary::GetProgramHandle(); }