-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathmain.cpp
52 lines (41 loc) · 1005 Bytes
/
main.cpp
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
#include "MetaGenerator.h"
#include "TypeInfoGenerator.h"
#include <iostream>
#include <sstream>
#include <fstream>
using namespace Ubpa::USRefl;
using namespace std;
string ReadFileIntoString(const char* filename) {
ifstream ifile(filename);
if (!ifile.is_open())
return "";
ostringstream buf;
char ch;
while (buf && ifile.get(ch))
buf.put(ch);
return buf.str();
}
int main(int argc, char** argv) {
if (argc != 3) {
cerr << "arguments error" << endl;
return 1;
}
string inputPath = argv[1];
string outputPath = argv[2];
auto code = ReadFileIntoString(inputPath.c_str());
MetaGenerator metaGenerator;
TypeInfoGenerator typeinfoGenerator;
auto typeMetas = metaGenerator.Parse(code);
auto rst = typeinfoGenerator.Generate(typeMetas);
auto curout = ReadFileIntoString(inputPath.c_str());
if (curout == rst)
return 0;
ofstream out(outputPath);
if (!out.is_open()) {
cerr << "open fail : " << outputPath << endl;
return 1;
}
out << rst;
out.close();
return 0;
}