-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto_table.h
103 lines (85 loc) · 3.46 KB
/
auto_table.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
#ifndef _AUTO_TABLE_H_
#define _AUTO_TABLE_H_
#include <map>
#include <vector>
#include "common.h"
using std::map;
using std::vector;
struct tagVarInfo {
string strVarPre; //变量前缀
string strVarType; //C++变量类型
tagVarInfo() {}
tagVarInfo(const tagVarInfo& other) {
strVarPre = other.strVarPre;
strVarType = other.strVarType;
}
tagVarInfo& operator=(const tagVarInfo& other) {
if (this == &other)
return *this;
strVarPre = other.strVarPre;
strVarType = other.strVarType;
return *this;
}
};
struct tagRow {
//数据库列信息
uint32 uiLength;
string strType;
string strRowName;
//根据数据库列信息查找得到的C++信息
tagVarInfo stVarInfo;
tagRow() {
uiLength = 0;
}
tagRow(const tagRow& other) {
uiLength = other.uiLength;
strType = other.strType;
strRowName = other.strRowName;
stVarInfo = other.stVarInfo;
}
tagRow& operator=(const tagRow& other) {
if (this == &other)
return *this;
uiLength = other.uiLength;
strType = other.strType;
strRowName = other.strRowName;
stVarInfo = other.stVarInfo;
return *this;
}
};
struct tagTable {
string strTable;
vector<tagRow> vecRow;
};
class AutoTable {
public:
AutoTable() {}
~AutoTable() {}
//strInPut:输入sql建表语句;strOutPutInc:输出数据库操作自动化类头文件;strOutPutSrc:输出数据库操作自动化类源文件,
void Analysis(const char* szFile);
private:
void Init();
void AddVarInfo(const char* szRowType, const char* szVarPre, const char* szVarType);
//过滤每行的所有tab键,并且过滤行首空格键
int32 SplitStringByEnter(const string& strInput, vector<string>& vecContent);
int32 GetTableFromVec(vector<string>& vecContent, vector<tagTable>& vecTable);
void SplitStringByTab(string& strLine); //过滤tab键
int32 AnalysisTable(const tagTable& stTable, string& strOutPutInc, string& strOutPutSrc);
void CreateDestruct(const tagTable& stTable, string& strOutPutInc, string& strOutPutSrc);
void CreateDefaultConstructor(const tagTable& stTable, string& strOutPutInc, string& strOutPutSrc);
void CreateCopyConstructor(const tagTable& stTable, string& strOutPutInc, string& strOutPutSrc);
void CreateGetRowName(const tagTable& stTable, string& strOutPutInc, string& strOutPutSrc);
void CreateTableName(const tagTable& stTable, string& strOutPutInc, string& strOutPutSrc);
void CreateSetRowValue(const tagTable& stTable, string& strOutPutInc, string& strOutPutSrc);
void CreateGetRowValue(const tagTable& stTable, string& strOutPutInc, string& strOutPutSrc);
void CreateHas(const tagTable& stTable, string& strOutPutInc, string& strOutPutSrc);
void CreateClearHas(const tagTable& stTable, string& strOutPutInc, string& strOutPutSrc);
void CreateOperatorEqual(const tagTable& stTable, string& strOutPutInc, string& strOutPutSrc);
void CreateGetCount(const tagTable& stTable, string& strOutPutInc, string& strOutPutSrc);
void CreateSerialize(const tagTable& stTable, string& strOutPutInc, string& strOutPutSrc);
void CreateClassVariables(const tagTable& stTable, string& strOutPutInc, string& strOutPutSrc);
void CreateIsValid(const tagTable& stTable, string& strOutPutInc, string& strOutPutSrc);
private:
map<string, tagVarInfo> m_mapVarInfo;
};
#endif