ctkAbstractPluginFactory.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) 2010 Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.commontk.org/LICENSE
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. #ifndef __ctkAbstractPluginFactory_h
  15. #define __ctkAbstractPluginFactory_h
  16. // Qt includes
  17. #include <QPluginLoader>
  18. #include <QFileInfo>
  19. // CTK includes
  20. #include "ctkAbstractFactory.h"
  21. //----------------------------------------------------------------------------
  22. template<typename BaseClassType>
  23. class ctkFactoryPluginItem : public ctkAbstractFactoryItem<BaseClassType>
  24. {
  25. public:
  26. explicit ctkFactoryPluginItem(const QString& key, const QString& path);
  27. virtual ~ctkFactoryPluginItem(){}
  28. virtual bool load();
  29. QString path()const;
  30. virtual QString loadErrorString()const;
  31. protected:
  32. virtual BaseClassType* instanciator();
  33. private:
  34. QPluginLoader Loader;
  35. QString Path;
  36. };
  37. //----------------------------------------------------------------------------
  38. template<typename BaseClassType, typename FactoryItemType = ctkFactoryPluginItem<BaseClassType> >
  39. class ctkAbstractPluginFactory : public ctkAbstractFactory<BaseClassType>
  40. {
  41. public:
  42. ///
  43. /// Constructor
  44. explicit ctkAbstractPluginFactory();
  45. virtual ~ctkAbstractPluginFactory();
  46. ///
  47. /// Return a name allowing to uniquely identify the plugin
  48. /// By default, it return \a fileName
  49. virtual QString fileNameToKey(const QString& fileName);
  50. ///
  51. /// Register a plugin in the factory
  52. /// The parameter \a key passed by reference will be updated with the
  53. /// associated object name obtained using ::fileNameToKey()
  54. virtual bool registerLibrary(const QFileInfo& file, QString& key);
  55. private:
  56. ctkAbstractPluginFactory(const ctkAbstractPluginFactory &); /// Not implemented
  57. void operator=(const ctkAbstractPluginFactory&); /// Not implemented
  58. };
  59. #include "ctkAbstractPluginFactory.tpp"
  60. #endif