ctkAbstractObjectFactory.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 __ctkAbstractObjectFactory_h
  15. #define __ctkAbstractObjectFactory_h
  16. // Qt includes
  17. #include <QDebug>
  18. // CTK includes
  19. #include "ctkAbstractFactory.h"
  20. //----------------------------------------------------------------------------
  21. namespace{
  22. /// \ingroup Core
  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. /// \ingroup Core
  32. template<typename BaseClassType, typename ClassType>
  33. class ctkFactoryObjectItem : public ctkAbstractFactoryItem<BaseClassType>
  34. {
  35. protected:
  36. typedef BaseClassType *(*InstantiateObjectFunc)();
  37. public:
  38. virtual bool load();
  39. protected:
  40. virtual BaseClassType* instanciator();
  41. private:
  42. InstantiateObjectFunc instantiateObjectFunc;
  43. };
  44. //----------------------------------------------------------------------------
  45. /// \ingroup Core
  46. template<typename BaseClassType>
  47. class ctkAbstractObjectFactory : public ctkAbstractFactory<BaseClassType>
  48. {
  49. public:
  50. explicit ctkAbstractObjectFactory();
  51. /// Register an object in the factory
  52. template<typename ClassType>
  53. bool registerObject(const QString& key);
  54. private:
  55. ctkAbstractObjectFactory(const ctkAbstractObjectFactory &); /// Not implemented
  56. void operator=(const ctkAbstractObjectFactory&); /// Not implemented
  57. };
  58. #include "ctkAbstractObjectFactory.tpp"
  59. #endif