ctkCmdLineModuleParameter.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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), Index(-1), Multiple(false), Aggregate("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::cppType() const
  68. //{
  69. // Q_D(const ctkCmdLineModuleParameter);
  70. // return d->CPPType;
  71. //}
  72. //----------------------------------------------------------------------------
  73. QString ctkCmdLineModuleParameter::type() const
  74. {
  75. return d->Type;
  76. }
  77. //----------------------------------------------------------------------------
  78. QString ctkCmdLineModuleParameter::reference() const
  79. {
  80. return d->Reference;
  81. }
  82. //----------------------------------------------------------------------------
  83. bool ctkCmdLineModuleParameter::hidden() const
  84. {
  85. return d->Hidden;
  86. }
  87. //----------------------------------------------------------------------------
  88. bool ctkCmdLineModuleParameter::isReturnParameter() const
  89. {
  90. // could check for tag == float, int, float-vector, ...
  91. if (d->Channel == "output"
  92. && !this->isFlagParameter() && !this->isIndexParameter())
  93. {
  94. return true;
  95. }
  96. return false;
  97. }
  98. //----------------------------------------------------------------------------
  99. bool ctkCmdLineModuleParameter::isFlagParameter() const
  100. {
  101. return (d->Flag != "" || d->LongFlag != "");
  102. }
  103. //----------------------------------------------------------------------------
  104. bool ctkCmdLineModuleParameter::isIndexParameter() const
  105. {
  106. return (d->Index > -1);
  107. }
  108. //----------------------------------------------------------------------------
  109. QString ctkCmdLineModuleParameter::argType() const
  110. {
  111. return d->ArgType;
  112. }
  113. ////----------------------------------------------------------------------------
  114. //QString ctkCmdLineModuleParameter::stringToType() const
  115. //{
  116. // Q_D(const ctkCmdLineModuleParameter);
  117. // return d->StringToType;
  118. //}
  119. //----------------------------------------------------------------------------
  120. QString ctkCmdLineModuleParameter::name() const
  121. {
  122. return d->Name;
  123. }
  124. //----------------------------------------------------------------------------
  125. QString ctkCmdLineModuleParameter::longFlag() const
  126. {
  127. return d->LongFlag;
  128. }
  129. //----------------------------------------------------------------------------
  130. QString ctkCmdLineModuleParameter::longFlagAliasesAsString() const
  131. {
  132. return d->LongFlagAliasesAsString;
  133. }
  134. //----------------------------------------------------------------------------
  135. QStringList ctkCmdLineModuleParameter::longFlagAliases() const
  136. {
  137. return d->LongFlagAliases;
  138. }
  139. //----------------------------------------------------------------------------
  140. QString ctkCmdLineModuleParameter::deprecatedLongFlagAliasesAsString() const
  141. {
  142. return d->DeprecatedLongFlagAliasesAsString;
  143. }
  144. //----------------------------------------------------------------------------
  145. QStringList ctkCmdLineModuleParameter::deprecatedLongFlagAliases() const
  146. {
  147. return d->DeprecatedLongFlagAliases;
  148. }
  149. //----------------------------------------------------------------------------
  150. QString ctkCmdLineModuleParameter::label() const
  151. {
  152. return d->Label;
  153. }
  154. //----------------------------------------------------------------------------
  155. bool ctkCmdLineModuleParameter::constraints() const
  156. {
  157. return d->Constraints;
  158. }
  159. //----------------------------------------------------------------------------
  160. QString ctkCmdLineModuleParameter::maximum() const
  161. {
  162. return d->Maximum;
  163. }
  164. //----------------------------------------------------------------------------
  165. QString ctkCmdLineModuleParameter::minimum() const
  166. {
  167. return d->Minimum;
  168. }
  169. //----------------------------------------------------------------------------
  170. QString ctkCmdLineModuleParameter::step() const
  171. {
  172. return d->Step;
  173. }
  174. //----------------------------------------------------------------------------
  175. QString ctkCmdLineModuleParameter::description() const
  176. {
  177. return d->Description;
  178. }
  179. //----------------------------------------------------------------------------
  180. QString ctkCmdLineModuleParameter::channel() const
  181. {
  182. return d->Channel;
  183. }
  184. //----------------------------------------------------------------------------
  185. int ctkCmdLineModuleParameter::index() const
  186. {
  187. return d->Index;
  188. }
  189. //----------------------------------------------------------------------------
  190. QString ctkCmdLineModuleParameter::defaultValue() const
  191. {
  192. return d->Default;
  193. }
  194. //----------------------------------------------------------------------------
  195. QString ctkCmdLineModuleParameter::flag() const
  196. {
  197. return d->Flag;
  198. }
  199. //----------------------------------------------------------------------------
  200. QString ctkCmdLineModuleParameter::flagAliasesAsString() const
  201. {
  202. return d->FlagAliasesAsString;
  203. }
  204. //----------------------------------------------------------------------------
  205. QStringList ctkCmdLineModuleParameter::flagAliases() const
  206. {
  207. return d->FlagAliases;
  208. }
  209. //----------------------------------------------------------------------------
  210. QString ctkCmdLineModuleParameter::deprecatedFlagAliasesAsString() const
  211. {
  212. return d->DeprecatedFlagAliasesAsString;
  213. }
  214. //----------------------------------------------------------------------------
  215. QStringList ctkCmdLineModuleParameter::deprecatedFlagAliases() const
  216. {
  217. return d->DeprecatedFlagAliases;
  218. }
  219. //----------------------------------------------------------------------------
  220. bool ctkCmdLineModuleParameter::multiple() const
  221. {
  222. return d->Multiple;
  223. }
  224. //----------------------------------------------------------------------------
  225. QString ctkCmdLineModuleParameter::aggregate() const
  226. {
  227. return d->Aggregate;
  228. }
  229. //----------------------------------------------------------------------------
  230. QString ctkCmdLineModuleParameter::fileExtensionsAsString() const
  231. {
  232. return d->FileExtensionsAsString;
  233. }
  234. //----------------------------------------------------------------------------
  235. QStringList ctkCmdLineModuleParameter::fileExtensions() const
  236. {
  237. return d->FileExtensions;
  238. }
  239. //----------------------------------------------------------------------------
  240. QString ctkCmdLineModuleParameter::coordinateSystem() const
  241. {
  242. return d->CoordinateSystem;
  243. }
  244. //----------------------------------------------------------------------------
  245. QStringList ctkCmdLineModuleParameter::elements() const
  246. {
  247. return d->Elements;
  248. }
  249. //----------------------------------------------------------------------------
  250. //QStringList& ctkCmdLineModuleParameter::elements()
  251. //{
  252. // return d->Elements;
  253. //}
  254. //----------------------------------------------------------------------------
  255. QTextStream& operator<<(QTextStream& os, const ctkCmdLineModuleParameter& parameter)
  256. {
  257. os << " Parameter" << '\n';
  258. os << " " << "Tag: " << parameter.tag() << '\n';
  259. os << " " << "Name: " << parameter.name() << '\n';
  260. os << " " << "Description: " << parameter.description() << '\n';
  261. os << " " << "Label: " << parameter.label() << '\n';
  262. os << " " << "Type: " << parameter.type() << '\n';
  263. os << " " << "Reference: " << parameter.reference() << '\n';
  264. os << " " << "Hidden: " << (parameter.hidden() ? "true" : "false") << '\n';
  265. //os << " " << "CPPType: " << parameter.cppType() << '\n';
  266. os << " " << "ArgType: " << parameter.argType() << '\n';
  267. //os << " " << "StringToType: " << parameter.stringToType() << '\n';
  268. os << " " << "Default: " << parameter.defaultValue() << '\n';
  269. os << " " << "Elements: " << parameter.elements().join(", ") << '\n';
  270. os << " " << "Constraints: " << (parameter.constraints() ? "true" : "false") << '\n';
  271. os << " " << "Minimum: " << parameter.minimum() << '\n';
  272. os << " " << "Maximum: " << parameter.maximum() << '\n';
  273. os << " " << "Step: " << parameter.step() << '\n';
  274. os << " " << "Flag: " << parameter.flag() << '\n';
  275. os << " " << "Flag aliases: " << parameter.flagAliasesAsString() << '\n';
  276. os << " " << "Deprecated Flag aliases: " << parameter.deprecatedFlagAliasesAsString() << '\n';
  277. os << " " << "LongFlag: " << parameter.longFlag() << '\n';
  278. os << " " << "LongFlag aliases: " << parameter.longFlagAliasesAsString() << '\n';
  279. os << " " << "Deprecated LongFlag aliases: " << parameter.deprecatedLongFlagAliasesAsString() << '\n';
  280. os << " " << "Channel: " << parameter.channel() << '\n';
  281. os << " " << "Index: " << parameter.index() << '\n';
  282. os << " " << "Multiple: " << (parameter.multiple() ? "true" : "false") << '\n';
  283. os << " " << "Aggregate: " << parameter.aggregate() << '\n';
  284. os << " " << "FileExtensions: " << parameter.fileExtensionsAsString() << '\n';
  285. os << " " << "CoordinateSystem: " << parameter.coordinateSystem() << '\n';
  286. return os;
  287. }