ctkAbstractFileBasedFactory.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 __ctkAbstractFileBasedFactory_h
  15. #define __ctkAbstractFileBasedFactory_h
  16. // Qt includes
  17. #include <QFileInfo>
  18. #include <QStringList>
  19. // CTK includes
  20. #include "ctkAbstractFactory.h"
  21. //----------------------------------------------------------------------------
  22. /// \ingroup Core
  23. template<typename BaseClassType>
  24. class ctkAbstractFactoryFileBasedItem
  25. : public ctkAbstractFactoryItem<BaseClassType>
  26. {
  27. public:
  28. /// Get path associated with the object identified by \a key
  29. void setPath(const QString& path);
  30. QString path()const;
  31. private:
  32. QString Path;
  33. };
  34. //----------------------------------------------------------------------------
  35. /// \ingroup Core
  36. template<typename BaseClassType>
  37. class ctkAbstractFileBasedFactory : public ctkAbstractFactory<BaseClassType>
  38. {
  39. public:
  40. /// Get path associated with the library identified by \a key
  41. virtual QString path(const QString& key);
  42. bool registerFileItem(const QFileInfo& file);
  43. bool registerFileItem(const QString& key, const QFileInfo& file);
  44. protected:
  45. void registerAllFileItems(const QStringList& directories);
  46. virtual bool isValidFile(const QFileInfo& file)const;
  47. virtual ctkAbstractFactoryItem<BaseClassType>* createFactoryFileBasedItem();
  48. virtual void initItem(ctkAbstractFactoryItem<BaseClassType>* item);
  49. virtual QString fileNameToKey(const QString& objectName)const;
  50. };
  51. #include "ctkAbstractFileBasedFactory.tpp"
  52. #endif