ctkAbstractPluginFactory.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) 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& path);
  27. virtual bool load();
  28. QString path()const;
  29. virtual QString loadErrorString()const;
  30. protected:
  31. virtual BaseClassType* instanciator();
  32. private:
  33. QPluginLoader Loader;
  34. QString Path;
  35. };
  36. //----------------------------------------------------------------------------
  37. template<typename BaseClassType>
  38. class ctkAbstractPluginFactory : public ctkAbstractFactory<BaseClassType>
  39. {
  40. public:
  41. /// Constructor
  42. explicit ctkAbstractPluginFactory();
  43. /// Register a plugin in the factory
  44. virtual bool registerLibrary(const QString& key, const QFileInfo& file);
  45. /// Get path associated with the plugin identified by \a key
  46. virtual QString path(const QString& key);
  47. protected:
  48. virtual ctkAbstractFactoryItem<BaseClassType>* createFactoryPluginItem(const QFileInfo& file);
  49. private:
  50. ctkAbstractPluginFactory(const ctkAbstractPluginFactory &); /// Not implemented
  51. void operator=(const ctkAbstractPluginFactory&); /// Not implemented
  52. };
  53. #include "ctkAbstractPluginFactory.tpp"
  54. #endif