ctkModuleDescriptionReader.cpp 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853
  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 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
  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. // Qt includes
  15. #include <QDebug>
  16. #include <QXmlSchema>
  17. #include <QXmlSchemaValidator>
  18. #include <QAbstractMessageHandler>
  19. #include <QXmlStreamReader>
  20. // CTK includes
  21. #include "ctkModuleDescription.h"
  22. // STD includes
  23. #include <stdexcept>
  24. class ctkModuleDescriptionParser
  25. {
  26. public:
  27. ctkModuleDescriptionParser(QIODevice* device, ctkModuleDescription* md);
  28. void validate();
  29. void doParse();
  30. void handleExecutableElement();
  31. void handleParametersElement();
  32. void handleParameterElement();
  33. private:
  34. QIODevice* const _device;
  35. ctkModuleDescription* _md;
  36. QXmlStreamReader _xmlReader;
  37. };
  38. namespace {
  39. static const QString EXECUTABLE = "executable";
  40. }
  41. // ----------------------------------------------------------------------------
  42. ctkModuleDescriptionParser::ctkModuleDescriptionParser(QIODevice* device,
  43. ctkModuleDescription* md)
  44. : _device(device), _md(md)
  45. {}
  46. // ----------------------------------------------------------------------------
  47. void ctkModuleDescriptionParser::validate()
  48. {
  49. class _MessageHandler : public QAbstractMessageHandler
  50. {
  51. public:
  52. QString statusMessage() const { return m_description; }
  53. int line() const { return m_sourceLocation.line(); }
  54. int column() const { return m_sourceLocation.column(); }
  55. protected:
  56. virtual void handleMessage(QtMsgType type, const QString& description,
  57. const QUrl& identifier, const QSourceLocation& sourceLocation)
  58. {
  59. Q_UNUSED(identifier)
  60. m_messageType = type;
  61. m_sourceLocation = sourceLocation;
  62. QXmlStreamReader reader(description);
  63. m_description.clear();
  64. m_description.reserve(description.size());
  65. while(!reader.atEnd())
  66. {
  67. reader.readNext();
  68. switch(reader.tokenType())
  69. {
  70. case QXmlStreamReader::Characters:
  71. {
  72. m_description.append(reader.text().toString());
  73. continue;
  74. }
  75. case QXmlStreamReader::StartElement:
  76. /* Fallthrough, */
  77. case QXmlStreamReader::EndElement:
  78. /* Fallthrough, */
  79. case QXmlStreamReader::StartDocument:
  80. /* Fallthrough, */
  81. case QXmlStreamReader::EndDocument:
  82. continue;
  83. default:
  84. Q_ASSERT_X(false, Q_FUNC_INFO,
  85. "Unexpected node.");
  86. }
  87. }
  88. }
  89. private:
  90. QtMsgType m_messageType;
  91. QString m_description;
  92. QSourceLocation m_sourceLocation;
  93. };
  94. _MessageHandler errorHandler;
  95. QXmlSchema schema;
  96. schema.setMessageHandler(&errorHandler);
  97. schema.load(QUrl::fromLocalFile(":ctkModuleDescription.xsd"));
  98. bool res = schema.isValid();
  99. if (!res)
  100. {
  101. throw std::runtime_error(std::string("Invalid Schema ") +
  102. errorHandler.statusMessage().toStdString());
  103. }
  104. QXmlSchemaValidator validator(schema);
  105. _device->open(QIODevice::ReadOnly);
  106. res = validator.validate(_device);
  107. _device->close();
  108. if (!res)
  109. {
  110. QString msg("Error validating XML description, at line %1, column %2: %3");
  111. throw std::runtime_error(msg.arg(errorHandler.line())
  112. .arg(errorHandler.column())
  113. .arg(errorHandler.statusMessage()).toStdString());
  114. }
  115. }
  116. // ----------------------------------------------------------------------------
  117. void ctkModuleDescriptionParser::doParse()
  118. {
  119. _xmlReader.clear();
  120. _xmlReader.setDevice(_device);
  121. while(!_xmlReader.hasError() && _xmlReader.readNextStartElement())
  122. {
  123. QStringRef name = _xmlReader.name();
  124. if (name.compare(EXECUTABLE, Qt::CaseInsensitive) == 0)
  125. {
  126. this->handleExecutableElement();
  127. }
  128. }
  129. if (_xmlReader.hasError() &&
  130. !(_xmlReader.atEnd() && _xmlReader.error() == QXmlStreamReader::PrematureEndOfDocumentError))
  131. {
  132. throw std::runtime_error(std::string("Error parsing XML description: ") +
  133. _xmlReader.errorString().toStdString());
  134. }
  135. }
  136. // ----------------------------------------------------------------------------
  137. void ctkModuleDescriptionParser::handleExecutableElement()
  138. {
  139. }
  140. // ----------------------------------------------------------------------------
  141. void ctkModuleDescriptionParser::handleParametersElement()
  142. {
  143. }
  144. // ----------------------------------------------------------------------------
  145. void ctkModuleDescriptionParser::handleParameterElement()
  146. {
  147. }
  148. // ===============================================================================
  149. void slicerParser()
  150. {
  151. if (name == "parameters")
  152. {
  153. group = new ModuleParameterGroup;
  154. int attrCount = XML_GetSpecifiedAttributeCount(ps->Parser);
  155. if (attrCount == 2 && (strcmp(attrs[0], "advanced") == 0))
  156. {
  157. group->SetAdvanced(attrs[1]);
  158. }
  159. }
  160. else if (name == "integer")
  161. {
  162. parameter = new ModuleParameter;
  163. parameter->SetTag(name);
  164. int attrCount = XML_GetSpecifiedAttributeCount(ps->Parser);
  165. if (attrCount == 2 &&
  166. (strcmp(attrs[0], "multiple") == 0) &&
  167. (strcmp(attrs[1], "true") == 0))
  168. {
  169. parameter->SetMultiple(attrs[1]);
  170. parameter->SetCPPType("std::vector<int>");
  171. parameter->SetArgType("int");
  172. parameter->SetStringToType("atoi"); }
  173. else
  174. {
  175. parameter->SetCPPType("int");
  176. }
  177. }
  178. else if (name == "float")
  179. {
  180. parameter = new ModuleParameter;
  181. int attrCount = XML_GetSpecifiedAttributeCount(ps->Parser);
  182. if (attrCount == 2 &&
  183. (strcmp(attrs[0], "multiple") == 0) &&
  184. (strcmp(attrs[1], "true") == 0))
  185. {
  186. parameter->SetMultiple(attrs[1]);
  187. parameter->SetCPPType("std::vector<float>");
  188. parameter->SetArgType("float");
  189. parameter->SetStringToType("atof");
  190. }
  191. else
  192. {
  193. parameter->SetCPPType("float");
  194. }
  195. parameter->SetTag(name);
  196. }
  197. else if (name == "double")
  198. {
  199. parameter = new ModuleParameter;
  200. int attrCount = XML_GetSpecifiedAttributeCount(ps->Parser);
  201. if (attrCount == 2 &&
  202. (strcmp(attrs[0], "multiple") == 0) &&
  203. (strcmp(attrs[1], "true") == 0))
  204. {
  205. parameter->SetMultiple(attrs[1]);
  206. parameter->SetCPPType("std::vector<double>");
  207. parameter->SetArgType("double");
  208. parameter->SetStringToType("atof");
  209. }
  210. else
  211. {
  212. parameter->SetCPPType("double");
  213. }
  214. parameter->SetTag(name);
  215. }
  216. else if (name == "string")
  217. {
  218. parameter = new ModuleParameter;
  219. int attrCount = XML_GetSpecifiedAttributeCount(ps->Parser);
  220. if (attrCount == 2 &&
  221. (strcmp(attrs[0], "multiple") == 0) &&
  222. (strcmp(attrs[1], "true") == 0))
  223. {
  224. parameter->SetMultiple(attrs[1]);
  225. parameter->SetCPPType("std::vector<std::string>");
  226. parameter->SetArgType("std::string");
  227. parameter->SetStringToType(""); }
  228. else
  229. {
  230. parameter->SetCPPType("std::string");
  231. }
  232. parameter->SetTag(name);
  233. }
  234. else if (name == "boolean")
  235. {
  236. parameter = new ModuleParameter;
  237. parameter->SetTag(name);
  238. parameter->SetCPPType("bool");
  239. // Parse attribute pairs
  240. int attrCount = XML_GetSpecifiedAttributeCount(ps->Parser);
  241. for (int attr=0; attr < (attrCount / 2); attr++)
  242. {
  243. if ((strcmp(attrs[2*attr], "hidden") == 0))
  244. {
  245. if ((strcmp(attrs[2*attr+1], "true") == 0) ||
  246. (strcmp(attrs[2*attr+1], "false") == 0))
  247. {
  248. parameter->SetHidden(attrs[2*attr+1]);
  249. }
  250. else
  251. {
  252. std::string error("ModuleDescriptionParser Error: \"" + std::string(attrs[2*attr+1]) + "\" is not a valid argument for the attribute \"hidden\". Only \"true\" and \"false\" are accepted.");
  253. if (ps->ErrorDescription.size() == 0)
  254. {
  255. ps->ErrorDescription = error;
  256. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  257. ps->Error = true;
  258. }
  259. ps->OpenTags.push(name);
  260. delete parameter;
  261. return;
  262. }
  263. }
  264. }
  265. }
  266. else if (name == "integer-vector")
  267. {
  268. parameter = new ModuleParameter;
  269. parameter->SetTag(name);
  270. parameter->SetCPPType("std::vector<int>");
  271. parameter->SetArgType("int");
  272. parameter->SetStringToType("atoi");
  273. }
  274. else if (name == "float-vector")
  275. {
  276. parameter = new ModuleParameter;
  277. parameter->SetTag(name);
  278. parameter->SetCPPType("std::vector<float>");
  279. parameter->SetArgType("float");
  280. parameter->SetStringToType("atof");
  281. }
  282. else if (name == "string-vector")
  283. {
  284. parameter = new ModuleParameter;
  285. parameter->SetTag(name);
  286. parameter->SetCPPType("std::vector<std::string>");
  287. parameter->SetArgType("std::string");
  288. parameter->SetStringToType("");
  289. }
  290. else if (name == "double-vector")
  291. {
  292. parameter = new ModuleParameter;
  293. parameter->SetTag(name);
  294. parameter->SetCPPType("std::vector<double>");
  295. parameter->SetArgType("double");
  296. parameter->SetStringToType("atof");
  297. }
  298. else if (name == "point")
  299. {
  300. parameter = new ModuleParameter;
  301. int attrCount = XML_GetSpecifiedAttributeCount(ps->Parser);
  302. // Parse attribute pairs
  303. for (int attr=0; attr < (attrCount / 2); attr++)
  304. {
  305. if ((strcmp(attrs[2*attr], "multiple") == 0))
  306. {
  307. if ((strcmp(attrs[2*attr+1], "true") == 0) ||
  308. (strcmp(attrs[2*attr+1], "false") == 0))
  309. {
  310. parameter->SetMultiple(attrs[2*attr+1]);
  311. parameter->SetCPPType("std::vector<std::vector<float> >");
  312. parameter->SetArgType("float");
  313. parameter->SetStringToType("atof");
  314. }
  315. else
  316. {
  317. std::string error("ModuleDescriptionParser Error: \"" + std::string(attrs[2*attr+1]) + "\" is not a valid argument for the attribute \"multiple\". Only \"true\" and \"false\" are accepted.");
  318. if (ps->ErrorDescription.size() == 0)
  319. {
  320. ps->ErrorDescription = error;
  321. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  322. ps->Error = true;
  323. }
  324. ps->OpenTags.push(name);
  325. delete parameter;
  326. return;
  327. }
  328. }
  329. else if ((strcmp(attrs[2*attr], "coordinateSystem") == 0))
  330. {
  331. if ((strcmp(attrs[2*attr+1], "ijk") == 0) ||
  332. (strcmp(attrs[2*attr+1], "lps") == 0) ||
  333. (strcmp(attrs[2*attr+1], "ras") == 0))
  334. {
  335. parameter->SetCoordinateSystem(attrs[2*attr+1]);
  336. }
  337. else
  338. {
  339. std::string error("ModuleDescriptionParser Error: \"" + std::string(attrs[2*attr+1]) + "\" is not a valid coordinate system. Only \"ijk\", \"lps\" and \"ras\" are accepted.");
  340. if (ps->ErrorDescription.size() == 0)
  341. {
  342. ps->ErrorDescription = error;
  343. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  344. ps->Error = true;
  345. }
  346. ps->OpenTags.push(name);
  347. delete parameter;
  348. return;
  349. }
  350. }
  351. else
  352. {
  353. std::string error("ModuleDescriptionParser Error: " + std::string(attrs[2*attr]) + " is not a valid attribute for the tag" + name);
  354. if (ps->ErrorDescription.size() == 0)
  355. {
  356. ps->ErrorDescription = error;
  357. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  358. ps->Error = true;
  359. }
  360. ps->OpenTags.push(name);
  361. delete parameter;
  362. return;
  363. }
  364. }
  365. if (parameter->GetMultiple() != "true")
  366. {
  367. parameter->SetCPPType("std::vector<float>");
  368. parameter->SetArgType("float");
  369. parameter->SetStringToType("atof");
  370. }
  371. parameter->SetTag(name);
  372. }
  373. else if (name == "region")
  374. {
  375. parameter = new ModuleParameter;
  376. int attrCount = XML_GetSpecifiedAttributeCount(ps->Parser);
  377. // Parse attribute pairs
  378. for (int attr=0; attr < (attrCount / 2); attr++)
  379. {
  380. if ((strcmp(attrs[2*attr], "multiple") == 0))
  381. {
  382. if ((strcmp(attrs[2*attr+1], "true") == 0) ||
  383. (strcmp(attrs[2*attr+1], "false") == 0))
  384. {
  385. parameter->SetMultiple(attrs[2*attr+1]);
  386. parameter->SetCPPType("std::vector<std::vector<float> >");
  387. parameter->SetArgType("float");
  388. parameter->SetStringToType("atof");
  389. }
  390. else
  391. {
  392. std::string error("ModuleDescriptionParser Error: \"" + std::string(attrs[2*attr+1]) + "\" is not a valid argument for the attribute \"multiple\". Only \"true\" and \"false\" are accepted.");
  393. if (ps->ErrorDescription.size() == 0)
  394. {
  395. ps->ErrorDescription = error;
  396. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  397. ps->Error = true;
  398. }
  399. ps->OpenTags.push(name);
  400. delete parameter;
  401. return;
  402. }
  403. }
  404. else if ((strcmp(attrs[2*attr], "coordinateSystem") == 0))
  405. {
  406. if ((strcmp(attrs[2*attr+1], "ijk") == 0) ||
  407. (strcmp(attrs[2*attr+1], "lps") == 0) ||
  408. (strcmp(attrs[2*attr+1], "ras") == 0))
  409. {
  410. parameter->SetCoordinateSystem(attrs[2*attr+1]);
  411. }
  412. else
  413. {
  414. std::string error("ModuleDescriptionParser Error: \"" + std::string(attrs[2*attr+1]) + "\" is not a valid coordinate system. Only \"ijk\", \"lps\" and \"ras\" are accepted.");
  415. if (ps->ErrorDescription.size() == 0)
  416. {
  417. ps->ErrorDescription = error;
  418. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  419. ps->Error = true;
  420. }
  421. ps->OpenTags.push(name);
  422. delete parameter;
  423. return;
  424. }
  425. }
  426. else
  427. {
  428. std::string error("ModuleDescriptionParser Error: " + std::string(attrs[2*attr]) + " is not a valid attribute for the tag" + name);
  429. if (ps->ErrorDescription.size() == 0)
  430. {
  431. ps->ErrorDescription = error;
  432. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  433. ps->Error = true;
  434. }
  435. ps->OpenTags.push(name);
  436. delete parameter;
  437. return;
  438. }
  439. }
  440. if (parameter->GetMultiple() != "true")
  441. {
  442. parameter->SetCPPType("std::vector<float>");
  443. parameter->SetArgType("float");
  444. parameter->SetStringToType("atof");
  445. }
  446. parameter->SetTag(name);
  447. }
  448. else if (name == "string-enumeration")
  449. {
  450. parameter = new ModuleParameter;
  451. parameter->SetTag(name);
  452. parameter->SetCPPType("std::string");
  453. // Parse attribute pairs
  454. int attrCount = XML_GetSpecifiedAttributeCount(ps->Parser);
  455. for (int attr=0; attr < (attrCount / 2); attr++)
  456. {
  457. bool res = true;
  458. if ((strcmp(attrs[2*attr], "hidden") == 0))
  459. {
  460. res = ModuleDescriptionParser::processHiddenAttribute(attrs[2*attr+1], parameter, ps);
  461. }
  462. if (!res)
  463. {
  464. ps->OpenTags.push(name);
  465. delete parameter;
  466. return;
  467. }
  468. }
  469. }
  470. else if (name == "integer-enumeration")
  471. {
  472. if (!group || (ps->OpenTags.top() != "parameters"))
  473. {
  474. std::string error("ModuleDescriptionParser Error: <" + name + "> can only be used inside <parameters> but was found inside <" + ps->OpenTags.top() + ">");
  475. if (ps->ErrorDescription.size() == 0)
  476. {
  477. ps->ErrorDescription = error;
  478. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  479. ps->Error = true;
  480. }
  481. ps->OpenTags.push(name);
  482. delete parameter;
  483. return;
  484. }
  485. parameter = new ModuleParameter;
  486. parameter->SetTag(name);
  487. parameter->SetCPPType("int");
  488. // Parse attribute pairs
  489. int attrCount = XML_GetSpecifiedAttributeCount(ps->Parser);
  490. for (int attr=0; attr < (attrCount / 2); attr++)
  491. {
  492. bool res = true;
  493. if ((strcmp(attrs[2*attr], "hidden") == 0))
  494. {
  495. res = ModuleDescriptionParser::processHiddenAttribute(attrs[2*attr+1], parameter, ps);
  496. }
  497. if (!res)
  498. {
  499. ps->OpenTags.push(name);
  500. delete parameter;
  501. return;
  502. }
  503. }
  504. }
  505. else if (name == "float-enumeration")
  506. {
  507. if (!group || (ps->OpenTags.top() != "parameters"))
  508. {
  509. std::string error("ModuleDescriptionParser Error: <" + name + "> can only be used inside <parameters> but was found inside <" + ps->OpenTags.top() + ">");
  510. if (ps->ErrorDescription.size() == 0)
  511. {
  512. ps->ErrorDescription = error;
  513. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  514. ps->Error = true;
  515. }
  516. ps->OpenTags.push(name);
  517. delete parameter;
  518. return;
  519. }
  520. parameter = new ModuleParameter;
  521. parameter->SetTag(name);
  522. parameter->SetCPPType("float");
  523. // Parse attribute pairs
  524. int attrCount = XML_GetSpecifiedAttributeCount(ps->Parser);
  525. for (int attr=0; attr < (attrCount / 2); attr++)
  526. {
  527. bool res = true;
  528. if ((strcmp(attrs[2*attr], "hidden") == 0))
  529. {
  530. res = ModuleDescriptionParser::processHiddenAttribute(attrs[2*attr+1], parameter, ps);
  531. }
  532. if (!res)
  533. {
  534. ps->OpenTags.push(name);
  535. delete parameter;
  536. return;
  537. }
  538. }
  539. }
  540. else if (name == "double-enumeration")
  541. {
  542. if (!group || (ps->OpenTags.top() != "parameters"))
  543. {
  544. std::string error("ModuleDescriptionParser Error: <" + name + "> can only be used inside <parameters> but was found inside <" + ps->OpenTags.top() + ">");
  545. if (ps->ErrorDescription.size() == 0)
  546. {
  547. ps->ErrorDescription = error;
  548. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  549. ps->Error = true;
  550. }
  551. ps->OpenTags.push(name);
  552. delete parameter;
  553. return;
  554. }
  555. parameter = new ModuleParameter;
  556. parameter->SetTag(name);
  557. parameter->SetCPPType("double");
  558. // Parse attribute pairs
  559. int attrCount = XML_GetSpecifiedAttributeCount(ps->Parser);
  560. for (int attr=0; attr < (attrCount / 2); attr++)
  561. {
  562. bool res = true;
  563. if ((strcmp(attrs[2*attr], "hidden") == 0))
  564. {
  565. res = ModuleDescriptionParser::processHiddenAttribute(attrs[2*attr+1], parameter, ps);
  566. }
  567. if (!res)
  568. {
  569. ps->OpenTags.push(name);
  570. delete parameter;
  571. return;
  572. }
  573. }
  574. }
  575. else if (name == "file")
  576. {
  577. if (!group || (ps->OpenTags.top() != "parameters"))
  578. {
  579. std::string error("ModuleDescriptionParser Error: <" + name + "> can only be used inside <parameters> but was found inside <" + ps->OpenTags.top() + ">");
  580. if (ps->ErrorDescription.size() == 0)
  581. {
  582. ps->ErrorDescription = error;
  583. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  584. ps->Error = true;
  585. }
  586. delete parameter;
  587. return;
  588. }
  589. parameter = new ModuleParameter;
  590. int attrCount = XML_GetSpecifiedAttributeCount(ps->Parser);
  591. // Parse attribute pairs
  592. parameter->SetCPPType("std::string");
  593. parameter->SetType("scalar");
  594. for (int attr=0; attr < (attrCount / 2); attr++)
  595. {
  596. if ((strcmp(attrs[2*attr], "multiple") == 0))
  597. {
  598. if ((strcmp(attrs[2*attr+1], "true") == 0) ||
  599. (strcmp(attrs[2*attr+1], "false") == 0))
  600. {
  601. parameter->SetMultiple(attrs[2*attr+1]);
  602. if (strcmp(attrs[2*attr+1], "true") == 0)
  603. {
  604. parameter->SetCPPType("std::vector<std::string>");
  605. parameter->SetArgType("std::string");
  606. }
  607. }
  608. else
  609. {
  610. std::string error("ModuleDescriptionParser Error: \"" + std::string(attrs[2*attr+1]) + "\" is not a valid argument for the attribute \"multiple\". Only \"true\" and \"false\" are accepted.");
  611. if (ps->ErrorDescription.size() == 0)
  612. {
  613. ps->ErrorDescription = error;
  614. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  615. ps->Error = true;
  616. }
  617. ps->OpenTags.push(name);
  618. delete parameter;
  619. return;
  620. }
  621. }
  622. else if ((strcmp(attrs[2*attr], "fileExtensions") == 0))
  623. {
  624. parameter->SetFileExtensionsAsString(attrs[2*attr+1]);
  625. }
  626. else
  627. {
  628. std::string error("ModuleDescriptionParser Error: \"" + std::string(attrs[2*attr]) + "\" is not a valid attribute for \"" + name + "\". Only \"multiple\" and \"fileExtensions\" are accepted.");
  629. if (ps->ErrorDescription.size() == 0)
  630. {
  631. ps->ErrorDescription = error;
  632. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  633. ps->Error = true;
  634. }
  635. ps->OpenTags.push(name);
  636. delete parameter;
  637. return;
  638. }
  639. }
  640. parameter->SetTag(name);
  641. }
  642. else if (name == "directory")
  643. {
  644. if (!group || (ps->OpenTags.top() != "parameters"))
  645. {
  646. std::string error("ModuleDescriptionParser Error: <" + name + "> can only be used inside <parameters> but was found inside <" + ps->OpenTags.top() + ">");
  647. if (ps->ErrorDescription.size() == 0)
  648. {
  649. ps->ErrorDescription = error;
  650. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  651. ps->Error = true;
  652. }
  653. ps->OpenTags.push(name);
  654. delete parameter;
  655. return;
  656. }
  657. parameter = new ModuleParameter;
  658. int attrCount = XML_GetSpecifiedAttributeCount(ps->Parser);
  659. if (attrCount == 2 &&
  660. (strcmp(attrs[0], "multiple") == 0) &&
  661. (strcmp(attrs[1], "true") == 0))
  662. {
  663. parameter->SetMultiple(attrs[1]);
  664. parameter->SetCPPType("std::vector<std::string>");
  665. parameter->SetArgType("std::string");
  666. }
  667. else
  668. {
  669. parameter->SetCPPType("std::string");
  670. }
  671. parameter->SetTag(name);
  672. }
  673. else if (name == "transform")
  674. {
  675. if (!group || (ps->OpenTags.top() != "parameters"))
  676. {
  677. std::string error("ModuleDescriptionParser Error: <" + name + "> can only be used inside <parameters> but was found inside <" + ps->OpenTags.top() + ">");
  678. if (ps->ErrorDescription.size() == 0)
  679. {
  680. ps->ErrorDescription = error;
  681. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  682. ps->Error = true;
  683. }
  684. ps->OpenTags.push(name);
  685. delete parameter;
  686. return;
  687. }
  688. parameter = new ModuleParameter;
  689. int attrCount = XML_GetSpecifiedAttributeCount(ps->Parser);
  690. // Parse attribute pairs
  691. parameter->SetCPPType("std::string");
  692. parameter->SetType("unknown");
  693. for (int attr=0; attr < (attrCount / 2); attr++)
  694. {
  695. if ((strcmp(attrs[2*attr], "multiple") == 0))
  696. {
  697. if ((strcmp(attrs[2*attr+1], "true") == 0) ||
  698. (strcmp(attrs[2*attr+1], "false") == 0))
  699. {
  700. parameter->SetMultiple(attrs[2*attr+1]);
  701. if (strcmp(attrs[2*attr+1], "true") == 0)
  702. {
  703. parameter->SetCPPType("std::vector<std::string>");
  704. parameter->SetArgType("std::string");
  705. }
  706. }
  707. else
  708. {
  709. std::string error("ModuleDescriptionParser Error: \"" + std::string(attrs[2*attr+1]) + "\" is not a valid argument for the attribute \"multiple\". Only \"true\" and \"false\" are accepted.");
  710. if (ps->ErrorDescription.size() == 0)
  711. {
  712. ps->ErrorDescription = error;
  713. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  714. ps->Error = true;
  715. }
  716. ps->OpenTags.push(name);
  717. delete parameter;
  718. return;
  719. }
  720. }
  721. else if ((strcmp(attrs[2*attr], "type") == 0))
  722. {
  723. if ((strcmp(attrs[2*attr+1], "linear") == 0) ||
  724. (strcmp(attrs[2*attr+1], "nonlinear") == 0) ||
  725. (strcmp(attrs[2*attr+1], "bspline") == 0))
  726. {
  727. parameter->SetType(attrs[2*attr+1]);
  728. }
  729. else
  730. {
  731. std::string error("ModuleDescriptionParser Error: \"" + std::string(attrs[2*attr+1]) + "\" is not a valid value for the attribute \"" + "type" + "\". Only \"linear\" and \"nonlinear\" are accepted.");
  732. if (ps->ErrorDescription.size() == 0)
  733. {
  734. ps->ErrorDescription = error;
  735. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  736. ps->Error = true;
  737. }
  738. ps->OpenTags.push(name);
  739. delete parameter;
  740. return;
  741. }
  742. }
  743. else if ((strcmp(attrs[2*attr], "fileExtensions") == 0))
  744. {
  745. parameter->SetFileExtensionsAsString(attrs[2*attr+1]);
  746. }
  747. else if ((strcmp(attrs[2*attr], "reference") == 0))
  748. {
  749. parameter->SetReference(attrs[2*attr+1]);
  750. }
  751. else
  752. {
  753. std::string error("ModuleDescriptionParser Error: \"" + std::string(attrs[2*attr]) + "\" is not a valid attribute for \"" + name + "\". Only \"multiple\", \"fileExtensions\" and \"type\" are accepted.");
  754. if (ps->ErrorDescription.size() == 0)
  755. {
  756. ps->ErrorDescription = error;
  757. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  758. ps->Error = true;
  759. }
  760. ps->OpenTags.push(name);
  761. delete parameter;
  762. return;
  763. }
  764. }
  765. parameter->SetTag(name);
  766. }
  767. else if (name == "image")
  768. {
  769. if (!group || (ps->OpenTags.top() != "parameters"))
  770. {
  771. std::string error("ModuleDescriptionParser Error: <" + name + "> can only be used inside <parameters> but was found inside <" + ps->OpenTags.top() + ">");
  772. if (ps->ErrorDescription.size() == 0)
  773. {
  774. ps->ErrorDescription = error;
  775. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  776. ps->Error = true;
  777. }
  778. ps->OpenTags.push(name);
  779. delete parameter;
  780. return;
  781. }
  782. parameter = new ModuleParameter;
  783. int attrCount = XML_GetSpecifiedAttributeCount(ps->Parser);
  784. // Parse attribute pairs
  785. parameter->SetCPPType("std::string");
  786. parameter->SetType("scalar");
  787. for (int attr=0; attr < (attrCount / 2); attr++)
  788. {
  789. if ((strcmp(attrs[2*attr], "multiple") == 0))
  790. {
  791. if ((strcmp(attrs[2*attr+1], "true") == 0) ||
  792. (strcmp(attrs[2*attr+1], "false") == 0))
  793. {
  794. parameter->SetMultiple(attrs[2*attr+1]);
  795. if (strcmp(attrs[2*attr+1], "true") == 0)
  796. {
  797. parameter->SetCPPType("std::vector<std::string>");
  798. parameter->SetArgType("std::string");
  799. }
  800. }
  801. else
  802. {
  803. std::string error("ModuleDescriptionParser Error: \"" + std::string(attrs[2*attr+1]) + "\" is not a valid argument for the attribute \"multiple\". Only \"true\" and \"false\" are accepted.");
  804. if (ps->ErrorDescription.size() == 0)
  805. {
  806. ps->ErrorDescription = error;
  807. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  808. ps->Error = true;
  809. }
  810. ps->OpenTags.push(name);
  811. delete parameter;
  812. return;
  813. }
  814. }
  815. else if ((strcmp(attrs[2*attr], "type") == 0))
  816. {
  817. if ((strcmp(attrs[2*attr+1], "any") == 0) ||
  818. (strcmp(attrs[2*attr+1], "scalar") == 0) ||
  819. (strcmp(attrs[2*attr+1], "label") == 0) ||
  820. (strcmp(attrs[2*attr+1], "tensor") == 0) ||
  821. (strcmp(attrs[2*attr+1], "diffusion-weighted") == 0) ||
  822. (strcmp(attrs[2*attr+1], "vector") == 0))
  823. {
  824. parameter->SetType(attrs[2*attr+1]);
  825. }
  826. else
  827. {
  828. std::string error("ModuleDescriptionParser Error: \"" + std::string(attrs[2*attr+1]) + "\" is not a valid value for the attribute \"" + "type" + "\". Only \"scalar\", \"label\" , \"tensor\", \"diffusion-weighted\", \"vector\" and \"any\" are accepted.");
  829. if (ps->ErrorDescription.size() == 0)
  830. {
  831. ps->ErrorDescription = error;
  832. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  833. ps->Error = true;
  834. }
  835. ps->OpenTags.push(name);
  836. delete parameter;
  837. return;
  838. }
  839. }
  840. else if ((strcmp(attrs[2*attr], "fileExtensions") == 0))
  841. {
  842. parameter->SetFileExtensionsAsString(attrs[2*attr+1]);
  843. }
  844. else if ((strcmp(attrs[2*attr], "hidden") == 0))
  845. {
  846. if ((strcmp(attrs[2*attr+1], "true") == 0) ||
  847. (strcmp(attrs[2*attr+1], "false") == 0))
  848. {
  849. parameter->SetHidden(attrs[2*attr+1]);
  850. }
  851. else
  852. {
  853. std::string error("ModuleDescriptionParser Error: \"" + std::string(attrs[2*attr+1]) + "\" is not a valid argument for the attribute \"hidden\". Only \"true\" and \"false\" are accepted.");
  854. if (ps->ErrorDescription.size() == 0)
  855. {
  856. ps->ErrorDescription = error;
  857. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  858. ps->Error = true;
  859. }
  860. ps->OpenTags.push(name);
  861. delete parameter;
  862. return;
  863. }
  864. }
  865. else if ((strcmp(attrs[2*attr], "reference") == 0))
  866. {
  867. parameter->SetReference(attrs[2*attr+1]);
  868. }
  869. else
  870. {
  871. std::string error("ModuleDescriptionParser Error: \"" + std::string(attrs[2*attr]) + "\" is not a valid attribute for \"" + name + "\". Only \"multiple\", \"fileExtensions\", \"type\", \"hidden\" and \"reference\" are accepted.");
  872. if (ps->ErrorDescription.size() == 0)
  873. {
  874. ps->ErrorDescription = error;
  875. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  876. ps->Error = true;
  877. }
  878. ps->OpenTags.push(name);
  879. delete parameter;
  880. return;
  881. }
  882. }
  883. parameter->SetTag(name);
  884. }
  885. else if (name == "geometry")
  886. {
  887. if (!group || (ps->OpenTags.top() != "parameters"))
  888. {
  889. std::string error("ModuleDescriptionParser Error: <" + name + "> can only be used inside <parameters> but was found inside <" + ps->OpenTags.top() + ">");
  890. if (ps->ErrorDescription.size() == 0)
  891. {
  892. ps->ErrorDescription = error;
  893. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  894. ps->Error = true;
  895. }
  896. ps->OpenTags.push(name);
  897. delete parameter;
  898. return;
  899. }
  900. parameter = new ModuleParameter;
  901. int attrCount = XML_GetSpecifiedAttributeCount(ps->Parser);
  902. // Parse attribute pairs
  903. parameter->SetCPPType("std::string");
  904. parameter->SetType("scalar");
  905. for (int attr=0; attr < (attrCount / 2); attr++)
  906. {
  907. if ((strcmp(attrs[2*attr], "multiple") == 0))
  908. {
  909. if ((strcmp(attrs[2*attr+1], "true") == 0) ||
  910. (strcmp(attrs[2*attr+1], "false") == 0))
  911. {
  912. parameter->SetMultiple(attrs[2*attr+1]);
  913. }
  914. else
  915. {
  916. std::string error("ModuleDescriptionParser Error: \"" + std::string(attrs[2*attr+1]) + "\" is not a valid argument for the attribute \"multiple\". Only \"true\" and \"false\" are accepted.");
  917. if (ps->ErrorDescription.size() == 0)
  918. {
  919. ps->ErrorDescription = error;
  920. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  921. ps->Error = true;
  922. }
  923. ps->OpenTags.push(name);
  924. delete parameter;
  925. return;
  926. }
  927. }
  928. else if ((strcmp(attrs[2*attr], "aggregate") == 0))
  929. {
  930. if ((strcmp(attrs[2*attr+1], "true") == 0) ||
  931. (strcmp(attrs[2*attr+1], "false") == 0))
  932. {
  933. parameter->SetAggregate(attrs[2*attr+1]);
  934. }
  935. else
  936. {
  937. std::string error("ModuleDescriptionParser Error: \"" + std::string(attrs[2*attr+1]) + "\" is not a valid argument for the attribute \"aggregate\". Only \"true\" and \"false\" are accepted.");
  938. if (ps->ErrorDescription.size() == 0)
  939. {
  940. ps->ErrorDescription = error;
  941. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  942. ps->Error = true;
  943. }
  944. ps->OpenTags.push(name);
  945. delete parameter;
  946. return;
  947. }
  948. } else if ((strcmp(attrs[2*attr], "type") == 0))
  949. {
  950. if ((strcmp(attrs[2*attr+1], "fiberbundle") == 0) ||
  951. (strcmp(attrs[2*attr+1], "model") == 0))
  952. {
  953. parameter->SetType(attrs[2*attr+1]);
  954. }
  955. else
  956. {
  957. std::string error("ModuleDescriptionParser Error: \"" + std::string(attrs[2*attr+1]) + "\" is not a valid value for the attribute \"" + "type" + "\". Only \"fiberbundle\", \"model\" are accepted.");
  958. if (ps->ErrorDescription.size() == 0)
  959. {
  960. ps->ErrorDescription = error;
  961. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  962. ps->Error = true;
  963. }
  964. ps->OpenTags.push(name);
  965. delete parameter;
  966. return;
  967. }
  968. }
  969. else if ((strcmp(attrs[2*attr], "fileExtensions") == 0))
  970. {
  971. parameter->SetFileExtensionsAsString(attrs[2*attr+1]);
  972. }
  973. else
  974. {
  975. std::string error("ModuleDescriptionParser Error: \"" + std::string(attrs[2*attr]) + "\" is not a valid attribute for \"" + name + "\". Only \"multiple\", \"type\", and \"fileExtensions\" are accepted.");
  976. if (ps->ErrorDescription.size() == 0)
  977. {
  978. ps->ErrorDescription = error;
  979. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  980. ps->Error = true;
  981. }
  982. ps->OpenTags.push(name);
  983. delete parameter;
  984. return;
  985. }
  986. }
  987. parameter->SetTag(name);
  988. if (parameter->GetMultiple() == "true"
  989. && parameter->GetAggregate() != "true")
  990. {
  991. parameter->SetCPPType("std::vector<std::string>");
  992. parameter->SetArgType("std::string");
  993. }
  994. }
  995. else if (name == "table")
  996. {
  997. if (!group || (ps->OpenTags.top() != "parameters"))
  998. {
  999. std::string error("ModuleDescriptionParser Error: <" + name + "> can only be used inside <parameters> but was found inside <" + ps->OpenTags.top() + ">");
  1000. if (ps->ErrorDescription.size() == 0)
  1001. {
  1002. ps->ErrorDescription = error;
  1003. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  1004. ps->Error = true;
  1005. }
  1006. ps->OpenTags.push(name);
  1007. delete parameter;
  1008. return;
  1009. }
  1010. parameter = new ModuleParameter;
  1011. int attrCount = XML_GetSpecifiedAttributeCount(ps->Parser);
  1012. // Parse attribute pairs
  1013. parameter->SetCPPType("std::string");
  1014. parameter->SetType("scalar");
  1015. for (int attr=0; attr < (attrCount / 2); attr++)
  1016. {
  1017. if ((strcmp(attrs[2*attr], "multiple") == 0))
  1018. {
  1019. if ((strcmp(attrs[2*attr+1], "true") == 0) ||
  1020. (strcmp(attrs[2*attr+1], "false") == 0))
  1021. {
  1022. parameter->SetMultiple(attrs[2*attr+1]);
  1023. if (strcmp(attrs[2*attr+1], "true") == 0)
  1024. {
  1025. parameter->SetCPPType("std::vector<std::string>");
  1026. parameter->SetArgType("std::string");
  1027. }
  1028. }
  1029. else
  1030. {
  1031. std::string error("ModuleDescriptionParser Error: \"" + std::string(attrs[2*attr+1]) + "\" is not a valid argument for the attribute \"multiple\". Only \"true\" and \"false\" are accepted.");
  1032. if (ps->ErrorDescription.size() == 0)
  1033. {
  1034. ps->ErrorDescription = error;
  1035. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  1036. ps->Error = true;
  1037. }
  1038. ps->OpenTags.push(name);
  1039. delete parameter;
  1040. return;
  1041. }
  1042. }
  1043. else if ((strcmp(attrs[2*attr], "reference") == 0))
  1044. {
  1045. parameter->SetReference(attrs[2*attr+1]);
  1046. }
  1047. else if ((strcmp(attrs[2*attr], "hidden") == 0))
  1048. {
  1049. if ((strcmp(attrs[2*attr+1], "true") == 0) ||
  1050. (strcmp(attrs[2*attr+1], "false") == 0))
  1051. {
  1052. parameter->SetHidden(attrs[2*attr+1]);
  1053. }
  1054. else
  1055. {
  1056. std::string error("ModuleDescriptionParser Error: \"" + std::string(attrs[2*attr+1]) + "\" is not a valid argument for the attribute \"hidden\". Only \"true\" and \"false\" are accepted.");
  1057. if (ps->ErrorDescription.size() == 0)
  1058. {
  1059. ps->ErrorDescription = error;
  1060. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  1061. ps->Error = true;
  1062. }
  1063. ps->OpenTags.push(name);
  1064. delete parameter;
  1065. return;
  1066. }
  1067. }
  1068. else if ((strcmp(attrs[2*attr], "type") == 0))
  1069. {
  1070. // Need to add other tables with context (similar to color
  1071. // tables) as well as add general CSV files
  1072. if ((strcmp(attrs[2*attr+1], "color") == 0))
  1073. {
  1074. parameter->SetType(attrs[2*attr+1]);
  1075. }
  1076. else
  1077. {
  1078. std::string error("ModuleDescriptionParser Error: \"" + std::string(attrs[2*attr+1]) + "\" is not a valid value for the attribute \"" + "type" + "\". Only \"color\" is currently accepted.");
  1079. if (ps->ErrorDescription.size() == 0)
  1080. {
  1081. ps->ErrorDescription = error;
  1082. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  1083. ps->Error = true;
  1084. }
  1085. ps->OpenTags.push(name);
  1086. delete parameter;
  1087. return;
  1088. }
  1089. }
  1090. else if ((strcmp(attrs[2*attr], "fileExtensions") == 0))
  1091. {
  1092. parameter->SetFileExtensionsAsString(attrs[2*attr+1]);
  1093. }
  1094. else
  1095. {
  1096. std::string error("ModuleDescriptionParser Error: \"" + std::string(attrs[2*attr]) + "\" is not a valid attribute for \"" + name + "\". Only \"multiple\", \"hidden\", \"reference\", \"type\", and \"fileExtensions\" are accepted.");
  1097. if (ps->ErrorDescription.size() == 0)
  1098. {
  1099. ps->ErrorDescription = error;
  1100. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  1101. ps->Error = true;
  1102. }
  1103. ps->OpenTags.push(name);
  1104. delete parameter;
  1105. return;
  1106. }
  1107. }
  1108. parameter->SetTag(name);
  1109. }
  1110. else if (name == "measurement")
  1111. {
  1112. if (!group || (ps->OpenTags.top() != "parameters"))
  1113. {
  1114. std::string error("ModuleDescriptionParser Error: <" + name + "> can only be used inside <parameters> but was found inside <" + ps->OpenTags.top() + ">");
  1115. if (ps->ErrorDescription.size() == 0)
  1116. {
  1117. ps->ErrorDescription = error;
  1118. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  1119. ps->Error = true;
  1120. }
  1121. ps->OpenTags.push(name);
  1122. delete parameter;
  1123. return;
  1124. }
  1125. parameter = new ModuleParameter;
  1126. int attrCount = XML_GetSpecifiedAttributeCount(ps->Parser);
  1127. // Parse attribute pairs
  1128. parameter->SetCPPType("std::string");
  1129. parameter->SetType("scalar");
  1130. for (int attr=0; attr < (attrCount / 2); attr++)
  1131. {
  1132. if ((strcmp(attrs[2*attr], "multiple") == 0))
  1133. {
  1134. if ((strcmp(attrs[2*attr+1], "true") == 0) ||
  1135. (strcmp(attrs[2*attr+1], "false") == 0))
  1136. {
  1137. parameter->SetMultiple(attrs[2*attr+1]);
  1138. if (strcmp(attrs[2*attr+1], "true") == 0)
  1139. {
  1140. parameter->SetCPPType("std::vector<std::string>");
  1141. parameter->SetArgType("std::string");
  1142. }
  1143. }
  1144. else
  1145. {
  1146. std::string error("ModuleDescriptionParser Error: \"" + std::string(attrs[2*attr+1]) + "\" is not a valid argument for the attribute \"multiple\". Only \"true\" and \"false\" are accepted.");
  1147. if (ps->ErrorDescription.size() == 0)
  1148. {
  1149. ps->ErrorDescription = error;
  1150. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  1151. ps->Error = true;
  1152. }
  1153. ps->OpenTags.push(name);
  1154. delete parameter;
  1155. return;
  1156. }
  1157. }
  1158. else if ((strcmp(attrs[2*attr], "reference") == 0))
  1159. {
  1160. parameter->SetReference(attrs[2*attr+1]);
  1161. }
  1162. else if ((strcmp(attrs[2*attr], "hidden") == 0))
  1163. {
  1164. if ((strcmp(attrs[2*attr+1], "true") == 0) ||
  1165. (strcmp(attrs[2*attr+1], "false") == 0))
  1166. {
  1167. parameter->SetHidden(attrs[2*attr+1]);
  1168. }
  1169. else
  1170. {
  1171. std::string error("ModuleDescriptionParser Error: \"" + std::string(attrs[2*attr+1]) + "\" is not a valid argument for the attribute \"hidden\". Only \"true\" and \"false\" are accepted.");
  1172. if (ps->ErrorDescription.size() == 0)
  1173. {
  1174. ps->ErrorDescription = error;
  1175. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  1176. ps->Error = true;
  1177. }
  1178. ps->OpenTags.push(name);
  1179. delete parameter;
  1180. return;
  1181. }
  1182. }
  1183. else if ((strcmp(attrs[2*attr], "type") == 0))
  1184. {
  1185. // "type" will refer to the error models (regression,
  1186. // orthogonal regression, ...). We'll define these later. When
  1187. // we do, put the error handling back in.
  1188. // if ((strcmp(attrs[2*attr+1], "some_error_type") == 0))
  1189. // {
  1190. parameter->SetType(attrs[2*attr+1]);
  1191. // }
  1192. // else
  1193. // {
  1194. // std::string error("ModuleDescriptionParser Error: \"" + std::string(attrs[2*attr+1]) + "\" is not a valid value for the attribute \"" + "type" + "\". Only \"color\" is currently accepted.");
  1195. // if (ps->ErrorDescription.size() == 0)
  1196. // {
  1197. // ps->ErrorDescription = error;
  1198. // ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  1199. // ps->Error = true;
  1200. // }
  1201. // ps->OpenTags.push(name);
  1202. // delete parameter;
  1203. // return;
  1204. // }
  1205. }
  1206. else if ((strcmp(attrs[2*attr], "fileExtensions") == 0))
  1207. {
  1208. parameter->SetFileExtensionsAsString(attrs[2*attr+1]);
  1209. }
  1210. else
  1211. {
  1212. std::string error("ModuleDescriptionParser Error: \"" + std::string(attrs[2*attr]) + "\" is not a valid attribute for \"" + name + "\". Only \"multiple\", \"hidden\", \"reference\", \"type\", and \"fileExtensions\" are accepted.");
  1213. if (ps->ErrorDescription.size() == 0)
  1214. {
  1215. ps->ErrorDescription = error;
  1216. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  1217. ps->Error = true;
  1218. }
  1219. ps->OpenTags.push(name);
  1220. delete parameter;
  1221. return;
  1222. }
  1223. }
  1224. parameter->SetTag(name);
  1225. }
  1226. else if (parameter && (name == "flag"))
  1227. {
  1228. int attrCount = XML_GetSpecifiedAttributeCount(ps->Parser);
  1229. if (attrCount > 0)
  1230. {
  1231. for (int i=0; i < attrCount/2; ++i)
  1232. {
  1233. if (strcmp(attrs[2*i], "alias") == 0)
  1234. {
  1235. parameter->SetFlagAliasesAsString(attrs[2*i+1]);
  1236. }
  1237. else if (strcmp(attrs[2*i], "deprecatedalias") == 0)
  1238. {
  1239. parameter->SetDeprecatedFlagAliasesAsString(attrs[2*i+1]);
  1240. }
  1241. }
  1242. }
  1243. }
  1244. else if (parameter && (name == "longflag"))
  1245. {
  1246. int attrCount = XML_GetSpecifiedAttributeCount(ps->Parser);
  1247. if (attrCount > 0)
  1248. {
  1249. for (int i=0; i < attrCount/2; ++i)
  1250. {
  1251. if (strcmp(attrs[2*i], "alias") == 0)
  1252. {
  1253. parameter->SetLongFlagAliasesAsString(attrs[2*i+1]);
  1254. }
  1255. else if (strcmp(attrs[2*i], "deprecatedalias") == 0)
  1256. {
  1257. parameter->SetDeprecatedLongFlagAliasesAsString(attrs[2*i+1]);
  1258. }
  1259. }
  1260. }
  1261. }
  1262. ps->CurrentParameter = parameter;
  1263. ps->CurrentGroup = group;
  1264. ps->OpenTags.push(name);
  1265. }
  1266. void
  1267. endElement(void *userData, const char *element)
  1268. {
  1269. ParserState *ps = reinterpret_cast<ParserState *>(userData);
  1270. ModuleParameter *parameter = ps->CurrentParameter;
  1271. ModuleParameterGroup *group = ps->CurrentGroup;
  1272. std::string name(element);
  1273. if (name == "parameters" && ps->Depth == 1)
  1274. {
  1275. ps->CurrentDescription.AddParameterGroup(*ps->CurrentGroup);
  1276. if (ps->CurrentGroup)
  1277. {
  1278. delete ps->CurrentGroup;
  1279. }
  1280. ps->CurrentGroup = 0;
  1281. ps->CurrentParameter = 0;
  1282. }
  1283. else if (name == "parameters" && ps->Depth != 1)
  1284. {
  1285. ps->CurrentGroup = 0;
  1286. ps->CurrentParameter = 0;
  1287. }
  1288. else if (group && parameter && (name == "integer"))
  1289. {
  1290. ps->CurrentGroup->AddParameter(*parameter);
  1291. if (ps->CurrentParameter)
  1292. {
  1293. delete ps->CurrentParameter;
  1294. }
  1295. ps->CurrentParameter = 0;
  1296. }
  1297. else if (group && parameter && (name == "float"))
  1298. {
  1299. ps->CurrentGroup->AddParameter(*parameter);
  1300. if (ps->CurrentParameter)
  1301. {
  1302. delete ps->CurrentParameter;
  1303. }
  1304. ps->CurrentParameter = 0;
  1305. }
  1306. else if (group && parameter && (name == "double"))
  1307. {
  1308. ps->CurrentGroup->AddParameter(*parameter);
  1309. if (ps->CurrentParameter)
  1310. {
  1311. delete ps->CurrentParameter;
  1312. }
  1313. ps->CurrentParameter = 0;
  1314. }
  1315. else if (group && parameter && (name == "string"))
  1316. {
  1317. ps->CurrentGroup->AddParameter(*parameter);
  1318. if (ps->CurrentParameter)
  1319. {
  1320. delete ps->CurrentParameter;
  1321. }
  1322. ps->CurrentParameter = 0;
  1323. }
  1324. else if (group && parameter && (name =="boolean"))
  1325. {
  1326. ps->CurrentGroup->AddParameter(*parameter);
  1327. if (ps->CurrentParameter)
  1328. {
  1329. delete ps->CurrentParameter;
  1330. }
  1331. ps->CurrentParameter = 0;
  1332. }
  1333. else if (group && parameter && (name == "file"))
  1334. {
  1335. ps->CurrentGroup->AddParameter(*parameter);
  1336. if (ps->CurrentParameter)
  1337. {
  1338. delete ps->CurrentParameter;
  1339. }
  1340. ps->CurrentParameter = 0;
  1341. }
  1342. else if (group && parameter && (name == "directory"))
  1343. {
  1344. ps->CurrentGroup->AddParameter(*parameter);
  1345. if (ps->CurrentParameter)
  1346. {
  1347. delete ps->CurrentParameter;
  1348. }
  1349. ps->CurrentParameter = 0;
  1350. }
  1351. else if (group && parameter && (name == "transform"))
  1352. {
  1353. ps->CurrentGroup->AddParameter(*parameter);
  1354. if (ps->CurrentParameter)
  1355. {
  1356. delete ps->CurrentParameter;
  1357. }
  1358. ps->CurrentParameter = 0;
  1359. }
  1360. else if (group && parameter && (name == "image"))
  1361. {
  1362. ps->CurrentGroup->AddParameter(*parameter);
  1363. if (ps->CurrentParameter)
  1364. {
  1365. delete ps->CurrentParameter;
  1366. }
  1367. ps->CurrentParameter = 0;
  1368. }
  1369. else if (group && parameter && (name == "geometry"))
  1370. {
  1371. ps->CurrentGroup->AddParameter(*parameter);
  1372. if (ps->CurrentParameter)
  1373. {
  1374. delete ps->CurrentParameter;
  1375. }
  1376. ps->CurrentParameter = 0;
  1377. }
  1378. else if (group && parameter && (name == "table"))
  1379. {
  1380. ps->CurrentGroup->AddParameter(*parameter);
  1381. if (ps->CurrentParameter)
  1382. {
  1383. delete ps->CurrentParameter;
  1384. }
  1385. ps->CurrentParameter = 0;
  1386. }
  1387. else if (group && parameter && (name == "measurement"))
  1388. {
  1389. ps->CurrentGroup->AddParameter(*parameter);
  1390. if (ps->CurrentParameter)
  1391. {
  1392. delete ps->CurrentParameter;
  1393. }
  1394. ps->CurrentParameter = 0;
  1395. }
  1396. else if (group && parameter && (name == "integer-vector"))
  1397. {
  1398. ps->CurrentGroup->AddParameter(*parameter);
  1399. if (ps->CurrentParameter)
  1400. {
  1401. delete ps->CurrentParameter;
  1402. }
  1403. ps->CurrentParameter = 0;
  1404. }
  1405. else if (group && parameter && (name == "float-vector"))
  1406. {
  1407. ps->CurrentGroup->AddParameter(*parameter);
  1408. if (ps->CurrentParameter)
  1409. {
  1410. delete ps->CurrentParameter;
  1411. }
  1412. ps->CurrentParameter = 0;
  1413. }
  1414. else if (group && parameter && (name == "string-vector"))
  1415. {
  1416. ps->CurrentGroup->AddParameter(*parameter);
  1417. if (ps->CurrentParameter)
  1418. {
  1419. delete ps->CurrentParameter;
  1420. }
  1421. ps->CurrentParameter = 0;
  1422. }
  1423. else if (group && parameter && (name == "double-vector"))
  1424. {
  1425. ps->CurrentGroup->AddParameter(*parameter);
  1426. if (ps->CurrentParameter)
  1427. {
  1428. delete ps->CurrentParameter;
  1429. }
  1430. ps->CurrentParameter = 0;
  1431. }
  1432. else if (group && parameter && (name == "point"))
  1433. {
  1434. ps->CurrentGroup->AddParameter(*parameter);
  1435. if (ps->CurrentParameter)
  1436. {
  1437. delete ps->CurrentParameter;
  1438. }
  1439. ps->CurrentParameter = 0;
  1440. }
  1441. else if (group && parameter && (name == "region"))
  1442. {
  1443. ps->CurrentGroup->AddParameter(*parameter);
  1444. if (ps->CurrentParameter)
  1445. {
  1446. delete ps->CurrentParameter;
  1447. }
  1448. ps->CurrentParameter = 0;
  1449. }
  1450. else if (group && parameter && (name == "string-enumeration"))
  1451. {
  1452. ps->CurrentGroup->AddParameter(*parameter);
  1453. if (ps->CurrentParameter)
  1454. {
  1455. delete ps->CurrentParameter;
  1456. }
  1457. ps->CurrentParameter = 0;
  1458. }
  1459. else if (group && parameter && (name == "integer-enumeration"))
  1460. {
  1461. ps->CurrentGroup->AddParameter(*parameter);
  1462. if (ps->CurrentParameter)
  1463. {
  1464. delete ps->CurrentParameter;
  1465. }
  1466. ps->CurrentParameter = 0;
  1467. }
  1468. else if (group && parameter && (name == "float-enumeration"))
  1469. {
  1470. ps->CurrentGroup->AddParameter(*parameter);
  1471. if (ps->CurrentParameter)
  1472. {
  1473. delete ps->CurrentParameter;
  1474. }
  1475. ps->CurrentParameter = 0;
  1476. }
  1477. else if (group && parameter && (name == "double-enumeration"))
  1478. {
  1479. ps->CurrentGroup->AddParameter(*parameter);
  1480. if (ps->CurrentParameter)
  1481. {
  1482. delete ps->CurrentParameter;
  1483. }
  1484. ps->CurrentParameter = 0;
  1485. }
  1486. else if (parameter && (name == "flag"))
  1487. {
  1488. std::string temp = ps->LastData[ps->Depth];
  1489. trimLeadingAndTrailing(temp);
  1490. trimLeading(temp, "-");
  1491. if (temp.size() > 1)
  1492. {
  1493. std::string error("ModuleDescriptionParser Error: <"
  1494. + name
  1495. + std::string("> can only contain one character. \"")
  1496. + temp
  1497. + std::string("\" has more than one character."));
  1498. if (ps->ErrorDescription.size() == 0)
  1499. {
  1500. ps->ErrorDescription = error;
  1501. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  1502. ps->Error = true;
  1503. }
  1504. if (!ps->OpenTags.empty())
  1505. {
  1506. ps->OpenTags.pop();
  1507. }
  1508. ps->Depth--;
  1509. return;
  1510. }
  1511. else
  1512. {
  1513. if (!parameter->GetIndex().empty())
  1514. {
  1515. std::string error("ModuleDescriptionParser Error: <"
  1516. + std::string(name)
  1517. + "> cannot be specified because an index has been specified for this parameter."
  1518. + std::string("\""));
  1519. if (ps->ErrorDescription.size() == 0)
  1520. {
  1521. ps->ErrorDescription = error;
  1522. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  1523. ps->Error = true;
  1524. }
  1525. if (!ps->OpenTags.empty())
  1526. {
  1527. ps->OpenTags.pop();
  1528. ps->Depth--;
  1529. }
  1530. return;
  1531. }
  1532. parameter->SetFlag(temp);
  1533. }
  1534. }
  1535. else if (parameter && (name == "longflag"))
  1536. {
  1537. std::string temp = ps->LastData[ps->Depth];
  1538. trimLeadingAndTrailing(temp);
  1539. trimLeading(temp, "-");
  1540. if (!validVariable(temp))
  1541. {
  1542. std::string error("ModuleDescriptionParser Error: <"
  1543. + std::string(name)
  1544. + "> can only contain letters, numbers and underscores and must start with a _ or letter. The offending name is \""
  1545. + temp
  1546. + std::string("\""));
  1547. if (ps->ErrorDescription.size() == 0)
  1548. {
  1549. ps->ErrorDescription = error;
  1550. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  1551. ps->Error = true;
  1552. }
  1553. if (!ps->OpenTags.empty())
  1554. {
  1555. ps->OpenTags.pop();
  1556. ps->Depth--;
  1557. }
  1558. return;
  1559. }
  1560. if (!parameter->GetIndex().empty())
  1561. {
  1562. std::string error("ModuleDescriptionParser Error: <"
  1563. + std::string(name)
  1564. + "> cannot be specified because an index has been specified for this parameter."
  1565. + std::string("\""));
  1566. if (ps->ErrorDescription.size() == 0)
  1567. {
  1568. ps->ErrorDescription = error;
  1569. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  1570. ps->Error = true;
  1571. }
  1572. if (!ps->OpenTags.empty())
  1573. {
  1574. ps->OpenTags.pop();
  1575. ps->Depth--;
  1576. }
  1577. return;
  1578. }
  1579. parameter->SetLongFlag(temp);
  1580. if (parameter->GetName().empty())
  1581. {
  1582. parameter->SetName(temp);
  1583. }
  1584. }
  1585. else if (parameter && (name == "name"))
  1586. {
  1587. std::string temp = std::string(ps->LastData[ps->Depth]);
  1588. trimLeadingAndTrailing(temp);
  1589. if (!validVariable(temp))
  1590. {
  1591. std::string error("ModuleDescriptionParser Error: <"
  1592. + std::string(name)
  1593. + "> can only contain letters, numbers and underscores and must start with an _ or letter. The offending name is \""
  1594. + temp
  1595. + std::string("\""));
  1596. if (ps->ErrorDescription.size() == 0)
  1597. {
  1598. ps->ErrorDescription = error;
  1599. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  1600. ps->Error = true;
  1601. }
  1602. if (!ps->OpenTags.empty())
  1603. {
  1604. ps->OpenTags.pop();
  1605. ps->Depth--;
  1606. }
  1607. return;
  1608. }
  1609. parameter->SetName(temp);
  1610. }
  1611. else if ((group || parameter) && (name == "label"))
  1612. {
  1613. std::string temp = ps->LastData[ps->Depth];
  1614. trimLeadingAndTrailing(temp);
  1615. if (group && !parameter)
  1616. {
  1617. group->SetLabel(temp);
  1618. }
  1619. else
  1620. {
  1621. parameter->SetLabel(temp);
  1622. }
  1623. }
  1624. else if (name == "category")
  1625. {
  1626. std::string temp = ps->LastData[ps->Depth];
  1627. trimLeadingAndTrailing(temp);
  1628. ps->CurrentDescription.SetCategory(temp);
  1629. }
  1630. else if (!parameter && (name == "index"))
  1631. {
  1632. std::string temp = ps->LastData[ps->Depth];
  1633. trimLeadingAndTrailing(temp);
  1634. ps->CurrentDescription.SetIndex(temp);
  1635. }
  1636. else if (name == "title")
  1637. {
  1638. std::string temp = ps->LastData[ps->Depth];
  1639. trimLeadingAndTrailing(temp);
  1640. ps->CurrentDescription.SetTitle(temp);
  1641. }
  1642. else if (name == "version")
  1643. {
  1644. std::string temp = ps->LastData[ps->Depth];
  1645. trimLeadingAndTrailing(temp);
  1646. ps->CurrentDescription.SetVersion(temp);
  1647. }
  1648. else if (name == "documentation-url")
  1649. {
  1650. std::string temp = ps->LastData[ps->Depth];
  1651. trimLeadingAndTrailing(temp);
  1652. ps->CurrentDescription.SetDocumentationURL(temp);
  1653. }
  1654. else if (name == "license")
  1655. {
  1656. std::string temp = ps->LastData[ps->Depth];
  1657. trimLeadingAndTrailing(temp);
  1658. ps->CurrentDescription.SetLicense(temp);
  1659. }
  1660. else if (name == "acknowledgements")
  1661. {
  1662. std::string temp = ps->LastData[ps->Depth];
  1663. trimLeadingAndTrailing(temp);
  1664. ps->CurrentDescription.SetAcknowledgements(temp);
  1665. }
  1666. else if (name == "contributor")
  1667. {
  1668. std::string temp = ps->LastData[ps->Depth];
  1669. trimLeadingAndTrailing(temp);
  1670. ps->CurrentDescription.SetContributor(temp);
  1671. }
  1672. else if (name == "location")
  1673. {
  1674. std::string temp = ps->LastData[ps->Depth];
  1675. trimLeadingAndTrailing(temp);
  1676. ps->CurrentDescription.SetLocation(temp);
  1677. }
  1678. else if (name == "description")
  1679. {
  1680. std::string temp = ps->LastData[ps->Depth];
  1681. replaceSubWithSub(temp, "\"", "'");
  1682. //replaceSubWithSub(temp, "\n", " ");
  1683. trimLeadingAndTrailing(temp);
  1684. if (!group && !parameter)
  1685. {
  1686. ps->CurrentDescription.SetDescription(temp);
  1687. }
  1688. else if (group && !parameter)
  1689. {
  1690. group->SetDescription(temp);
  1691. }
  1692. else
  1693. {
  1694. parameter->SetDescription(temp);
  1695. }
  1696. }
  1697. else if (parameter && (name == "element"))
  1698. {
  1699. std::string temp = ps->LastData[ps->Depth];
  1700. trimLeadingAndTrailing(temp);
  1701. parameter->GetElements().push_back(temp);
  1702. }
  1703. else if (parameter && (name == "default"))
  1704. {
  1705. std::string temp = ps->LastData[ps->Depth];
  1706. trimLeadingAndTrailing(temp);
  1707. parameter->SetDefault(temp);
  1708. }
  1709. else if (parameter && (name == "channel"))
  1710. {
  1711. std::string temp = ps->LastData[ps->Depth];
  1712. trimLeadingAndTrailing(temp);
  1713. parameter->SetChannel(temp);
  1714. }
  1715. else if (parameter && (name == "index"))
  1716. {
  1717. if (!parameter->GetLongFlag().empty() || !parameter->GetFlag().empty() )
  1718. {
  1719. std::string error("ModuleDescriptionParser Error: <"
  1720. + std::string(name)
  1721. + "> cannot be specified because a <longflag> and/or <flag> has been specified for this parameter."
  1722. + std::string("\""));
  1723. if (ps->ErrorDescription.size() == 0)
  1724. {
  1725. ps->ErrorDescription = error;
  1726. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  1727. ps->Error = true;
  1728. }
  1729. if (!ps->OpenTags.empty())
  1730. {
  1731. ps->OpenTags.pop();
  1732. ps->Depth--;
  1733. }
  1734. return;
  1735. }
  1736. std::string temp = ps->LastData[ps->Depth];
  1737. trimLeadingAndTrailing(temp);
  1738. parameter->SetIndex(temp);
  1739. }
  1740. else if (parameter && (name == "constraints"))
  1741. {
  1742. parameter->SetConstraints(name);
  1743. }
  1744. else if (parameter && (name == "minimum"))
  1745. {
  1746. std::string temp = ps->LastData[ps->Depth];
  1747. trimLeadingAndTrailing(temp);
  1748. parameter->SetMinimum(temp);
  1749. }
  1750. else if (parameter && (name == "maximum"))
  1751. {
  1752. std::string temp = ps->LastData[ps->Depth];
  1753. trimLeadingAndTrailing(temp);
  1754. parameter->SetMaximum(temp);
  1755. }
  1756. else if (parameter && (name == "step"))
  1757. {
  1758. std::string temp = ps->LastData[ps->Depth];
  1759. trimLeadingAndTrailing(temp);
  1760. parameter->SetStep(temp);
  1761. }
  1762. else if(name != "executable")
  1763. {
  1764. std::string error("ModuleDescriptionParser Error: Unrecognized element <" + name + std::string("> was found."));
  1765. if (ps->ErrorDescription.size() == 0)
  1766. {
  1767. ps->ErrorDescription = error;
  1768. ps->ErrorLine = XML_GetCurrentLineNumber(ps->Parser);
  1769. ps->Error = true;
  1770. }
  1771. }
  1772. }
  1773. // ===============================================================================
  1774. // ----------------------------------------------------------------------------
  1775. ctkModuleDescription* ctkModuleDescription::parse(QIODevice* device)
  1776. {
  1777. ctkModuleDescription* moduleDescription = new ctkModuleDescription();
  1778. ctkModuleDescriptionParser parser(device, moduleDescription);
  1779. try
  1780. {
  1781. // Verify the xml is correct
  1782. parser.validate();
  1783. parser.doParse();
  1784. }
  1785. catch(...)
  1786. {
  1787. delete moduleDescription;
  1788. throw;
  1789. }
  1790. return moduleDescription;
  1791. }