PGE Engine
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros Pages
smbx64_macro.h
1 #ifndef SMBX64_MACRO_H
2 #define SMBX64_MACRO_H
3 
4 /*
5  There are a special macroses used to organize
6  SMBX64 specific file read functions.
7 
8  Skeleton of read file function:
9 
10  #include "file_formats.h"
11  #include "file_strlist.h"
12  #include "smbx64.h"
13  #include "smbx64_macro.h"
14  #include <iostream>
15 
16  void readFunc(QString rawData)
17  {
18  //Must be at begin of file
19  SMBX64_File(rawData);
20 
21  //...
22 
23  std::cout << "File parsed!";
24  return;
25  badfile:
26  std::cout << "File format is wrong!\n"<<
27  << "line :" << str_count << ", file format version: "<<file_format
28  << "Line data: "<< line;
29  }
30 
31 */
32 
33 /********************Read function begins***********************/
34 //for Header readers.
35 //Use it if you want read file partially
36 //(you must create QTextStream in(&fstream); !!!)
37 #define SMBX64_FileBegin() int str_count=0;/*Line Counter*/\
38  int file_format=0; /*File format number*/\
39  PGESTRING line; /*Current Line data*/
40 
41 //for entire data readers.
42 //Use it if you want parse entire file data
43 #define SMBX64_File(raw) FileStringList in;\
44  in.addData( raw );\
45  SMBX64_FileBegin()
46 
47 //Jump to next line
48 #define nextLine() str_count++;line = in.readLine();
49 
50 #define parseLine(validate, target, converted) if( validate ) \
51  goto badfile;\
52  else target=converted;
53 
54 //ValueTypes
55 #define strVar(target, line) parseLine( SMBX64::qStr(line), target, SMBX64::StrToStr(line))
56 #define UIntVar(target, line) parseLine( SMBX64::uInt(line), target, toInt(line))
57 #define SIntVar(target, line) parseLine( SMBX64::sInt(line), target, toInt(line))
58 #define wBoolVar(target, line) parseLine( SMBX64::wBool(line), target, SMBX64::wBoolR(line))
59 #ifdef PGE_FILES_QT
60 #define SFltVar(target, line) parseLine( SMBX64::sFloat(line), target, line.replace(QChar(','), QChar('.')).toFloat());
61 #else
62 #define SFltVar(target, line) parseLine( SMBX64::sFloat(line), target, ([line]() -> float { std::string newx=line;PGE_FileFormats_misc::replaceAll(newx, ",", "."); return toFloat(newx); })() )
63 #endif
64 
65 #ifdef PGE_FILES_QT
66 #define strVarMultiLine(target, line) {\
67 bool first=true;\
68 while( (first && (line.size()==1)&&(line=="\""))||(!line.endsWith('\"')))\
69 {\
70  first=false;\
71  line.append('\n');\
72  str_count++;line.append(in.readLine());\
73  if(line.endsWith('\"'))\
74  break;\
75 }\
76 strVar(target, line);\
77 }
78 #else
79 #define strVarMultiLine(target, line) {\
80 bool first=true;\
81 while( (first && (line.size()==1)&&(line=="\""))||(!PGE_FileFormats_misc::hasEnding(line, "\"")))\
82 {\
83  first=false;\
84  line.append("\n");\
85  str_count++;line.append(in.readLine());\
86  if(PGE_FileFormats_misc::hasEnding(line, "\""))\
87  break;\
88 }\
89 strVar(target, line);\
90 }
91 #endif
92 
93 //Version comparison
94 #define ge(v) file_format>=v
95 #define gt(v) file_format>v
96 #define le(v) file_format<=v
97 #define lt(v) file_format<v
98 
99 #endif // SMBX64_MACRO_H
100