cmWIXSourceWriter.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #ifndef cmWIXSourceWriter_h
  4. #define cmWIXSourceWriter_h
  5. #include "cmCPackLog.h"
  6. #include "cmsys/FStream.hxx"
  7. #include <string>
  8. #include <vector>
  9. /** \class cmWIXSourceWriter
  10. * \brief Helper class to generate XML WiX source files
  11. */
  12. class cmWIXSourceWriter
  13. {
  14. public:
  15. enum GuidType
  16. {
  17. WIX_GENERATED_GUID,
  18. CMAKE_GENERATED_GUID
  19. };
  20. enum RootElementType
  21. {
  22. WIX_ELEMENT_ROOT,
  23. INCLUDE_ELEMENT_ROOT
  24. };
  25. cmWIXSourceWriter(cmCPackLog* logger, std::string const& filename,
  26. GuidType componentGuidType,
  27. RootElementType rootElementType = WIX_ELEMENT_ROOT);
  28. ~cmWIXSourceWriter();
  29. void BeginElement(std::string const& name);
  30. void EndElement(std::string const& name);
  31. void AddTextNode(std::string const& text);
  32. void AddProcessingInstruction(std::string const& target,
  33. std::string const& content);
  34. void AddAttribute(std::string const& key, std::string const& value);
  35. void AddAttributeUnlessEmpty(std::string const& key,
  36. std::string const& value);
  37. std::string CreateGuidFromComponentId(std::string const& componentId);
  38. protected:
  39. cmCPackLog* Logger;
  40. private:
  41. enum State
  42. {
  43. DEFAULT,
  44. BEGIN
  45. };
  46. void WriteXMLDeclaration();
  47. void Indent(size_t count);
  48. static std::string EscapeAttributeValue(std::string const& value);
  49. cmsys::ofstream File;
  50. State State;
  51. std::vector<std::string> Elements;
  52. std::string SourceFilename;
  53. GuidType ComponentGuidType;
  54. };
  55. #endif