ctkAbstractLibraryFactory.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 __ctkAbstractLibraryFactory_h
  11. #define __ctkAbstractLibraryFactory_h
  12. #include "ctkAbstractFactory.h"
  13. #include <QFileInfo>
  14. #include <QLibrary>
  15. #include <QStringList>
  16. //----------------------------------------------------------------------------
  17. template<typename BaseClassType>
  18. class ctkFactoryLibraryItem : public ctkAbstractFactoryItem<BaseClassType>
  19. {
  20. protected:
  21. typedef typename QHash<QString, void*>::const_iterator ConstIterator;
  22. typedef typename QHash<QString, void*>::iterator Iterator;
  23. public:
  24. explicit ctkFactoryLibraryItem(const QString& key, const QString& path);
  25. virtual bool load();
  26. QString path()const;
  27. virtual QString loadErrorString()const;
  28. void setSymbols(const QStringList& symbols);
  29. //-----------------------------------------------------------------------------
  30. ///
  31. /// Resolve symbols
  32. void resolve();
  33. //-----------------------------------------------------------------------------
  34. ///
  35. /// Get symbol address
  36. void* symbolAddress(const QString& symbol)const;
  37. private:
  38. QLibrary Library;
  39. QString Path;
  40. QHash<QString, void*> ResolvedSymbols;
  41. QStringList Symbols;
  42. };
  43. //----------------------------------------------------------------------------
  44. template<typename BaseClassType, typename FactoryItemType>
  45. class ctkAbstractLibraryFactory : public ctkAbstractFactory<BaseClassType>
  46. {
  47. public:
  48. //-----------------------------------------------------------------------------
  49. ///
  50. /// Constructor
  51. explicit ctkAbstractLibraryFactory();
  52. virtual ~ctkAbstractLibraryFactory();
  53. //-----------------------------------------------------------------------------
  54. ///
  55. /// Set the list of symbols
  56. void setSymbols(const QStringList& symbols);
  57. //-----------------------------------------------------------------------------
  58. ///
  59. /// Register a plugin in the factory
  60. virtual bool registerLibrary(const QFileInfo& file, QString& key);
  61. private:
  62. ctkAbstractLibraryFactory(const ctkAbstractLibraryFactory &); /// Not implemented
  63. void operator=(const ctkAbstractLibraryFactory&); /// Not implemented
  64. QStringList Symbols;
  65. };
  66. #include "ctkAbstractLibraryFactory.tpp"
  67. #endif