ctkSlicerModuleReader.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. #ifndef __ctkSlicerModuleReader_h
  15. #define __ctkSlicerModuleReader_h
  16. // Qt includes
  17. #include <QRegExp>
  18. #include <QStack>
  19. #include <QXmlAttributes>
  20. #include <QXmlDefaultHandler>
  21. // CTK includes
  22. #include "ctkModuleDescriptionReader.h"
  23. #include <org_commontk_slicermodule_Export.h>
  24. /**
  25. * Reader of Slicer Module XML description
  26. * Freely inspired from
  27. * Slicer/Libs/SlicerExecutionModel/ModuleDescriptionParser/ModuleDescriptionParser.cxx
  28. */
  29. class org_commontk_slicermodule_EXPORT ctkSlicerModuleReader : public ctkModuleDescriptionReader
  30. {
  31. Q_OBJECT
  32. public:
  33. virtual void update();
  34. bool validate()const;
  35. };
  36. /**
  37. * Utility class to parse the Slicer Module XML descriptions using the
  38. * SAX interface.
  39. */
  40. class ctkSlicerModuleHandler: public QXmlDefaultHandler
  41. {
  42. public:
  43. ctkSlicerModuleHandler();
  44. bool characters(const QString& ch);
  45. virtual bool endElement(const QString& namespaceURI, const QString& localName, const QString& qName);
  46. virtual bool startElement(const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& atts );
  47. void setModuleDescription(ctkModuleDescription* moduleDescription);
  48. ctkModuleDescription* moduleDescription()const;
  49. protected:
  50. bool startExecutableElement(const QString& namespaceURI, const QString& localName,
  51. const QString& name, const QXmlAttributes& atts);
  52. bool startGroupElement(const QString& namespaceURI, const QString& localName,
  53. const QString& name, const QXmlAttributes& atts);
  54. bool startParameterElement(const QString& namespaceURI, const QString& localName,
  55. const QString& name, const QXmlAttributes& atts);
  56. bool endExecutableElement(const QString& namespaceURI, const QString& localName,
  57. const QString& name);
  58. bool endGroupElement(const QString& namespaceURI, const QString& localName,
  59. const QString& name);
  60. bool endParameterElement(const QString& namespaceURI, const QString& localName,
  61. const QString& name);
  62. ctkModuleDescription* ModuleDescription;
  63. struct ParserState{
  64. ctkModuleParameter* CurrentParameter;
  65. ctkModuleParameterGroup* CurrentGroup;
  66. QString CurrentText;
  67. int InExecutable;
  68. int InGroup;
  69. int InParameter;
  70. };
  71. ParserState State;
  72. QRegExp ParamValidator;
  73. };
  74. #endif