ctkAbstractLibraryFactoryTest1.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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.commontk.org/LICENSE
  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. // Qt includes
  15. #include <QApplication>
  16. // CTK includes
  17. #include "ctkAbstractLibraryFactory.h"
  18. // STD includes
  19. #include <cstdlib>
  20. #include <iostream>
  21. int ObjectConstructed = 0;
  22. //-----------------------------------------------------------------------------
  23. class Object
  24. {
  25. public:
  26. Object()
  27. {
  28. ++ObjectConstructed;
  29. }
  30. ~Object()
  31. {
  32. --ObjectConstructed;
  33. }
  34. };
  35. //-----------------------------------------------------------------------------
  36. class ObjectFactoryItem : public ctkFactoryLibraryItem<Object>
  37. {
  38. public:
  39. ObjectFactoryItem(const QString& path)
  40. :ctkFactoryLibraryItem<Object>(path)
  41. {
  42. }
  43. protected:
  44. virtual Object* instanciator(){return new Object;}
  45. };
  46. //-----------------------------------------------------------------------------
  47. class ObjectFactory : public ctkAbstractLibraryFactory<Object>
  48. {
  49. public:
  50. virtual void registerItems()
  51. {
  52. qDebug() << "Registering items";
  53. }
  54. protected:
  55. virtual ctkFactoryLibraryItem<Object>* createFactoryLibraryItem(const QFileInfo& file)const
  56. {
  57. return new ObjectFactoryItem(file.filePath());
  58. }
  59. };
  60. //-----------------------------------------------------------------------------
  61. int ctkAbstractLibraryFactoryTest1(int argc, char * argv [])
  62. {
  63. QApplication app(argc, argv);
  64. ObjectFactory factory;
  65. factory.registerItems();
  66. return EXIT_SUCCESS;
  67. }