From: stephan b. <st...@ei...> - 2003-09-29 13:14:51
|
Yo, i've just finished a rough draft for a DLL-using classloader which takes it's BaseType (a-la LoadableClass) via a template parameter. Under this model the LoadableClass --> ClassLoader explicit relationship is obsolete. Current caveats: - it's template based, so it's implemented in a header file. (It's not /so/ big, though.) - it (somehow) loads classes which do not derive from the BaseType, and i have no idea how/why it's doing it. This /might/ not be a problem in practice, but it sure is bugging the hell out of me (HTF is the dynamic_cast<BaseType*>(NonDerived*) actually working???). Consider: class LoadableClass {...} class Foo : public LoadableClass {...} class Bar : public LoadableClass {...} class Unrelated {...} typedef DLLLoader<LoadableClass> CL; CL cl; CL::value_type * obj = cl.load( "Foo" ); // finds Foo obj = cl.load( "Bar" ); // finds Bar obj = cl.load( "Unrelated" ); // somehow actually loads Unrelated as a LoadableClass(!?!?), // but it shouldn't. i don't have the code in the fun tree yet, but i'll move it all over once i'm happier with how it's working. After putting the s11n tree into fun this weekend i spent the rest of the weekend in a major refactoring session so i could: a) pull out some of the code that s11n is dependent on. b) make the non-removable code more project-portable, so i can maintain copies in elib and libfun without significant hassles. So, the LoadableClass classloader is now just a typedef: typedef DLLLoader<LoadableClass> ClassLoader; The loader can also take statically-registered factory functions. When i loads a class from an INSTANTIATOR func it maps that function back to it's registered factories, so the parent class (non-DLL-aware) can handle future requests for a given key. DLLLoader.cpp:11 : check_for_dll_bootstrap(0x40014f50 , main ) DLLLoader.cpp:20 : running DLLLoader_bootstrap() ../../../include/elib/DLLLoader.h:189 : No DLL found for key 'Car'. Looking in main() space. ../../../include/elib/DLLLoader.h:234 : Found instantiator new_Car() playground.cpp:152 : l[Car]=0x80af1b8 class=LoadableClass playground.cpp:48 : Car::foo() playground.cpp:153 : l[Car]=0x8126008 class=LoadableClass playground.cpp:48 : Car::foo() playground.cpp:154 : l[Car]=0x812cd18 class=LoadableClass playground.cpp:48 : Car::foo() playground.cpp:155 : l[Truck]=0x8128cb0 class=LoadableClass playground.cpp:99 : Truck::foo() ../../../include/elib/DLLLoader.h:189 : No DLL found for key 'Unrelated'. Looking in main() space. ../../../include/elib/DLLLoader.h:234 : Found instantiator new_Unrelated() playground.cpp:156 : l[Unrelated]=0x8124ec0 class=LoadableClass playground.cpp:69 : Unrelated::foo() ../../../include/elib/DLLLoader.h:189 : No DLL found for key 'Unloadable'. Looking in main() space. playground.cpp:157 : l[Unloadable]=0 ../../../include/elib/DLLLoader.h:194 : Found DLL for 'LoadableSubclass': ./LoadableSubclass.so DLLLoader.cpp:11 : check_for_dll_bootstrap(0x80a0390 , LoadableSubclass ) DLLLoader.cpp:17 : no DLLLoader_bootstrap() found in 0x80a0390 ../../../include/elib/DLLLoader.h:234 : Found instantiator new_LoadableSubclass() playground.cpp:158 : l[LoadableSubclass]=0x80f2570 class=LoadableClass LoadableSubclass.cpp:5 : LoadableSubclass::foo() -- ----- st...@ei... - http://www.einsurance.de "... it's up to other companies to ensure interoperability." -- Bill Gates http://www.nydailynews.com/city_life/tech/story/84722p-77434c.html |