aboutsummaryrefslogtreecommitdiff
path: root/base/plugins.cpp
diff options
context:
space:
mode:
authorColin Snover2017-11-10 23:06:42 -0600
committerColin Snover2017-12-03 20:26:38 -0600
commitd087c9605ffffdc9053c5efdc83f53658afbe9a6 (patch)
treedc03820fe11d65d683c386512086f62faeb98089 /base/plugins.cpp
parent55855cab838c2cb48ea02b983924f4c2b53583c1 (diff)
downloadscummvm-rg350-d087c9605ffffdc9053c5efdc83f53658afbe9a6.tar.gz
scummvm-rg350-d087c9605ffffdc9053c5efdc83f53658afbe9a6.tar.bz2
scummvm-rg350-d087c9605ffffdc9053c5efdc83f53658afbe9a6.zip
BASE: Remove bad casts between incompatible Plugin types
Previously, a C-style cast was used to convert a Common::Array<Plugin *>, populated with pointers to StaticPlugin and DynamicPlugin instances, to a Common::Array<PluginSubclass<T> *>, but PluginSubclass<T> is a *sibling* class to StaticPlugin/DynamicPlugin, so this cast was invalid and the results undefined. The methods for retrieving subclasses of plugins can't be easily changed to just generate an array of temporary wrapper objects that expose an identical API which dereferences to the preferred PluginObject subclass because pointers to these objects are retained by other parts of ScummVM, so the wrappers would needed to be persisted or they would need to just re-expose the underlying Plugin object again. This indicated that a way to solve this problem is to have the callers receive Plugin objects and get the PluginObject from the Plugin by explicitly stating their desired type, in a similar manner to std::get(std::variant), so that the pattern used by this patch to solve the problem. Closes gh-1051.
Diffstat (limited to 'base/plugins.cpp')
-rw-r--r--base/plugins.cpp24
1 files changed, 12 insertions, 12 deletions
diff --git a/base/plugins.cpp b/base/plugins.cpp
index 39aaf2f73e..18755003b4 100644
--- a/base/plugins.cpp
+++ b/base/plugins.cpp
@@ -457,7 +457,7 @@ DECLARE_SINGLETON(EngineManager);
* For the uncached version, we first try to find the plugin using the gameId
* and only if we can't find it there, we loop through the plugins.
**/
-GameDescriptor EngineManager::findGame(const Common::String &gameName, const EnginePlugin **plugin) const {
+GameDescriptor EngineManager::findGame(const Common::String &gameName, const Plugin **plugin) const {
GameDescriptor result;
// First look for the game using the plugins in memory. This is critical
@@ -493,18 +493,18 @@ GameDescriptor EngineManager::findGame(const Common::String &gameName, const Eng
/**
* Find the game within the plugins loaded in memory
**/
-GameDescriptor EngineManager::findGameInLoadedPlugins(const Common::String &gameName, const EnginePlugin **plugin) const {
+GameDescriptor EngineManager::findGameInLoadedPlugins(const Common::String &gameName, const Plugin **plugin) const {
// Find the GameDescriptor for this target
- const EnginePlugin::List &plugins = getPlugins();
+ const PluginList &plugins = getPlugins();
GameDescriptor result;
if (plugin)
*plugin = 0;
- EnginePlugin::List::const_iterator iter;
+ PluginList::const_iterator iter;
for (iter = plugins.begin(); iter != plugins.end(); ++iter) {
- result = (**iter)->findGame(gameName.c_str());
+ result = (*iter)->get<MetaEngine>().findGame(gameName.c_str());
if (!result.gameid().empty()) {
if (plugin)
*plugin = *iter;
@@ -516,22 +516,22 @@ GameDescriptor EngineManager::findGameInLoadedPlugins(const Common::String &game
GameList EngineManager::detectGames(const Common::FSList &fslist) const {
GameList candidates;
- EnginePlugin::List plugins;
- EnginePlugin::List::const_iterator iter;
+ PluginList plugins;
+ PluginList::const_iterator iter;
PluginManager::instance().loadFirstPlugin();
do {
plugins = getPlugins();
// Iterate over all known games and for each check if it might be
// the game in the presented directory.
for (iter = plugins.begin(); iter != plugins.end(); ++iter) {
- candidates.push_back((**iter)->detectGames(fslist));
+ candidates.push_back((*iter)->get<MetaEngine>().detectGames(fslist));
}
} while (PluginManager::instance().loadNextPlugin());
return candidates;
}
-const EnginePlugin::List &EngineManager::getPlugins() const {
- return (const EnginePlugin::List &)PluginManager::instance().getPlugins(PLUGIN_TYPE_ENGINE);
+const PluginList &EngineManager::getPlugins() const {
+ return PluginManager::instance().getPlugins(PLUGIN_TYPE_ENGINE);
}
@@ -543,6 +543,6 @@ namespace Common {
DECLARE_SINGLETON(MusicManager);
}
-const MusicPlugin::List &MusicManager::getPlugins() const {
- return (const MusicPlugin::List &)PluginManager::instance().getPlugins(PLUGIN_TYPE_MUSIC);
+const PluginList &MusicManager::getPlugins() const {
+ return PluginManager::instance().getPlugins(PLUGIN_TYPE_MUSIC);
}