ctkSlicerModuleReader.h 3.2 KB

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