ctkAbstractObjectFactory.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) 2010 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
  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 __ctkAbstractObjectFactory_h
  15. #define __ctkAbstractObjectFactory_h
  16. // Qt includes
  17. #include <QDebug>
  18. // CTK includes
  19. #include "ctkAbstractFactory.h"
  20. //----------------------------------------------------------------------------
  21. namespace{
  22. ///
  23. /// Function in charge of instanciating an object of type: ClassType
  24. template<typename BaseClassType, typename ClassType>
  25. BaseClassType *instantiateObject()
  26. {
  27. return new ClassType;
  28. }
  29. }
  30. //----------------------------------------------------------------------------
  31. template<typename BaseClassType, typename ClassType>
  32. class ctkFactoryObjectItem : public ctkAbstractFactoryItem<BaseClassType>
  33. {
  34. protected:
  35. typedef BaseClassType *(*InstantiateObjectFunc)();
  36. public:
  37. explicit ctkFactoryObjectItem(const QString& key);
  38. virtual bool load();
  39. protected:
  40. virtual BaseClassType* instanciator();
  41. private:
  42. InstantiateObjectFunc instantiateObjectFunc;
  43. };
  44. //----------------------------------------------------------------------------
  45. template<typename BaseClassType>
  46. class ctkAbstractObjectFactory : public ctkAbstractFactory<BaseClassType>
  47. {
  48. public:
  49. ///
  50. /// Constructor/Desctructor
  51. explicit ctkAbstractObjectFactory();
  52. virtual ~ctkAbstractObjectFactory();
  53. ///
  54. /// Register an object in the factory
  55. template<typename ClassType>
  56. bool registerObject(const QString& key);
  57. private:
  58. ctkAbstractObjectFactory(const ctkAbstractObjectFactory &); /// Not implemented
  59. void operator=(const ctkAbstractObjectFactory&); /// Not implemented
  60. };
  61. #include "ctkAbstractObjectFactory.tpp"
  62. #endif