Slightly reduced internal reliance on specific module backends

This commit is contained in:
Alex Szpakowski
2013-08-03 16:30:37 -03:00
parent 2106ff2403
commit 3e57cfd174
7 changed files with 39 additions and 21 deletions
+15 -2
View File
@@ -54,9 +54,9 @@ void Module::registerInstance(Module *instance)
registry.insert(make_pair(name, instance));
}
Module *Module::getInstance(const char *name)
Module *Module::getInstance(const std::string &name)
{
std::map<std::string, Module*>::iterator it = registry.find(std::string(name));
std::map<std::string, Module*>::const_iterator it = registry.find(name);
if (registry.end() == it)
return NULL;
@@ -64,4 +64,17 @@ Module *Module::getInstance(const char *name)
return it->second;
}
Module *Module::findInstance(const std::string &name)
{
std::map<std::string, Module*>::const_iterator it;
for (it = registry.begin(); it != registry.end(); ++it)
{
if (it->first.find(name) == 0)
return it->second;
}
return NULL;
}
} // love
+11 -2
View File
@@ -59,9 +59,18 @@ public:
* Retrieve module instance from internal registry. May return NULL
* if module not registered.
* @param name The full name of the module.
* @returns Module instance of NULL if the module is not registered.
* @return Module instance or NULL if the module is not registered.
*/
static Module *getInstance(const char *name);
static Module *getInstance(const std::string &name);
/**
* Find the first module instance from the internal registry whose name
* starts with the supplied name. May return NULL if module is not
* registered or the supplied name is not part of any module name.
* @param name The partial name of the module.
* @return Module instance or NULL if the module is not registered.
**/
static Module *findInstance(const std::string &name);
}; // Module