diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2020-02-15 11:56:16 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2020-02-15 12:32:25 +0000 |
commit | b8a7c3d7814ca8594ab14e497d143d9e3e2193ad (patch) | |
tree | 0e9cfccf44734dc1d873f891e0999ae741587956 /libadhocutil/plugins.h | |
parent | Add Nagios passive check helpers (diff) | |
download | libadhocutil-b8a7c3d7814ca8594ab14e497d143d9e3e2193ad.tar.bz2 libadhocutil-b8a7c3d7814ca8594ab14e497d143d9e3e2193ad.tar.xz libadhocutil-b8a7c3d7814ca8594ab14e497d143d9e3e2193ad.zip |
Big modernize and tidy
Diffstat (limited to 'libadhocutil/plugins.h')
-rw-r--r-- | libadhocutil/plugins.h | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/libadhocutil/plugins.h b/libadhocutil/plugins.h index ce3447a..81764da 100644 --- a/libadhocutil/plugins.h +++ b/libadhocutil/plugins.h @@ -10,6 +10,7 @@ #include <algorithm> #include "visibility.h" #include "unique.h" +#include "c++11Helpers.h" namespace std { DLL_PUBLIC @@ -28,7 +29,10 @@ namespace AdHoc { /// Base class for all plugin implementations. class DLL_PUBLIC AbstractPluginImplementation { public: + AbstractPluginImplementation() = default; virtual ~AbstractPluginImplementation() = 0; + /// Standard move/copy support + SPECIAL_MEMBERS_DEFAULT(AbstractPluginImplementation); }; /// Base class for untyped plugins. @@ -36,13 +40,15 @@ namespace AdHoc { public: /// Constructor taking name, filename and line of install. Plugin(const std::string_view &, const std::string_view &, int); + /// Standard move/copy support + SPECIAL_MEMBERS_DELETE(Plugin); virtual ~Plugin() = default; /// Get the plugin type from the subclass. - virtual const std::type_info & type() const = 0; + [[nodiscard]] virtual const std::type_info & type() const = 0; /// Get the abstract base plugin implementation. - virtual std::shared_ptr<AbstractPluginImplementation> instance() const = 0; + [[nodiscard]] virtual std::shared_ptr<AbstractPluginImplementation> instance() const = 0; /// The name the plugin was installed with. const std::string name; @@ -51,7 +57,7 @@ namespace AdHoc { /// The line of file the plugin was installed in. const int lineno; }; - typedef std::shared_ptr<const Plugin> PluginPtr; + using PluginPtr = std::shared_ptr<const Plugin>; /// Thrown when a plugin with the same name and base is loaded into a manager. class DuplicatePluginException : public std::runtime_error { @@ -64,7 +70,7 @@ namespace AdHoc { class DuplicateResolverException : public std::runtime_error { public: /// Constuctor taking resolver type. - DuplicateResolverException(const std::type_info &); + explicit DuplicateResolverException(const std::type_info &); }; /// Thrown when an attempt to load a library fails. @@ -79,17 +85,17 @@ namespace AdHoc { class DLL_PUBLIC PluginOf : public Plugin { public: /// Constructor taking an instance and name, filename and line of install for Plugin. - PluginOf(const std::shared_ptr<T> & t, const std::string_view & n, const std::string_view & f, int l); + PluginOf(std::shared_ptr<T> t, const std::string_view & n, const std::string_view & f, int l); /// Get the type of this plugin. - const std::type_info & type() const override; + [[nodiscard]] const std::type_info & type() const override; /// Get the implementation of this plugin. - std::shared_ptr<T> implementation() const; + [[nodiscard]] std::shared_ptr<T> implementation() const; - std::shared_ptr<AbstractPluginImplementation> instance() const override; + [[nodiscard]] std::shared_ptr<AbstractPluginImplementation> instance() const override; private: - std::shared_ptr<T> impl; + const std::shared_ptr<T> impl; }; /// Container for loaded plugins. @@ -97,21 +103,24 @@ namespace AdHoc { public: /// Callback definition to resolve a plugin type and name to a potential library /// containing an implementation. - typedef std::function<std::optional<std::string> (const std::type_info &, const std::string_view &)> PluginResolver; + using PluginResolver = std::function<std::optional<std::string> (const std::type_info &, const std::string_view &)>; PluginManager(); virtual ~PluginManager(); + /// Standard move/copy support + SPECIAL_MEMBERS_DELETE(PluginManager); + /// Install a plugin. void add(const PluginPtr &); /// Uninstall a plugin. void remove(const std::string_view &, const std::type_info &); /// Get a specific plugin. - PluginPtr get(const std::string_view &, const std::type_info &) const; + [[nodiscard]] PluginPtr get(const std::string_view &, const std::type_info &) const; /// Get all plugins. - std::set<PluginPtr> getAll() const; + [[nodiscard]] std::set<PluginPtr> getAll() const; /// Get all plugins of a specific type. - std::set<PluginPtr> getAll(const std::type_info &) const; + [[nodiscard]] std::set<PluginPtr> getAll(const std::type_info &) const; /** * Install a plugin. @@ -147,23 +156,23 @@ namespace AdHoc { * Get a specific plugin. * @param n Name of plugin. */ - template<typename T> std::shared_ptr<const PluginOf<T>> get(const std::string_view & n) const; + template<typename T> [[nodiscard]] std::shared_ptr<const PluginOf<T>> get(const std::string_view & n) const; /** * Get the implementation from specific plugin. * @param n Name of plugin. */ - template<typename T> std::shared_ptr<T> getImplementation(const std::string_view & n) const; + template<typename T> [[nodiscard]] std::shared_ptr<T> getImplementation(const std::string_view & n) const; /** * Get all plugins of a given time. */ - template<typename T> std::set<std::shared_ptr<const PluginOf<T>>> getAll() const; + template<typename T> [[nodiscard]] std::set<std::shared_ptr<const PluginOf<T>>> getAll() const; /** * The number of installed plugins. */ - size_t count() const; + [[nodiscard]] size_t count() const; /** * Add a type plugin resolver function. @@ -192,7 +201,7 @@ namespace AdHoc { /** * The number of installed plugins. */ - size_t countResolvers() const; + [[nodiscard]] size_t countResolvers() const; /** * Get the default plugin manager instance. |