
Vladislav Lazarenko wrote:
Vladimir Prus wrote:
I have some initial work in boost sandbox, directory libs/plugin. However, I'm more interested in higher-level functionality -- given a shared library create an instance of class defined there, given name of the class and a set of constructor arguments.
- Volodya
Hm.. it will aplly some dependensies to shared library development. I mean it is impossible for example to get a set of constructor argument of the class stored in the shared library without shared library development agreement. So, if we want to go this way then we need to define some base interface for the class and all of the classes in SO/DLL should implement it.
Sure. I doubt there are many use case where you can use a symbol in a DLL knowing only its name ;-)
Moreone, for class X we should have some description struct which will have information about that class (at least class type), a pointer to the function which will create an instance of the class, information about arguments (possible with its description), pointer to the function which creates an instance of that class (Class *createInstance(...)). And also a list of exported classes (extern "C" struct with a list of description structs), init and fini methods (to hide DLLMain/_init/_fini from the user).
Am I right?
Yes. In my design shared library keeps a map<string, any>. When you want to create a plugin, you specify a name and a base type. That map is accessed for and the 'any' value, if found, is cast to 'abstract_factory<BasePluginType>' and then a 'create' method of 'abstract_factory' is called. For each base plugin type, you specialize a template class called 'virtual_constructors', which specifies all constructor signatures you may use when creating plugins of those types. So, abstract_factory<BasePluginType> will have one 'create' overload for each signature. The information about arguments is not represented at run-time, as I can get everything to work with static type information. - Volodya