The purpose of this library is to allow creating classes defined in dynamic libraries by specifying string name of the class.
A user provides a name of class, a name of a shared library and a set of constructor arguments. The library returns a new class instance. Example usage:
plugin<BasePlugin?> p("somelib.so", "SpecificType?"); BasePlugin?* n = p.create(10);
This use case is important because in general user might have his own mechanism for tracking which libraries contain which classes.
User loads several libraries and then creates a class by name and a set of constructor arguments.
plugin_registry<BasePlugin?> registry; registry.add("somelib.so"); BasePlugin?* n = registry["SpecificType?"].create(10);
Note: the operator[] would return instance of 'plugin'. This is the primary use case for the library.
In addition to the above, it might be desirable to create by name classes defined in the same application, not only in some library. For example, a compiler might have a number of passes, and it's reasonable if each pass just registers itself with the global registry and is then created via that registry.
It might be desirable to attach extra information to a plugin, in a form of a string. Might be good to handle versioning, for example. Not sure about this.
It's possible to create a system where user ask for a specific "service" with specific properties, and the library searches for the right plugin. Such system can become contrived, and I think we should not implement it for the first version.