ctkAbstractLibraryFactory.h 2.4 KB

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