|
From: stephan b. <st...@s1...> - 2004-12-25 01:54:30
|
Yo!
Forget all that code i showed you earlier regarding plugins. i mean, it
still works, but it just got a lot easier:
MyType * m = P::Factory<MyType>::create( "MyType" );
If MyType isn't registered that will look for a DLL named MyType.(so|
dll). If that is found, it is opened and we check again for a factory.
TODO: implement a way to hook in arbitrary classname-to-dll-name
translations.
The cool part is: the core doesn't know it's doing this. i used a
FactoryInstanceHook<> partial specialization in Plugin.h. The hook
simply returns a DLL-aware Factory instance (A PluginManager, which is
a Factory subclass). Any client which includes Plugin.h automatically
gets DLL-aware factory lookups through the core API. If they don't
include Plugin.h, they don't get this feature.
It is experimental, but this hook approach appears to work how i wanted
it to. It's a tiny bit clumsy to implement, but not too bad.
:)
Demo of an app which doesn't know it's using DLL lookups:
./FactoryTest
<snip>
../include/pclasses/Plugin/Plugin.h:325 : Initializing a PluginManager
instance() we hacked in via FactoryInstanceHook!
FactoryTest.cpp:19 : Factory tests...
FactoryTest.cpp:67 : DefaultDocumentType NamedTypeFactory::create()ed?
== 0
FactoryTest.cpp:67 : DefaultDocumentType classload()ed? == 0
/// DLL load was triggered by call to create("CType") here:
CType.cpp:28 : CType_bogo_init()
FactoryTest.h:27 : AType()
FactoryTest.h:50 : BType()
CType.cpp:9 : CType()
FactoryTest.cpp:68 : CType NamedTypeFactory::create(CType)ed? ==
0x8058c98
--
----- st...@s1... http://s11n.net
"...pleasure is a grace and is not obedient to the commands
of the will." -- Alan W. Watts
|