A simple C++ framework for Plugins (interface + factory) loadable from shared libraries
class someInterface {
public:
virtual blah iface(blah) = 0;
virtual ~someInterface() {};
someInterface(someArgs) {};
};
In that, use the PLUGIN()
and PLUGIN_DEFS()
macros. PLUGIN declares the class (inheriting from the interface via some other internal stuff). PLUGIN_DEFS declares/defines some magic registration objects (and a factory)
#include <Plugin>
#include <someInterface>
PLUGIN(someInteface, someImplementationName) {
public:
virtual blah iface(blah) { ... };
~someImplementation() {...};
someImplementation(someargs) { ... };
};
PLUGIN_DEFS(someInterface, someImplementation);
- Write a consumer. Somewhere in the global scope in the actual process you'll need to use PLUGIN_BASE()
#include <Plugin>
PLUGIN_BASE()
...
try {
someInterface *i = Plugin<someInterface,someargs>::getPlugin(
"name", args...);
} catch (std::runtime_error &e) {
cerr << "Failed to load plugin: " << e.what() << endl;
}