ctkAbstractLibraryFactory.h 2.9 KB

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