Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Kitware
GitHub Repository: Kitware/CMake
Path: blob/master/Source/CPack/WiX/cmWIXPatchParser.h
5017 views
1
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2
file LICENSE.rst or https://cmake.org/licensing for details. */
3
#pragma once
4
5
#include <map>
6
#include <memory>
7
#include <vector>
8
9
#include "cmCPackLog.h"
10
#include "cmXMLParser.h"
11
12
struct cmWIXPatchNode
13
{
14
enum Type
15
{
16
TEXT,
17
ELEMENT
18
};
19
20
virtual ~cmWIXPatchNode();
21
22
virtual Type type() = 0;
23
};
24
25
struct cmWIXPatchText : public cmWIXPatchNode
26
{
27
virtual Type type();
28
29
std::string text;
30
};
31
32
struct cmWIXPatchElement : cmWIXPatchNode
33
{
34
virtual Type type();
35
36
cmWIXPatchElement();
37
38
cmWIXPatchElement(cmWIXPatchElement const&) = delete;
39
cmWIXPatchElement const& operator=(cmWIXPatchElement const&) = delete;
40
41
~cmWIXPatchElement();
42
43
using child_list_t = std::vector<std::unique_ptr<cmWIXPatchNode>>;
44
using attributes_t = std::map<std::string, std::string>;
45
46
std::string name;
47
child_list_t children;
48
attributes_t attributes;
49
};
50
51
/** \class cmWIXPatchParser
52
* \brief Helper class that parses XML patch files (CPACK_WIX_PATCH_FILE)
53
*/
54
class cmWIXPatchParser : public cmXMLParser
55
{
56
public:
57
using fragment_map_t = std::map<std::string, cmWIXPatchElement>;
58
59
cmWIXPatchParser(fragment_map_t& Fragments, cmCPackLog* logger);
60
61
private:
62
virtual void StartElement(std::string const& name, char const** atts);
63
64
void StartFragment(char const** attributes);
65
66
virtual void EndElement(std::string const& name);
67
68
virtual void CharacterDataHandler(char const* data, int length);
69
70
virtual void ReportError(int line, int column, char const* msg);
71
72
void ReportValidationError(std::string const& message);
73
74
bool IsValid() const;
75
76
cmCPackLog* Logger;
77
78
enum ParserState
79
{
80
BEGIN_DOCUMENT,
81
BEGIN_FRAGMENTS,
82
INSIDE_FRAGMENT
83
};
84
85
ParserState State;
86
87
bool Valid;
88
89
fragment_map_t& Fragments;
90
91
std::vector<cmWIXPatchElement*> ElementStack;
92
};
93
94