]> git.saurik.com Git - wxWidgets.git/blame - include/wx/dynload.h
Wrappers for *ToText
[wxWidgets.git] / include / wx / dynload.h
CommitLineData
0b9ab0bd
RL
1/////////////////////////////////////////////////////////////////////////////
2// Name: dynload.h
3// Purpose: Dynamic loading framework
4// Author: Ron Lee, David Falkinder, Vadim Zeitlin and a cast of 1000's
5// (derived in part from dynlib.cpp (c) 1998 Guilhem Lavaux)
6// Modified by:
7// Created: 03/12/01
8// RCS-ID: $Id$
9// Copyright: (c) 2001 Ron Lee <ron@debian.org>
65571936 10// Licence: wxWindows licence
0b9ab0bd
RL
11/////////////////////////////////////////////////////////////////////////////
12
13#ifndef _WX_DYNAMICLOADER_H__
14#define _WX_DYNAMICLOADER_H__
15
12028905 16#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
0b9ab0bd
RL
17#pragma interface "dynload.h"
18#endif
19
20// ----------------------------------------------------------------------------
21// headers
22// ----------------------------------------------------------------------------
23
24#include "wx/defs.h"
25
26#if wxUSE_DYNAMIC_LOADER
27
1948bb32 28#include "wx/dynlib.h"
2b5f62a0 29#include "wx/hashmap.h"
0b9ab0bd
RL
30#include "wx/module.h"
31
bddd7a8d 32class WXDLLIMPEXP_BASE wxPluginLibrary;
0b9ab0bd 33
0b9ab0bd 34
1948bb32
VS
35WX_DECLARE_STRING_HASH_MAP_WITH_DECL(wxPluginLibrary *, wxDLManifest,
36 class WXDLLIMPEXP_BASE);
37typedef wxDLManifest wxDLImports;
0b9ab0bd
RL
38
39// ---------------------------------------------------------------------------
4f89dbc4 40// wxPluginLibrary
0b9ab0bd
RL
41// ---------------------------------------------------------------------------
42
4f89dbc4
RL
43// NOTE: Do not attempt to use a base class pointer to this class.
44// wxDL is not virtual and we deliberately hide some of it's
45// methods here.
46//
47// Unless you know exacty why you need to, you probably shouldn't
48// instantiate this class directly anyway, use wxPluginManager
49// instead.
50
bddd7a8d 51class WXDLLIMPEXP_BASE wxPluginLibrary : public wxDynamicLibrary
0b9ab0bd
RL
52{
53public:
54
dabd1377 55 static wxDLImports* ms_classes; // Static hash of all imported classes.
0b9ab0bd 56
23213f18 57 wxPluginLibrary( const wxString &libname, int flags = wxDL_DEFAULT );
4f89dbc4 58 ~wxPluginLibrary();
0b9ab0bd 59
d0fcccc4 60 wxPluginLibrary *RefLib();
4f89dbc4 61 bool UnrefLib();
7c1e2b44
RL
62
63 // These two are called by the PluginSentinel on (PLUGGABLE) object
64 // creation/destruction. There is usually no reason for the user to
65 // call them directly. We have to separate this from the link count,
66 // since the two are not interchangeable.
67
68 // FIXME: for even better debugging PluginSentinel should register
69 // the name of the class created too, then we can state
70 // exactly which object was not destroyed which may be
71 // difficult to find otherwise. Also this code should
72 // probably only be active in DEBUG mode, but let's just
73 // get it right first.
74
4f89dbc4
RL
75 void RefObj() { ++m_objcount; }
76 void UnrefObj()
7c1e2b44
RL
77 {
78 wxASSERT_MSG( m_objcount > 0, _T("Too many objects deleted??") );
79 --m_objcount;
80 }
0b9ab0bd 81
4f89dbc4 82 // Override/hide some base class methods
0b9ab0bd 83
4f89dbc4
RL
84 bool IsLoaded() const { return m_linkcount > 0; }
85 void Unload() { UnrefLib(); }
0b9ab0bd
RL
86
87private:
88
7c1e2b44 89 wxClassInfo *m_before; // sm_first before loading this lib
7c1e2b44 90 wxClassInfo *m_after; // ..and after.
0b9ab0bd 91
7c1e2b44
RL
92 size_t m_linkcount; // Ref count of library link calls
93 size_t m_objcount; // ..and (pluggable) object instantiations.
94 wxModuleList m_wxmodules; // any wxModules that we initialised.
0b9ab0bd 95
2d4957f2
VS
96 void UpdateClasses(); // Update ms_classes
97 void RestoreClasses(); // Removes this library from ms_classes
7c1e2b44
RL
98 void RegisterModules(); // Init any wxModules in the lib.
99 void UnregisterModules(); // Cleanup any wxModules we installed.
0b9ab0bd 100
2b5f62a0 101 DECLARE_NO_COPY_CLASS(wxPluginLibrary)
0b9ab0bd
RL
102};
103
104
bddd7a8d 105class WXDLLIMPEXP_BASE wxPluginManager
0b9ab0bd
RL
106{
107public:
108
109 // Static accessors.
110
4f89dbc4 111 static wxPluginLibrary *LoadLibrary( const wxString &libname,
23213f18 112 int flags = wxDL_DEFAULT );
4f89dbc4
RL
113 static bool UnloadLibrary(const wxString &libname);
114
115 // This is used by wxDllLoader. It's wrapped in the compatibility
116 // macro because it's of arguable use outside of that.
117
118#if WXWIN_COMPATIBILITY_2_2
119 static wxPluginLibrary *GetObjectFromHandle(wxDllType handle);
120#endif
0b9ab0bd
RL
121
122 // Instance methods.
123
2b5f62a0 124 wxPluginManager() : m_entry(NULL) {};
23213f18 125 wxPluginManager(const wxString &libname, int flags = wxDL_DEFAULT)
4f89dbc4
RL
126 {
127 Load(libname, flags);
128 }
e5e2612a 129 ~wxPluginManager() { if ( IsLoaded() ) Unload(); }
4f89dbc4 130
23213f18 131 bool Load(const wxString &libname, int flags = wxDL_DEFAULT);
4f89dbc4 132 void Unload();
0b9ab0bd
RL
133
134 bool IsLoaded() const { return m_entry && m_entry->IsLoaded(); }
135 void *GetSymbol(const wxString &symbol, bool *success = 0)
136 {
137 return m_entry->GetSymbol( symbol, success );
138 }
139
dabd1377
JS
140 static void CreateManifest() { ms_manifest = new wxDLManifest(wxKEY_STRING); }
141 static void ClearManifest() { delete ms_manifest; ms_manifest = NULL; }
142
0b9ab0bd 143private:
2b5f62a0
VZ
144 // return the pointer to the entry for the library with given name in
145 // ms_manifest or NULL if none
146 static wxPluginLibrary *FindByName(const wxString& name)
147 {
148 const wxDLManifest::iterator i = ms_manifest->find(name);
149
150 return i == ms_manifest->end() ? NULL : i->second;
151 }
0b9ab0bd 152
dabd1377
JS
153 static wxDLManifest* ms_manifest; // Static hash of loaded libs.
154 wxPluginLibrary* m_entry; // Cache our entry in the manifest.
0b9ab0bd
RL
155
156 // We could allow this class to be copied if we really
157 // wanted to, but not without modification.
2b5f62a0 158 DECLARE_NO_COPY_CLASS(wxPluginManager)
0b9ab0bd
RL
159};
160
161
162#endif // wxUSE_DYNAMIC_LOADER
163#endif // _WX_DYNAMICLOADER_H__
164