ctkCmdLineModuleParameterGroup.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) 2010 Brigham and Women's Hospital (BWH) All Rights Reserved.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use d 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. #include "ctkCmdLineModuleParameterGroup.h"
  15. #include "ctkCmdLineModuleParameter.h"
  16. #include "ctkCmdLineModuleParameterGroup_p.h"
  17. #include "ctkException.h"
  18. #include <QTextStream>
  19. //----------------------------------------------------------------------------
  20. ctkCmdLineModuleParameterGroup::ctkCmdLineModuleParameterGroup()
  21. : d(new ctkCmdLineModuleParameterGroupPrivate())
  22. {
  23. }
  24. //----------------------------------------------------------------------------
  25. ctkCmdLineModuleParameterGroup::ctkCmdLineModuleParameterGroup(const ctkCmdLineModuleParameterGroup& other)
  26. : d(other.d)
  27. {
  28. }
  29. //----------------------------------------------------------------------------
  30. ctkCmdLineModuleParameterGroup::~ctkCmdLineModuleParameterGroup()
  31. {
  32. }
  33. //----------------------------------------------------------------------------
  34. ctkCmdLineModuleParameterGroup& ctkCmdLineModuleParameterGroup::operator=(const ctkCmdLineModuleParameterGroup& other)
  35. {
  36. d = other.d;
  37. return *this;
  38. }
  39. //----------------------------------------------------------------------------
  40. QString ctkCmdLineModuleParameterGroup::label() const
  41. {
  42. return d->Label;
  43. }
  44. //----------------------------------------------------------------------------
  45. QString ctkCmdLineModuleParameterGroup::description() const
  46. {
  47. return d->Description;
  48. }
  49. //----------------------------------------------------------------------------
  50. bool ctkCmdLineModuleParameterGroup::advanced() const
  51. {
  52. return d->Advanced;
  53. }
  54. //----------------------------------------------------------------------------
  55. QList<ctkCmdLineModuleParameter> ctkCmdLineModuleParameterGroup::parameters() const
  56. {
  57. return d->Parameters;
  58. }
  59. //----------------------------------------------------------------------------
  60. bool ctkCmdLineModuleParameterGroup::hasParameter(const QString& name) const
  61. {
  62. foreach(const ctkCmdLineModuleParameter param, d->Parameters)
  63. {
  64. if (param.name() == name) return true;
  65. }
  66. return false;
  67. }
  68. //----------------------------------------------------------------------------
  69. ctkCmdLineModuleParameter ctkCmdLineModuleParameterGroup::parameter(const QString& name) const
  70. {
  71. foreach(const ctkCmdLineModuleParameter param, d->Parameters)
  72. {
  73. if (param.name() == name) return param;
  74. }
  75. throw ctkInvalidArgumentException(QString("No parameter group named \"%1\" available.").arg(name));
  76. }
  77. //----------------------------------------------------------------------------
  78. bool ctkCmdLineModuleParameterGroup::hasReturnParameters() const
  79. {
  80. // iterate over each parameter in d group
  81. foreach(const ctkCmdLineModuleParameter param, d->Parameters)
  82. {
  83. if (param.isReturnParameter())
  84. {
  85. return true;
  86. }
  87. }
  88. return false;
  89. }
  90. //----------------------------------------------------------------------------
  91. QTextStream & operator<<(QTextStream &os, const ctkCmdLineModuleParameterGroup &group)
  92. {
  93. os << " Advanced: " << (group.advanced() ? "true" : "false") << '\n';
  94. os << " Label: " << group.label() << '\n';
  95. os << " Description: " << group.description() << '\n';
  96. os << " Parameters: " << '\n';
  97. foreach(const ctkCmdLineModuleParameter param, group.parameters())
  98. {
  99. os << param;
  100. }
  101. return os;
  102. }