ctkAbstractLibraryFactory.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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.apache.org/licenses/LICENSE-2.0.txt
  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 "ctkAbstractFileBasedFactory.h"
  22. //----------------------------------------------------------------------------
  23. /// \ingroup Core
  24. template<typename BaseClassType>
  25. class ctkFactoryLibraryItem : public ctkAbstractFactoryFileBasedItem<BaseClassType>
  26. {
  27. public:
  28. #if QT_VERSION < 0x50000
  29. typedef void* SymbolAddressType;
  30. #else
  31. typedef QFunctionPointer SymbolAddressType;
  32. #endif
  33. protected:
  34. typedef typename QHash<QString, SymbolAddressType>::const_iterator ConstIterator;
  35. typedef typename QHash<QString, SymbolAddressType>::iterator Iterator;
  36. public:
  37. //explicit ctkFactoryLibraryItem(const QString& path);
  38. virtual bool load();
  39. ///
  40. /// Set list of required symbols
  41. void setSymbols(const QStringList& symbols);
  42. /// Set lookup hints for symbol resolution. See QLibrary documentation.
  43. void setLoadHints(QLibrary::LoadHints hints);
  44. ///
  45. /// \brief Resolve symbols
  46. /// \note The function will return False if it fails to resolve one
  47. /// of the required symbols set using setSymbols(const QStringList&)
  48. bool resolve();
  49. ///
  50. /// Get symbol address
  51. SymbolAddressType symbolAddress(const QString& symbol)const;
  52. protected:
  53. mutable QLibrary Library;
  54. QHash<QString, SymbolAddressType> ResolvedSymbols;
  55. QStringList Symbols;
  56. };
  57. //----------------------------------------------------------------------------
  58. /// \ingroup Core
  59. template<typename BaseClassType>
  60. class ctkAbstractLibraryFactory
  61. : public ctkAbstractFileBasedFactory<BaseClassType>
  62. {
  63. public:
  64. /// Set the list of symbols
  65. void setSymbols(const QStringList& symbols);
  66. protected:
  67. virtual bool isValidFile(const QFileInfo& file)const;
  68. virtual void initItem(ctkAbstractFactoryItem<BaseClassType>* item);
  69. private:
  70. QStringList Symbols;
  71. };
  72. #include "ctkAbstractLibraryFactory.tpp"
  73. #endif