diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-09-28 01:01:30 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-09-28 01:01:30 +0100 |
commit | 22e8e288d8e2f02a5bd2da743b257096cc7513ff (patch) | |
tree | 480adac2a8e2a5ae1fa757b2945ebdc7c1597746 | |
parent | Unambiguous create function name (diff) | |
download | libadhocutil-22e8e288d8e2f02a5bd2da743b257096cc7513ff.tar.bz2 libadhocutil-22e8e288d8e2f02a5bd2da743b257096cc7513ff.tar.xz libadhocutil-22e8e288d8e2f02a5bd2da743b257096cc7513ff.zip |
Access to plugin implementations from the very base class of plugin
-rw-r--r-- | libadhocutil/factory.h | 2 | ||||
-rw-r--r-- | libadhocutil/plugins.cpp | 2 | ||||
-rw-r--r-- | libadhocutil/plugins.h | 11 | ||||
-rw-r--r-- | libadhocutil/unittests/testPlugins.cpp | 5 | ||||
-rw-r--r-- | libadhocutil/unittests/utilTestClasses.h | 6 |
5 files changed, 21 insertions, 5 deletions
diff --git a/libadhocutil/factory.h b/libadhocutil/factory.h index 1765f50..184164f 100644 --- a/libadhocutil/factory.h +++ b/libadhocutil/factory.h @@ -9,7 +9,7 @@ namespace AdHoc { * Base class for factories creating instances of Base. */ template <typename Base, typename ... Params> - class DLL_PUBLIC Factory { + class DLL_PUBLIC Factory : public AbstractPluginImplementation { public: virtual ~Factory() = 0; diff --git a/libadhocutil/plugins.cpp b/libadhocutil/plugins.cpp index a1eef70..2630e57 100644 --- a/libadhocutil/plugins.cpp +++ b/libadhocutil/plugins.cpp @@ -49,6 +49,8 @@ namespace AdHoc { defaultPluginManager = nullptr; } + AbstractPluginImplementation::~AbstractPluginImplementation() = default; + Plugin::Plugin(const std::string & n, const std::string & f, int l) : name(n), filename(f), diff --git a/libadhocutil/plugins.h b/libadhocutil/plugins.h index 4e81b62..d73ffec 100644 --- a/libadhocutil/plugins.h +++ b/libadhocutil/plugins.h @@ -30,6 +30,12 @@ namespace AdHoc { NoSuchPluginException(const std::string &, const std::type_info &); }; + /// Base class for all plugin implementations. + class DLL_PUBLIC AbstractPluginImplementation { + public: + virtual ~AbstractPluginImplementation() = 0; + }; + /// Base class for untyped plugins. class DLL_PUBLIC Plugin { public: @@ -40,6 +46,9 @@ namespace AdHoc { /// Get the plugin type from the subclass. virtual const std::type_info & type() const = 0; + /// Get the abstract base plugin implementation. + virtual const AbstractPluginImplementation * implementation() const = 0; + /// The name the plugin was installed with. const std::string name; /// The filename the plugin was installed in. @@ -81,7 +90,7 @@ namespace AdHoc { /// Get the type of this plugin. const std::type_info & type() const override; /// Get the implementation of this plugin. - const T * implementation() const; + const T * implementation() const override; private: const T * impl; diff --git a/libadhocutil/unittests/testPlugins.cpp b/libadhocutil/unittests/testPlugins.cpp index ef5ed4b..d0f38a1 100644 --- a/libadhocutil/unittests/testPlugins.cpp +++ b/libadhocutil/unittests/testPlugins.cpp @@ -23,7 +23,6 @@ BOOST_AUTO_TEST_CASE( get ) BOOST_REQUIRE(implOfThingPlugin != nullptr); auto implOfThing = implOfThingPlugin->implementation(); BOOST_REQUIRE(implOfThing != nullptr); - BOOST_REQUIRE_EQUAL(typeid(BaseThing), typeid(*implOfThing)); auto implOfThingDirect = PluginManager::getDefault()->getImplementation<BaseThing>("ImplOfThing"); BOOST_REQUIRE_EQUAL(implOfThing, implOfThingDirect); } @@ -32,6 +31,10 @@ BOOST_AUTO_TEST_CASE( getAll ) { auto all = PluginManager::getDefault()->getAll(); BOOST_REQUIRE_EQUAL(1, all.size()); + auto base = (*all.begin())->implementation(); + BOOST_REQUIRE(base); + BOOST_REQUIRE(dynamic_cast<const BaseThing *>(base)); + BOOST_REQUIRE(dynamic_cast<const ImplOfThing *>(base)); auto allOf = PluginManager::getDefault()->getAll<BaseThing>(); BOOST_REQUIRE_EQUAL(1, allOf.size()); } diff --git a/libadhocutil/unittests/utilTestClasses.h b/libadhocutil/unittests/utilTestClasses.h index f2a2036..18ddbef 100644 --- a/libadhocutil/unittests/utilTestClasses.h +++ b/libadhocutil/unittests/utilTestClasses.h @@ -1,7 +1,9 @@ #ifndef LIBADHOCUTIL_UNITTESTS_UTILTESTCLASSES_H #define LIBADHOCUTIL_UNITTESTS_UTILTESTCLASSES_H -class BaseThing { +#include <plugins.h> + +class BaseThing : public AdHoc::AbstractPluginImplementation { }; class ImplOfThing : public BaseThing { @@ -10,7 +12,7 @@ class ImplOfThing : public BaseThing { class OtherImplOfThing : public BaseThing { }; -class OtherBase { +class OtherBase : public AdHoc::AbstractPluginImplementation { }; class OtherImpl : public OtherBase { |