mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
Slightly reduced internal reliance on specific module backends
This commit is contained in:
+15
-2
@@ -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
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user