ctkCmdLineModuleParameter.cpp 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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 "ctkCmdLineModuleParameter.h"
  15. #include "ctkCmdLineModuleParameter_p.h"
  16. #include <QStringList>
  17. #include <QTextStream>
  18. //----------------------------------------------------------------------------
  19. ctkCmdLineModuleParameterPrivate::ctkCmdLineModuleParameterPrivate()
  20. : Hidden(false), Constraints(false), Channel("input"), Index(-1), Multiple(false)
  21. {}
  22. //----------------------------------------------------------------------------
  23. QStringList ctkCmdLineModuleParameterPrivate::splitAndTrim(const QString& str, const QString& separator)
  24. {
  25. QStringList l = str.split(separator, QString::SkipEmptyParts);
  26. l.removeDuplicates();
  27. // trim the strings
  28. QMutableStringListIterator i(l);
  29. while(i.hasNext())
  30. {
  31. QString& n = i.next();
  32. n = n.trimmed();
  33. }
  34. return l;
  35. }
  36. //----------------------------------------------------------------------------
  37. void ctkCmdLineModuleParameterPrivate::setFileExtensionsAsString(const QString& extensions)
  38. {
  39. FileExtensions = splitAndTrim(extensions, ",");
  40. FileExtensionsAsString = FileExtensions.join(",");
  41. }
  42. //----------------------------------------------------------------------------
  43. ctkCmdLineModuleParameter::ctkCmdLineModuleParameter()
  44. : d(new ctkCmdLineModuleParameterPrivate())
  45. { }
  46. //----------------------------------------------------------------------------
  47. ctkCmdLineModuleParameter::~ctkCmdLineModuleParameter()
  48. {
  49. }
  50. //----------------------------------------------------------------------------
  51. ctkCmdLineModuleParameter::ctkCmdLineModuleParameter(const ctkCmdLineModuleParameter &other)
  52. : d(other.d)
  53. {
  54. }
  55. //----------------------------------------------------------------------------
  56. ctkCmdLineModuleParameter& ctkCmdLineModuleParameter::operator=(const ctkCmdLineModuleParameter& other)
  57. {
  58. d = other.d;
  59. return *this;
  60. }
  61. //----------------------------------------------------------------------------
  62. QString ctkCmdLineModuleParameter::tag() const
  63. {
  64. return d->Tag;
  65. }
  66. //----------------------------------------------------------------------------
  67. QString ctkCmdLineModuleParameter::type() const
  68. {
  69. return d->Type;
  70. }
  71. //----------------------------------------------------------------------------
  72. bool ctkCmdLineModuleParameter::hidden() const
  73. {
  74. return d->Hidden;
  75. }
  76. //----------------------------------------------------------------------------
  77. bool ctkCmdLineModuleParameter::isReturnParameter() const
  78. {
  79. if (d->Channel == "output" && this->isIndexParameter() &&
  80. this->index() == 1000)
  81. {
  82. return true;
  83. }
  84. return false;
  85. }
  86. //----------------------------------------------------------------------------
  87. bool ctkCmdLineModuleParameter::isFlagParameter() const
  88. {
  89. return (d->Flag != "" || d->LongFlag != "");
  90. }
  91. //----------------------------------------------------------------------------
  92. bool ctkCmdLineModuleParameter::isIndexParameter() const
  93. {
  94. return (d->Index > -1);
  95. }
  96. //----------------------------------------------------------------------------
  97. QString ctkCmdLineModuleParameter::name() const
  98. {
  99. return d->Name;
  100. }
  101. //----------------------------------------------------------------------------
  102. QString ctkCmdLineModuleParameter::longFlag() const
  103. {
  104. return d->LongFlag;
  105. }
  106. //----------------------------------------------------------------------------
  107. QString ctkCmdLineModuleParameter::longFlagAliasesAsString() const
  108. {
  109. return d->LongFlagAliasesAsString;
  110. }
  111. //----------------------------------------------------------------------------
  112. QStringList ctkCmdLineModuleParameter::longFlagAliases() const
  113. {
  114. return d->LongFlagAliases;
  115. }
  116. //----------------------------------------------------------------------------
  117. QString ctkCmdLineModuleParameter::deprecatedLongFlagAliasesAsString() const
  118. {
  119. return d->DeprecatedLongFlagAliasesAsString;
  120. }
  121. //----------------------------------------------------------------------------
  122. QStringList ctkCmdLineModuleParameter::deprecatedLongFlagAliases() const
  123. {
  124. return d->DeprecatedLongFlagAliases;
  125. }
  126. //----------------------------------------------------------------------------
  127. QString ctkCmdLineModuleParameter::label() const
  128. {
  129. return d->Label;
  130. }
  131. //----------------------------------------------------------------------------
  132. bool ctkCmdLineModuleParameter::constraints() const
  133. {
  134. return d->Constraints;
  135. }
  136. //----------------------------------------------------------------------------
  137. QString ctkCmdLineModuleParameter::maximum() const
  138. {
  139. return d->Maximum;
  140. }
  141. //----------------------------------------------------------------------------
  142. QString ctkCmdLineModuleParameter::minimum() const
  143. {
  144. return d->Minimum;
  145. }
  146. //----------------------------------------------------------------------------
  147. QString ctkCmdLineModuleParameter::step() const
  148. {
  149. return d->Step;
  150. }
  151. //----------------------------------------------------------------------------
  152. QString ctkCmdLineModuleParameter::description() const
  153. {
  154. return d->Description;
  155. }
  156. //----------------------------------------------------------------------------
  157. QString ctkCmdLineModuleParameter::channel() const
  158. {
  159. return d->Channel;
  160. }
  161. //----------------------------------------------------------------------------
  162. int ctkCmdLineModuleParameter::index() const
  163. {
  164. return d->Index;
  165. }
  166. //----------------------------------------------------------------------------
  167. QString ctkCmdLineModuleParameter::defaultValue() const
  168. {
  169. return d->Default;
  170. }
  171. //----------------------------------------------------------------------------
  172. QString ctkCmdLineModuleParameter::flag() const
  173. {
  174. return d->Flag;
  175. }
  176. //----------------------------------------------------------------------------
  177. QString ctkCmdLineModuleParameter::flagAliasesAsString() const
  178. {
  179. return d->FlagAliasesAsString;
  180. }
  181. //----------------------------------------------------------------------------
  182. QStringList ctkCmdLineModuleParameter::flagAliases() const
  183. {
  184. return d->FlagAliases;
  185. }
  186. //----------------------------------------------------------------------------
  187. QString ctkCmdLineModuleParameter::deprecatedFlagAliasesAsString() const
  188. {
  189. return d->DeprecatedFlagAliasesAsString;
  190. }
  191. //----------------------------------------------------------------------------
  192. QStringList ctkCmdLineModuleParameter::deprecatedFlagAliases() const
  193. {
  194. return d->DeprecatedFlagAliases;
  195. }
  196. //----------------------------------------------------------------------------
  197. bool ctkCmdLineModuleParameter::multiple() const
  198. {
  199. return d->Multiple;
  200. }
  201. //----------------------------------------------------------------------------
  202. QString ctkCmdLineModuleParameter::fileExtensionsAsString() const
  203. {
  204. return d->FileExtensionsAsString;
  205. }
  206. //----------------------------------------------------------------------------
  207. QStringList ctkCmdLineModuleParameter::fileExtensions() const
  208. {
  209. return d->FileExtensions;
  210. }
  211. //----------------------------------------------------------------------------
  212. QString ctkCmdLineModuleParameter::coordinateSystem() const
  213. {
  214. return d->CoordinateSystem;
  215. }
  216. //----------------------------------------------------------------------------
  217. QStringList ctkCmdLineModuleParameter::elements() const
  218. {
  219. return d->Elements;
  220. }
  221. //----------------------------------------------------------------------------
  222. QTextStream& operator<<(QTextStream& os, const ctkCmdLineModuleParameter& parameter)
  223. {
  224. os << " Parameter" << '\n';
  225. os << " " << "Tag: " << parameter.tag() << '\n';
  226. os << " " << "Name: " << parameter.name() << '\n';
  227. os << " " << "Description: " << parameter.description() << '\n';
  228. os << " " << "Label: " << parameter.label() << '\n';
  229. os << " " << "Type: " << parameter.type() << '\n';
  230. os << " " << "Hidden: " << (parameter.hidden() ? "true" : "false") << '\n';
  231. os << " " << "Default: " << parameter.defaultValue() << '\n';
  232. os << " " << "Elements: " << parameter.elements().join(", ") << '\n';
  233. os << " " << "Constraints: " << (parameter.constraints() ? "true" : "false") << '\n';
  234. os << " " << "Minimum: " << parameter.minimum() << '\n';
  235. os << " " << "Maximum: " << parameter.maximum() << '\n';
  236. os << " " << "Step: " << parameter.step() << '\n';
  237. os << " " << "Flag: " << parameter.flag() << '\n';
  238. os << " " << "Flag aliases: " << parameter.flagAliasesAsString() << '\n';
  239. os << " " << "Deprecated Flag aliases: " << parameter.deprecatedFlagAliasesAsString() << '\n';
  240. os << " " << "LongFlag: " << parameter.longFlag() << '\n';
  241. os << " " << "LongFlag aliases: " << parameter.longFlagAliasesAsString() << '\n';
  242. os << " " << "Deprecated LongFlag aliases: " << parameter.deprecatedLongFlagAliasesAsString() << '\n';
  243. os << " " << "Channel: " << parameter.channel() << '\n';
  244. os << " " << "Index: " << parameter.index() << '\n';
  245. os << " " << "Multiple: " << (parameter.multiple() ? "true" : "false") << '\n';
  246. os << " " << "FileExtensions: " << parameter.fileExtensionsAsString() << '\n';
  247. os << " " << "CoordinateSystem: " << parameter.coordinateSystem() << '\n';
  248. return os;
  249. }