Plugin.hpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. ///
  2. /// \file Plugin/Plugin.hpp
  3. ///
  4. /// The plugin representation for the plugin registry.
  5. ///
  6. /// \copyright
  7. /// Copyright (c) 2013-2016 Josh Blum
  8. /// SPDX-License-Identifier: BSL-1.0
  9. ///
  10. #pragma once
  11. #include <Pothos/Config.hpp>
  12. #include <Pothos/Plugin/Path.hpp>
  13. #include <Pothos/Plugin/Module.hpp>
  14. #include <Pothos/Object/Object.hpp>
  15. #include <string>
  16. namespace Pothos {
  17. /*!
  18. * A plugin is a combination of an Path, Object, and a Module.
  19. */
  20. class POTHOS_API Plugin
  21. {
  22. public:
  23. //! Create a null plugin
  24. Plugin(void);
  25. /*!
  26. * Create a plugin from components.
  27. */
  28. Plugin(const PluginPath &path,
  29. const Object &object = Object(),
  30. const PluginModule &module = PluginModule::null());
  31. /*!
  32. * Create a plugin from components.
  33. * This templated version takes any type and stores it in an Object.
  34. */
  35. template <typename ValueType>
  36. Plugin(const PluginPath &path, ValueType &&value);
  37. //! Get the path from the Plugin.
  38. const PluginPath &getPath(void) const;
  39. //! Get the object from the Plugin.
  40. const Object &getObject(void) const;
  41. //! Get the Module from the Plugin.
  42. PluginModule getModule(void) const;
  43. //! String representation of plugin
  44. std::string toString(void) const;
  45. private:
  46. // This module owns the plugin, so its just a weak pointer.
  47. std::weak_ptr<PluginModule::Impl> _module;
  48. PluginPath _path;
  49. Object _object;
  50. };
  51. } //namespace Pothos
  52. #include <utility> //std::forward
  53. template <typename ValueType>
  54. Pothos::Plugin::Plugin(const PluginPath &path, ValueType &&value):
  55. _path(path),
  56. _object(Object(std::forward<ValueType>(value)))
  57. {
  58. return;
  59. }