ctkAbstractObjectFactory.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. All rights reserved.
  5. Distributed under a BSD License. See LICENSE.txt file.
  6. This software is distributed "AS IS" WITHOUT ANY WARRANTY; without even
  7. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the above copyright notice for more information.
  9. =========================================================================*/
  10. #ifndef __ctkAbstractObjectFactory_h
  11. #define __ctkAbstractObjectFactory_h
  12. #include "ctkAbstractFactory.h"
  13. #include <QDebug>
  14. //----------------------------------------------------------------------------
  15. namespace{
  16. ///
  17. /// Function in charge of instanciating an object of type: ClassType
  18. template<typename BaseClassType, typename ClassType>
  19. BaseClassType *instantiateObject()
  20. {
  21. return new ClassType;
  22. }
  23. }
  24. //----------------------------------------------------------------------------
  25. template<typename BaseClassType, typename ClassType>
  26. class ctkFactoryObjectItem : public ctkAbstractFactoryItem<BaseClassType>
  27. {
  28. protected:
  29. typedef BaseClassType *(*InstantiateObjectFunc)();
  30. public:
  31. explicit ctkFactoryObjectItem(const QString& key);
  32. virtual bool load();
  33. protected:
  34. virtual BaseClassType* instanciator();
  35. private:
  36. InstantiateObjectFunc instantiateObjectFunc;
  37. };
  38. //----------------------------------------------------------------------------
  39. template<typename BaseClassType>
  40. class ctkAbstractObjectFactory : public ctkAbstractFactory<BaseClassType>
  41. {
  42. public:
  43. //-----------------------------------------------------------------------------
  44. ///
  45. /// Constructor/Desctructor
  46. explicit ctkAbstractObjectFactory();
  47. virtual ~ctkAbstractObjectFactory();
  48. //-----------------------------------------------------------------------------
  49. ///
  50. /// Register an object in the factory
  51. template<typename ClassType>
  52. bool registerObject(const QString& key);
  53. private:
  54. ctkAbstractObjectFactory(const ctkAbstractObjectFactory &); /// Not implemented
  55. void operator=(const ctkAbstractObjectFactory&); /// Not implemented
  56. };
  57. #include "ctkAbstractObjectFactory.tpp"
  58. #endif