ctkAbstractLibraryFactory.h 2.7 KB

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