ctkCmdLineModuleReference.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. #include "ctkCmdLineModuleReference.h"
  16. #include "ctkCmdLineModuleReference_p.h"
  17. #include "ctkCmdLineModuleXmlParser_p.h"
  18. #include "ctkCmdLineModuleXmlException.h"
  19. #include <QBuffer>
  20. //----------------------------------------------------------------------------
  21. ctkCmdLineModuleReferencePrivate::ctkCmdLineModuleReferencePrivate()
  22. : Backend(NULL), XmlException(NULL)
  23. {
  24. }
  25. //----------------------------------------------------------------------------
  26. ctkCmdLineModuleReferencePrivate::~ctkCmdLineModuleReferencePrivate()
  27. {
  28. delete XmlException;
  29. }
  30. //----------------------------------------------------------------------------
  31. ctkCmdLineModuleDescription ctkCmdLineModuleReferencePrivate::description() const
  32. {
  33. // If we already got an XML exception just throw it immediately, since
  34. // the XML description cannot change for this module reference.
  35. if (XmlException)
  36. {
  37. throw *XmlException;
  38. }
  39. // Lazy creation. The title is a required XML element.
  40. if (Description.title().isNull())
  41. {
  42. QByteArray xml(RawXmlDescription);
  43. QBuffer xmlInput(&xml);
  44. ctkCmdLineModuleXmlParser parser(&xmlInput, &Description);
  45. try
  46. {
  47. parser.doParse();
  48. }
  49. catch (const ctkCmdLineModuleXmlException& e)
  50. {
  51. XmlException = e.clone();
  52. }
  53. }
  54. return Description;
  55. }
  56. //----------------------------------------------------------------------------
  57. ctkCmdLineModuleReference::ctkCmdLineModuleReference()
  58. : d(new ctkCmdLineModuleReferencePrivate())
  59. {}
  60. //----------------------------------------------------------------------------
  61. ctkCmdLineModuleReference::~ctkCmdLineModuleReference()
  62. {
  63. }
  64. //----------------------------------------------------------------------------
  65. ctkCmdLineModuleReference::ctkCmdLineModuleReference(const ctkCmdLineModuleReference &ref)
  66. : d(ref.d)
  67. {
  68. }
  69. //----------------------------------------------------------------------------
  70. ctkCmdLineModuleReference &ctkCmdLineModuleReference::operator =(const ctkCmdLineModuleReference &ref)
  71. {
  72. d = ref.d;
  73. return *this;
  74. }
  75. //----------------------------------------------------------------------------
  76. ctkCmdLineModuleReference::operator bool() const
  77. {
  78. return !d->RawXmlDescription.isEmpty();
  79. }
  80. //----------------------------------------------------------------------------
  81. ctkCmdLineModuleDescription ctkCmdLineModuleReference::description() const
  82. {
  83. return d->description();
  84. }
  85. //----------------------------------------------------------------------------
  86. QByteArray ctkCmdLineModuleReference::rawXmlDescription() const
  87. {
  88. return d->RawXmlDescription;
  89. }
  90. //----------------------------------------------------------------------------
  91. QString ctkCmdLineModuleReference::xmlValidationErrorString() const
  92. {
  93. return d->XmlValidationErrorString;
  94. }
  95. //----------------------------------------------------------------------------
  96. QUrl ctkCmdLineModuleReference::location() const
  97. {
  98. return d->Location;
  99. }
  100. //----------------------------------------------------------------------------
  101. ctkCmdLineModuleBackend *ctkCmdLineModuleReference::backend() const
  102. {
  103. return d->Backend;
  104. }
  105. //----------------------------------------------------------------------------
  106. uint qHash(const ctkCmdLineModuleReference& moduleRef)
  107. {
  108. return qHash(moduleRef.d.data());
  109. }