Generate proxy makefiles in output tree.
[reactos.git] / reactos / tools / rbuild / XML.h
1 #ifndef XML_H
2 #define XML_H
3
4 #include "pch.h"
5
6 class XMLElement;
7
8 extern std::string working_directory;
9
10 void
11 InitWorkingDirectory();
12
13 #ifdef _MSC_VER
14 unsigned __int64
15 #else
16 unsigned long long
17 #endif
18 filelen ( FILE* f );
19
20 class Path
21 {
22 std::vector<std::string> path;
23 public:
24 Path(); // initializes path to getcwd();
25 Path ( const Path& cwd, const std::string& filename );
26 std::string Fixup ( const std::string& filename, bool include_filename ) const;
27
28 std::string RelativeFromWorkingDirectory ();
29 static std::string RelativeFromWorkingDirectory ( const std::string& path );
30
31 static void Split ( std::vector<std::string>& out,
32 const std::string& path,
33 bool include_last );
34 };
35
36 class XMLInclude
37 {
38 public:
39 XMLElement *e;
40 Path path;
41 std::string topIncludeFilename;
42 bool fileExists;
43
44 XMLInclude ( XMLElement* e_, const Path& path_, const std::string topIncludeFilename_ )
45 : e ( e_ ), path ( path_ ), topIncludeFilename ( topIncludeFilename_ )
46 {
47 }
48 };
49
50 class XMLIncludes : public std::vector<XMLInclude*>
51 {
52 public:
53 ~XMLIncludes();
54 };
55
56 class XMLFile
57 {
58 friend class XMLElement;
59 public:
60 XMLFile();
61 void close();
62 bool open(const std::string& filename);
63 void next_token();
64 bool next_is_text();
65 bool more_tokens();
66 bool get_token(std::string& token);
67 const std::string& filename() { return _filename; }
68 std::string Location() const;
69
70 private:
71 std::string _buf, _filename;
72
73 const char *_p, *_end;
74 };
75
76
77 class XMLAttribute
78 {
79 public:
80 std::string name;
81 std::string value;
82
83 XMLAttribute();
84 XMLAttribute ( const std::string& name_, const std::string& value_ );
85 XMLAttribute ( const XMLAttribute& );
86 XMLAttribute& operator = ( const XMLAttribute& );
87 };
88
89
90 class XMLElement
91 {
92 public:
93 XMLFile* xmlFile;
94 std::string location;
95 std::string name;
96 std::vector<XMLAttribute*> attributes;
97 XMLElement* parentElement;
98 std::vector<XMLElement*> subElements;
99 std::string value;
100
101 XMLElement ( XMLFile* xmlFile,
102 const std::string& location );
103 ~XMLElement();
104 bool Parse(const std::string& token,
105 bool& end_tag);
106 void AddSubElement ( XMLElement* e );
107 XMLAttribute* GetAttribute ( const std::string& attribute,
108 bool required);
109 const XMLAttribute* GetAttribute ( const std::string& attribute,
110 bool required) const;
111 };
112
113 XMLElement*
114 XMLLoadFile ( const std::string& filename,
115 const Path& path,
116 XMLIncludes& includes );
117
118 #endif // XML_H