cmWIXPatchParser.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #pragma once
  4. #include <map>
  5. #include <memory>
  6. #include <vector>
  7. #include "cmCPackLog.h"
  8. #include "cmXMLParser.h"
  9. struct cmWIXPatchNode
  10. {
  11. enum Type
  12. {
  13. TEXT,
  14. ELEMENT
  15. };
  16. virtual ~cmWIXPatchNode();
  17. virtual Type type() = 0;
  18. };
  19. struct cmWIXPatchText : public cmWIXPatchNode
  20. {
  21. virtual Type type();
  22. std::string text;
  23. };
  24. struct cmWIXPatchElement : cmWIXPatchNode
  25. {
  26. virtual Type type();
  27. cmWIXPatchElement();
  28. cmWIXPatchElement(const cmWIXPatchElement&) = delete;
  29. const cmWIXPatchElement& operator=(const cmWIXPatchElement&) = delete;
  30. ~cmWIXPatchElement();
  31. using child_list_t = std::vector<std::unique_ptr<cmWIXPatchNode>>;
  32. using attributes_t = std::map<std::string, std::string>;
  33. std::string name;
  34. child_list_t children;
  35. attributes_t attributes;
  36. };
  37. /** \class cmWIXPatchParser
  38. * \brief Helper class that parses XML patch files (CPACK_WIX_PATCH_FILE)
  39. */
  40. class cmWIXPatchParser : public cmXMLParser
  41. {
  42. public:
  43. using fragment_map_t = std::map<std::string, cmWIXPatchElement>;
  44. cmWIXPatchParser(fragment_map_t& Fragments, cmCPackLog* logger);
  45. private:
  46. virtual void StartElement(const std::string& name, const char** atts);
  47. void StartFragment(const char** attributes);
  48. virtual void EndElement(const std::string& name);
  49. virtual void CharacterDataHandler(const char* data, int length);
  50. virtual void ReportError(int line, int column, const char* msg);
  51. void ReportValidationError(std::string const& message);
  52. bool IsValid() const;
  53. cmCPackLog* Logger;
  54. enum ParserState
  55. {
  56. BEGIN_DOCUMENT,
  57. BEGIN_FRAGMENTS,
  58. INSIDE_FRAGMENT
  59. };
  60. ParserState State;
  61. bool Valid;
  62. fragment_map_t& Fragments;
  63. std::vector<cmWIXPatchElement*> ElementStack;
  64. };