34 virtual void *Create()
override {
46 std::map<std::string, GFactoryBase *> factoryMap;
51 std::map<std::string, DynamicLib *> dlMap;
61 void registerDL(std::string name) {
63 dlMap[name] =
new DynamicLib(log, name +
".gplugin");
64 log->debug(NORMAL,
"Loading DL ", name);
73 GManager(GLogger
const *logger, std::string name) : gname(name), log(logger) {
74 log->debug(CONSTRUCTOR,
"Instantiating ", gname);
86 template<
class Derived>
89 log->debug(NORMAL,
"Registering ", name,
"into factory Map");
105 auto factory = factoryMap.find(name);
107 if (factory == factoryMap.end()) {
111 log->debug(NORMAL,
"Creating instance of ", name,
" factory.");
112 return static_cast<Base *
>(factory->second->Create());
130 if (dynamicLib !=
nullptr) {
132 if (thisDLHandle !=
nullptr) {
133 return T::instantiate(thisDLHandle);
159 for (
auto &i: dlMap) {
virtual void * Create()=0
Pure virtual method. Derived classes use this to instantiate themselves.
Derived from GFactoryBase, implements Create to instantiate the derived classes.
Instantiates derived classes either statically or dynamically.
Base * CreateObject(std::string name) const
void RegisterObjectFactory(std::string name)
T * LoadAndRegisterObjectFromLibrary(std::string name)
GManager(GLogger const *logger, std::string name)
#define EC__FACTORYNOTFOUND
#define EC__DLHANDLENOTFOUND
Structure to load dynamically symbols from a shared library.