forked from WohlSoft/PGE-File-Library-STL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpge_x_macro.h
181 lines (161 loc) · 8 KB
/
pge_x_macro.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
/*
* PGE File Library - a library to process file formats, part of Moondust project
*
* Copyright (c) 2014-2022 Vitaly Novichkov <[email protected]>
*
* The MIT License (MIT)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/*!
* \file pge_x_macro.h
*
* \brief Contains helper macroses for making PGE-X format based parsers
*
*/
#pragma once
#ifndef PGE_X_MACRO_H
#define PGE_X_MACRO_H
/*! \def PGEX_FileBegin()
\brief Placing at begin of the parsing function
*/
#define PGEX_FileBegin() int str_count=0; /*Line Counter*/\
PGESTRING line; /*Current Line data*/
/*! \def PGEX_FileParseTree(raw)
\brief Parse PGE-X Tree from raw data
*/
#define PGEX_FileParseTree(raw) PGEFile pgeX_Data(raw);\
if( !pgeX_Data.buildTreeFromRaw() )\
{\
errorString = pgeX_Data.lastError();\
goto badfile;\
}
/*! \def PGEX_FetchSection()
\brief Prepare to fetch all data from specified section
*/
#define PGEX_FetchSection() for(pge_size_t section=0; section < pgeX_Data.dataTree.size(); section++)
/*! \def PGEX_FetchSection_begin()
\brief Prepare to detect separate data of different sections
*/
#define PGEX_FetchSection_begin() PGEFile::PGEX_Entry &f_section = pgeX_Data.dataTree[section];\
if(IsEmpty(f_section.name)) continue;
/*! \def PGEX_Section(sct)
\brief Defines block of fields for section of specified name
*/
#define PGEX_Section(sct) else if(f_section.name == sct)
/*! \def PGEX_SectionBegin(stype)
\brief Run syntax of raw data in this section for specified data type
*/
#define PGEX_SectionBegin(stype) if(f_section.type != stype) \
{ \
errorString=PGESTRING("Wrong section data syntax:\nSection ["+f_section.name+"]");\
goto badfile;\
}
/*! \def PGEX_Items()
\brief Prepare to read items from this section
*/
#define PGEX_Items() for(pge_size_t sdata = 0; sdata < f_section.data.size(); sdata++)
/*! \def PGEX_ItemBegin(stype)
\brief Declares block with a list of values
*/
#define PGEX_ItemBegin(stype) if(f_section.data[sdata].type != stype) \
{ \
errorString=PGESTRING("Wrong data item syntax:\nSection ["+f_section.name+"]\nData line "+fromNum(sdata));\
goto badfile;\
}\
PGEFile::PGEX_Item x = f_section.data[sdata];
/*! \def PGEX_Values()
\brief Declares block with a list of values
*/
#define PGEX_Values() for(pge_size_t sval=0; sval < x.values.size(); sval++)
/*! \def PGEX_ValueBegin()
\brief Initializes getting of the values
*/
#define PGEX_ValueBegin() PGEFile::PGEX_Val v = x.values[sval];\
errorString=PGESTRING("Wrong value syntax\nSection ["+f_section.name+ \
"]\nData line "+fromNum(sdata) \
+"\nMarker "+v.marker+"\nValue "+v.value);\
if(IsEmpty(v.marker)) continue;
/*! \def PGEX_StrVal(Mark, targetValue)
\brief Parse Plain text string value by requested Marker and write into target variable
*/
#define PGEX_StrVal(Mark, targetValue) else if(v.marker==Mark) { if(PGEFile::IsQoutedString(v.value)) \
targetValue = PGEFile::X2STRING(v.value); \
else goto badfile; }
/*! \def PGEX_StrArrVal(Mark, targetValue)
\brief Parse Plain text string array value by requested Marker and write into target variable
*/
#define PGEX_StrArrVal(Mark, targetValue) else if(v.marker==Mark) { bool valid=false;\
targetValue = PGEFile::X2STRArr(v.value, &valid); \
if(!valid) goto badfile; }
/*! \def PGEX_BoolVal(Mark, targetValue)
\brief Parse boolean flag value by requested Marker and write into target variable
*/
#define PGEX_BoolVal(Mark, targetValue) if(v.marker==Mark) { if(PGEFile::IsBool(v.value)) \
targetValue = static_cast<bool>(toInt(v.value) != 0);\
else goto badfile; }
/*! \def PGEX_BoolArrVal(Mark, targetValue)
\brief Parse boolean flags array value by requested Marker and write into target variable
*/
#define PGEX_BoolArrVal(Mark, targetValue) else if(v.marker==Mark) { if(PGEFile::IsBoolArray(v.value)) \
targetValue = PGEFile::X2BollArr(v.value); \
else goto badfile; }
/*! \def PGEX_UIntVal(Mark, targetValue)
\brief Parse unsigned integer value by requested Marker and write into target variable
*/
#define PGEX_USIntVal(Mark, targetValue) if(v.marker==Mark) { if(PGEFile::IsIntU(v.value)) \
targetValue = toInt(v.value);\
else goto badfile; }
/*! \def PGEX_UIntVal(Mark, targetValue)
\brief Parse unsigned integer value by requested Marker and write into target variable
*/
#define PGEX_UIntVal(Mark, targetValue) if(v.marker==Mark) { if(PGEFile::IsIntU(v.value)) \
targetValue = toUInt(v.value);\
else goto badfile; }
/*! \def PGEX_SIntVal(Mark, targetValue)
\brief Parse signed integer value by requested Marker and write into target variable
*/
#define PGEX_SIntVal(Mark, targetValue) if(v.marker==Mark) { if(PGEFile::IsIntS(v.value)) \
targetValue = toInt(v.value);\
else goto badfile; }
/*! \def PGEX_SLongVal(Mark, targetValue)
\brief Parse signed long integer value by requested Marker and write into target variable
*/
#define PGEX_SLongVal(Mark, targetValue) if(v.marker==Mark) { if(PGEFile::IsIntS(v.value)) \
targetValue = toLong(v.value);\
else goto badfile; }
/*! \def PGEX_ULongVal(Mark, targetValue)
\brief Parse unsigned long integer value by requested Marker and write into target variable
*/
#define PGEX_ULongVal(Mark, targetValue) if(v.marker==Mark) { if(PGEFile::IsIntU(v.value)) \
targetValue = toULong(v.value);\
else goto badfile; }
/*! \def PGEX_USLongVal(Mark, targetValue)
\brief Parse unsigned long integer value by requested Marker and write into target variable
*/
#define PGEX_USLongVal(Mark, targetValue) if(v.marker==Mark) { if(PGEFile::IsIntU(v.value)) \
targetValue = toLong(v.value);\
else goto badfile; }
/*! \def PGEX_FloatVal(Mark, targetValue)
\brief Parse floating point value by requested Marker and write into target variable
*/
#define PGEX_FloatVal(Mark, targetValue) if(v.marker==Mark) { if(PGEFile::IsFloat(v.value)) \
targetValue = toDouble(v.value);\
else goto badfile; }
#endif // PGE_X_MACRO_H