ctkAbstractLibraryFactory.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. protected:
  28. typedef typename QHash<QString, void*>::const_iterator ConstIterator;
  29. typedef typename QHash<QString, void*>::iterator Iterator;
  30. public:
  31. //explicit ctkFactoryLibraryItem(const QString& path);
  32. virtual bool load();
  33. virtual QString loadErrorString()const;
  34. ///
  35. /// Set list of required symbols
  36. void setSymbols(const QStringList& symbols);
  37. ///
  38. /// \brief Resolve symbols
  39. /// \note The function will return False if it fails to resolve one
  40. /// of the required symbols set using ::setSymbols
  41. bool resolve();
  42. ///
  43. /// Get symbol address
  44. void* symbolAddress(const QString& symbol)const;
  45. protected:
  46. QLibrary Library;
  47. QHash<QString, void*> ResolvedSymbols;
  48. QStringList Symbols;
  49. };
  50. //----------------------------------------------------------------------------
  51. /// \ingroup Core
  52. template<typename BaseClassType>
  53. class ctkAbstractLibraryFactory
  54. : public ctkAbstractFileBasedFactory<BaseClassType>
  55. {
  56. public:
  57. /// Set the list of symbols
  58. void setSymbols(const QStringList& symbols);
  59. protected:
  60. virtual bool isValidFile(const QFileInfo& file)const;
  61. virtual void initItem(ctkAbstractFactoryItem<BaseClassType>* item);
  62. private:
  63. QStringList Symbols;
  64. };
  65. #include "ctkAbstractLibraryFactory.tpp"
  66. #endif