forked from ParadoxGameConverters/commonItems
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParserHelpers.h
265 lines (180 loc) · 6.26 KB
/
ParserHelpers.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#ifndef PARSER_HELPERS_H
#define PARSER_HELPERS_H
// Functions for reading common structures within Paradox Script.
#include "Parser.h"
#include <concepts>
#include <map>
#include <vector>
namespace commonItems
{
void ignoreItem(const std::string& unused, std::istream& theStream);
void ignoreAndLogItem(const std::string& keyword, std::istream& theStream);
void ignoreObject(const std::string& unused, std::istream& theStream);
void ignoreString(const std::string& unused, std::istream& theStream);
/*function template only enabled for integer types
* converts string to integer types, e.g.: unsigned int value = stringToInteger<unsigned int>("420");
* works for:
* signed char stringToInteger<signed char>(const std::string& str, bool skipPartialMatchWarning);
* unsigned char stringToInteger<unsigned char>(const std::string& str, bool skipPartialMatchWarning);
* short stringToInteger<short>(const std::string& str, bool skipPartialMatchWarning);
* unsigned short stringToInteger<unsigned short>(const std::string& str, bool skipPartialMatchWarning);
* int stringToInteger<int>(const std::string& str, bool skipPartialMatchWarning);
* unsigned int stringToInteger<unsigned int>(const std::string& str, bool skipPartialMatchWarning);
* long stringToInteger<long>(const std::string& str, bool skipPartialMatchWarning);
* unsigned long stringToInteger<unsigned long>(const std::string& str, bool skipPartialMatchWarning);
* long long stringToInteger<long long>(const std::string& str, bool skipPartialMatchWarning);
* unsigned long long stringToInteger<unsigned long long>(const std::string& str, bool skipPartialMatchWarning);
*/
template <std::integral T> [[nodiscard]] T stringToInteger(const std::string& str, bool skipPartialMatchWarning = false);
[[nodiscard]] double stringToDouble(const std::string& str);
[[nodiscard]] std::vector<int> getInts(std::istream& theStream);
[[nodiscard]] std::vector<long long> getLlongs(std::istream& theStream);
[[nodiscard]] std::vector<unsigned long long> getULlongs(std::istream& theStream);
[[nodiscard]] std::vector<double> getDoubles(std::istream& theStream);
[[nodiscard]] std::vector<std::string> getStrings(std::istream& theStream);
[[nodiscard]] int getInt(std::istream& theStream);
[[nodiscard]] long long getLlong(std::istream& theStream);
[[nodiscard]] unsigned long long getULlong(std::istream& theStream);
[[nodiscard]] double getDouble(std::istream& theStream);
[[nodiscard]] std::string getString(std::istream& theStream);
class intList: parser
{
public:
explicit intList(std::istream& theStream);
[[nodiscard]] std::vector<int> getInts() const { return integers; }
private:
std::vector<int> integers;
};
class llongList: parser
{
public:
explicit llongList(std::istream& theStream);
[[nodiscard]] std::vector<long long> getLlongs() const { return llongs; }
private:
std::vector<long long> llongs;
};
class ullongList: parser
{
public:
explicit ullongList(std::istream& theStream);
[[nodiscard]] std::vector<unsigned long long> getULlongs() const { return ullongs; }
private:
std::vector<unsigned long long> ullongs;
};
class singleInt: parser
{
public:
explicit singleInt(std::istream& theStream);
[[nodiscard]] int getInt() const noexcept { return theInt; }
private:
int theInt = 0;
};
class singleLlong: parser
{
public:
explicit singleLlong(std::istream& theStream);
[[nodiscard]] long long getLlong() const noexcept { return theLongLong; }
private:
long long theLongLong = 0;
};
class singleULlong: parser
{
public:
explicit singleULlong(std::istream& theStream);
[[nodiscard]] unsigned long long getULlong() const noexcept { return theUnsignedLongLong; }
private:
unsigned long long theUnsignedLongLong = 0;
};
// Parses an object where each entry is a simple assignment, key = value.
// Nested objects, key = { ... }, are ignored.
class simpleObject: parser
{
public:
explicit simpleObject(std::istream& theStream);
[[nodiscard]] std::string getValue(const std::string& key) const;
[[nodiscard]] int getValueAsInt(const std::string& key) const;
private:
std::map<std::string, std::string> values;
};
class doubleList: parser
{
public:
explicit doubleList(std::istream& theStream);
[[nodiscard]] std::vector<double> getDoubles() const { return doubles; }
private:
std::vector<double> doubles;
};
class blobList: parser
{
public:
explicit blobList(std::istream& theStream);
[[nodiscard]] std::vector<std::string> getBlobs() const { return blobs; }
private:
std::vector<std::string> blobs;
};
class singleDouble: parser
{
public:
explicit singleDouble(std::istream& theStream);
[[nodiscard]] double getDouble() const noexcept { return theDouble; }
private:
double theDouble = 0.0;
};
class stringList: parser
{
public:
explicit stringList(std::istream& theStream);
[[nodiscard]] std::vector<std::string> getStrings() const { return strings; }
private:
std::vector<std::string> strings;
};
class singleString: parser
{
public:
explicit singleString(std::istream& theStream);
[[nodiscard]] std::string getString() const { return theString; }
private:
std::string theString;
};
class stringOfObject: parser
{
public:
explicit stringOfObject(std::istream& theStream);
[[deprecated("Use stringOfItem")]] [[nodiscard]] std::string getString() const { return theString; }
private:
std::string theString;
};
class stringOfItem: parser
{
public:
explicit stringOfItem(std::istream& theStream);
[[nodiscard]] std::string getString() const { return theString; }
private:
std::string theString;
};
class stringsOfItems: parser
{
public:
explicit stringsOfItems(std::istream& theStream);
[[nodiscard]] std::vector<std::string> getStrings() const { return theStrings; }
private:
std::vector<std::string> theStrings;
};
class stringsOfItemNames: parser
{
public:
explicit stringsOfItemNames(std::istream& theStream);
[[nodiscard]] std::vector<std::string> getStrings() const { return theStrings; }
private:
std::vector<std::string> theStrings;
};
class assignments: parser
{
public:
explicit assignments(std::istream& theStream);
[[nodiscard]] std::map<std::string, std::string> getAssignments() const { return theAssignments; }
private:
std::map<std::string, std::string> theAssignments;
};
} // namespace commonItems
#endif // PARSER_HELPERS_H