ctkAbstractObjectFactory.tpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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_tpp
  15. #define __ctkAbstractObjectFactory_tpp
  16. // CTK includes
  17. #include "ctkAbstractObjectFactory.h"
  18. // QT includes
  19. #include <QDebug>
  20. //----------------------------------------------------------------------------
  21. // ctkFactoryObjectItem methods
  22. //----------------------------------------------------------------------------
  23. template<typename BaseClassType, typename ClassType>
  24. bool ctkFactoryObjectItem<BaseClassType,ClassType>::load()
  25. {
  26. this->instantiateObjectFunc = &instantiateObject<BaseClassType, ClassType>;
  27. return true;
  28. }
  29. //----------------------------------------------------------------------------
  30. template<typename BaseClassType, typename ClassType>
  31. BaseClassType* ctkFactoryObjectItem<BaseClassType,ClassType>::instanciator()
  32. {
  33. return this->instantiateObjectFunc();
  34. }
  35. //----------------------------------------------------------------------------
  36. // ctkAbstractObjectFactory methods
  37. //-----------------------------------------------------------------------------
  38. template<typename BaseClassType>
  39. ctkAbstractObjectFactory<BaseClassType>::ctkAbstractObjectFactory()
  40. :ctkAbstractFactory<BaseClassType>()
  41. {
  42. }
  43. //-----------------------------------------------------------------------------
  44. template<typename BaseClassType>
  45. template<typename ClassType>
  46. bool ctkAbstractObjectFactory<BaseClassType>::registerObject(const QString& key)
  47. {
  48. QString description = QString("Attempt to register \"%1\"").arg(key);
  49. if(this->sharedItem(key) || this->item(key))
  50. {
  51. this->displayRegistrationStatus(QtDebugMsg, description,
  52. "Already registered", this->verbose());
  53. return false;
  54. }
  55. QSharedPointer<ctkFactoryObjectItem<BaseClassType, ClassType> > objectItem =
  56. QSharedPointer<ctkFactoryObjectItem<BaseClassType, ClassType> >(
  57. new ctkFactoryObjectItem<BaseClassType, ClassType>() );
  58. objectItem->setVerbose(this->verbose());
  59. bool res = this->registerItem(key, objectItem);
  60. if(res)
  61. {
  62. this->displayRegistrationStatus(QtDebugMsg, description, "OK", this->verbose());
  63. }
  64. else
  65. {
  66. this->displayRegistrationStatus(QtWarningMsg, description, "Failed", this->verbose());
  67. }
  68. return res;
  69. }
  70. #endif