From fe58f0ee4b9d91f4ed349bafb16d2a8d6fb59faa Mon Sep 17 00:00:00 2001 From: Jordi Vilalta Prat Date: Tue, 13 May 2008 09:30:23 +0000 Subject: - Added operator-> to Plugin subclasses so they don't have to reimplement the PluginObject subclass interfaces (thanks to Fingolfin for suggesting it) - Added the PluginSubclass template to help creating Plugin subclasses svn-id: r32082 --- base/commandLine.cpp | 10 +++++----- base/main.cpp | 3 ++- base/plugins.cpp | 40 ++++++++-------------------------------- base/plugins.h | 28 ++++++++++++++-------------- gui/about.cpp | 8 ++++---- 5 files changed, 33 insertions(+), 56 deletions(-) diff --git a/base/commandLine.cpp b/base/commandLine.cpp index 5b919a495c..d2f286cc4a 100644 --- a/base/commandLine.cpp +++ b/base/commandLine.cpp @@ -23,7 +23,7 @@ * */ -#include "engines/engine.h" +#include "engines/metaengine.h" #include "base/commandLine.h" #include "base/plugins.h" #include "base/version.h" @@ -559,10 +559,10 @@ static void listGames() { printf("Game ID Full Title \n" "-------------------- ------------------------------------------------------\n"); - const EnginePluginList &plugins = EngineMan.getPlugins(); - EnginePluginList::const_iterator iter = plugins.begin(); + const EnginePlugin::list &plugins = EngineMan.getPlugins(); + EnginePlugin::list::const_iterator iter = plugins.begin(); for (iter = plugins.begin(); iter != plugins.end(); ++iter) { - GameList list = (*iter)->getSupportedGames(); + GameList list = (**iter)->getSupportedGames(); for (GameList::iterator v = list.begin(); v != list.end(); ++v) { printf("%-20s %s\n", v->gameid().c_str(), v->description().c_str()); } @@ -622,7 +622,7 @@ static void listSaves(const char *target) { } // Query the plugin for a list of savegames - SaveStateList saveList = plugin->listSaves(target); + SaveStateList saveList = (*plugin)->listSaves(target); // TODO: Include more info about the target (desc, engine name, ...) ??? printf("Saves for target '%s':\n", target); diff --git a/base/main.cpp b/base/main.cpp index 8b697e120d..c36c506d7f 100644 --- a/base/main.cpp +++ b/base/main.cpp @@ -32,6 +32,7 @@ */ #include "engines/engine.h" +#include "engines/metaengine.h" #include "base/commandLine.h" #include "base/plugins.h" #include "base/version.h" @@ -138,7 +139,7 @@ static int runGame(const EnginePlugin *plugin, OSystem &system, const Common::St // Create the game engine Engine *engine = 0; - PluginError err = plugin->createInstance(&system, &engine); + PluginError err = (*plugin)->createInstance(&system, &engine); if (!engine || err != kNoError) { // TODO: Show an error dialog or so? // TODO: Also take 'err' into consideration... diff --git a/base/plugins.cpp b/base/plugins.cpp index d2bd9b398a..d4153f17d3 100644 --- a/base/plugins.cpp +++ b/base/plugins.cpp @@ -301,43 +301,19 @@ bool PluginManager::tryLoadPlugin(Plugin *plugin) { #include "engines/metaengine.h" -const char *EnginePlugin::getCopyright() const { - return ((MetaEngine*)_pluginObject)->getCopyright(); -} - -PluginError EnginePlugin::createInstance(OSystem *syst, Engine **engine) const { - return ((MetaEngine*)_pluginObject)->createInstance(syst, engine); -} - -GameList EnginePlugin::getSupportedGames() const { - return ((MetaEngine*)_pluginObject)->getSupportedGames(); -} - -GameDescriptor EnginePlugin::findGame(const char *gameid) const { - return ((MetaEngine*)_pluginObject)->findGame(gameid); -} - -GameList EnginePlugin::detectGames(const FSList &fslist) const { - return ((MetaEngine*)_pluginObject)->detectGames(fslist); -} - -SaveStateList EnginePlugin::listSaves(const char *target) const { - return ((MetaEngine*)_pluginObject)->listSaves(target); -} - DECLARE_SINGLETON(EngineManager); GameDescriptor EngineManager::findGame(const Common::String &gameName, const EnginePlugin **plugin) const { // Find the GameDescriptor for this target - const EnginePluginList &plugins = getPlugins(); + const EnginePlugin::list &plugins = getPlugins(); GameDescriptor result; if (plugin) *plugin = 0; - EnginePluginList::const_iterator iter = plugins.begin(); + EnginePlugin::list::const_iterator iter = plugins.begin(); for (iter = plugins.begin(); iter != plugins.end(); ++iter) { - result = (*iter)->findGame(gameName.c_str()); + result = (**iter)->findGame(gameName.c_str()); if (!result.gameid().empty()) { if (plugin) *plugin = *iter; @@ -350,18 +326,18 @@ GameDescriptor EngineManager::findGame(const Common::String &gameName, const Eng GameList EngineManager::detectGames(const FSList &fslist) const { GameList candidates; - const EnginePluginList &plugins = getPlugins(); + const EnginePlugin::list &plugins = getPlugins(); // Iterate over all known games and for each check if it might be // the game in the presented directory. - EnginePluginList::const_iterator iter; + EnginePlugin::list::const_iterator iter; for (iter = plugins.begin(); iter != plugins.end(); ++iter) { - candidates.push_back((*iter)->detectGames(fslist)); + candidates.push_back((**iter)->detectGames(fslist)); } return candidates; } -const EnginePluginList &EngineManager::getPlugins() const { - return (const EnginePluginList&)PluginManager::instance().getPlugins(PLUGIN_TYPE_ENGINE); +const EnginePlugin::list &EngineManager::getPlugins() const { + return (const EnginePlugin::list&)PluginManager::instance().getPlugins(PLUGIN_TYPE_ENGINE); } diff --git a/base/plugins.h b/base/plugins.h index 3f2d19fd50..858c8d9106 100644 --- a/base/plugins.h +++ b/base/plugins.h @@ -141,6 +141,17 @@ public: /** List of plugins. */ typedef Common::Array PluginList; +/** Template to help defining Plugin subclasses */ +template +class PluginSubclass : public Plugin { +public: + PO_t *operator->() const { + return (PO_t *)_pluginObject; + } + + typedef Common::Array list; +}; + class PluginProvider { public: virtual ~PluginProvider() {} @@ -197,21 +208,10 @@ public: // Engine plugins -class Engine; class FSList; -class OSystem; - -class EnginePlugin : public Plugin { -public: - const char *getCopyright() const; - PluginError createInstance(OSystem *syst, Engine **engine) const; - GameList getSupportedGames() const; - GameDescriptor findGame(const char *gameid) const; - GameList detectGames(const FSList &fslist) const; - SaveStateList listSaves(const char *target) const; -}; +class MetaEngine; -typedef Common::Array EnginePluginList; +typedef PluginSubclass EnginePlugin; class EngineManager : public Common::Singleton { private: @@ -220,7 +220,7 @@ private: public: GameDescriptor findGame(const Common::String &gameName, const EnginePlugin **plugin = NULL) const; GameList detectGames(const FSList &fslist) const; - const EnginePluginList &getPlugins() const; + const EnginePlugin::list &getPlugins() const; }; /** Shortcut for accessing the engine manager. */ diff --git a/gui/about.cpp b/gui/about.cpp index b4d8cb0bf2..2afaae9a97 100644 --- a/gui/about.cpp +++ b/gui/about.cpp @@ -22,7 +22,7 @@ * $Id$ */ -#include "engines/engine.h" +#include "engines/metaengine.h" #include "base/plugins.h" #include "base/version.h" #include "common/events.h" @@ -128,8 +128,8 @@ AboutDialog::AboutDialog() _lines.push_back(""); addLine("\\C\\c1""Available engines:"); - const EnginePluginList &plugins = EngineMan.getPlugins(); - EnginePluginList::const_iterator iter = plugins.begin(); + const EnginePlugin::list &plugins = EngineMan.getPlugins(); + EnginePlugin::list::const_iterator iter = plugins.begin(); for (; iter != plugins.end(); ++iter) { Common::String str; str = "\\C"; @@ -137,7 +137,7 @@ AboutDialog::AboutDialog() addLine(str.c_str()); str = "\\C\\c2"; - str += (**iter).getCopyright(); + str += (**iter)->getCopyright(); addLine(str.c_str()); //addLine(""); -- cgit v1.2.3