ctkAbstractPluginFactory.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. All rights reserved.
  5. Distributed under a BSD License. See LICENSE.txt file.
  6. This software is distributed "AS IS" WITHOUT ANY WARRANTY; without even
  7. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the above copyright notice for more information.
  9. =========================================================================*/
  10. #ifndef __ctkAbstractPluginFactory_h
  11. #define __ctkAbstractPluginFactory_h
  12. #include "ctkAbstractFactory.h"
  13. #include <QPluginLoader>
  14. #include <QFileInfo>
  15. //----------------------------------------------------------------------------
  16. template<typename BaseClassType>
  17. class ctkFactoryPluginItem : public ctkAbstractFactoryItem<BaseClassType>
  18. {
  19. public:
  20. explicit ctkFactoryPluginItem(const QString& key, const QString& path);
  21. virtual bool load();
  22. QString path()const;
  23. virtual QString loadErrorString()const;
  24. protected:
  25. virtual BaseClassType* instanciator();
  26. private:
  27. QPluginLoader Loader;
  28. QString Path;
  29. };
  30. //----------------------------------------------------------------------------
  31. template<typename BaseClassType, typename FactoryItemType = ctkFactoryPluginItem<BaseClassType> >
  32. class ctkAbstractPluginFactory : public ctkAbstractFactory<BaseClassType>
  33. {
  34. public:
  35. ///
  36. /// Constructor
  37. explicit ctkAbstractPluginFactory();
  38. virtual ~ctkAbstractPluginFactory();
  39. ///
  40. /// Register a plugin in the factory
  41. virtual bool registerLibrary(const QFileInfo& file, QString& key);
  42. private:
  43. ctkAbstractPluginFactory(const ctkAbstractPluginFactory &); /// Not implemented
  44. void operator=(const ctkAbstractPluginFactory&); /// Not implemented
  45. };
  46. #include "ctkAbstractPluginFactory.tpp"
  47. #endif