-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtinyXmlHelper.cpp
More file actions
211 lines (202 loc) · 5.12 KB
/
tinyXmlHelper.cpp
File metadata and controls
211 lines (202 loc) · 5.12 KB
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
//#include <tinyxml.h>
//#include <string>
//#include <vector>
//#include <map>
//class tinyXmlHelper
//{
//public:
// tinyXmlHelper(const TiXmlElement& root);
// ~tinyXmlHelper();
// void parse(const char* name, int& value)
// {
// root.Attribute(name, value);
// }
// void parse(const char* name, double& value)
// {
// root.Attribute(name, value);
// }
// void parse(const char* name, float& value)
// {
// root.QueryFloatAttribute(name, &value);
// }
// void parse(const char* name, std::string& value)
// {
// const char* attr = root.Attribute(name);
// if (attr)
// {
// value = attr;
// }
// value = "";
// }
// /*
// 单个元素的parse,属性名从root的“key”属性读出。结构为:
// <root key="aKey">
// <item aKey="3"/>
// <item aKey="4"/>
// <item aKey="5"/>
// </root>
// */
// template<typename T>
// void parse(const TiXmlElement& root, std::vector<T>& vec)
// {
// for(TiXmlElement* child = root.FirstChildElement("item"); child != NULL; child = child->NextSiblingElement())
// {
// tinyXmlHelper helper(child);
// T v;
// helper.parse(root.Attribute(key), v);
// vec.push_back(v);
// }
// }
// //多元素的parse,包括嵌套的单元素vector等,也算是多元素的
// //征途2那边,是将所有的元素都封装了下,那么,这2个vector的parse自然就可以统一起来了。但是我没有这么做,现在就显得有些重复了
// /*
// 单个元素的parse,属性名从root的“key”属性读出。结构为:
// <root key="aKey">
// <aKey prop1="3" prop2="aaa"/>
// <aKey prop1="4" prop2="aaa"/>
// <aKey prop1="5" prop2="aaa"/>
// </root>
// */
// template<typename T>
// void parse(const TiXmlElement& root, std::vector<T>& vec)
// {
// for(TiXmlElement* child = root.FirstChildElement(root.Attribute("key")); child != NULL; child = child->NextSiblingElement())
// {
// tinyXmlHelper helper(child);
// T v;
// v.parse(child);
// vec.push_back(v);
// }
// }
// //单个元素key,单元素value的parse
// /*
// 单个元素的parse,属性名从root的“key”属性读出。结构为:
// <root keyName="aKey" valueName="aValue">
// <item aKey="3" aValue="aaa"/>
// <item aKey="4" aValue="aaa"/>
// <item aKey="5" aValue="aaa"/>
// </root>
// */
// template<typename KeyType, typename ValueType>
// void parse(const TiXmlElement& root, std::map<KeyType, ValueType>& map)
// {
// for(TiXmlElement* child = root.FirstChildElement("item"); child != NULL; child = child->NextSiblingElement())
// {
// tinyXmlHelper helper(child);
// KeyType key;
// helper.parse(keyName, key);
// ValueType value;
// helper.parse(valueName, value);
// map[key] = value;
// }
// }
// //单个元素key,多元素value的parse
// /*
// 单个元素的parse,属性名从root的“key”属性读出。结构为:
// <root keyName="aKey" valueName="aValue">
// <item aKey="p1">
// <aValue prop1="3" prop2="lish" prop3="name"/>
// </item>
// <item aKey="p2">
// <aValue prop1="3" prop2="lish" prop3="name"/>
// </item>
// <item aKey="p3">
// <aValue prop1="3" prop2="lish" prop3="name"/>
// </item>
// </root>
// */
// template<typename KeyType, typename ValueType>
// void parse(const TiXmlElement& root, std::map<KeyType, ValueType>& map)
// {
// for(TiXmlElement* child = root.FirstChildElement(root.Attribute("keyName")); child != NULL; child = child->NextSiblingElement())
// {
// tinyXmlHelper helper(child);
// KeyType key;
// helper.parse(keyName, key);
// ValueType value;
// value.parse(root);
// map[key] = value;
// }
// }
//};
//template<typename T>
//class ValueWrapper
//{
//public:
// ValueWrapper(T& value)m_value(value){}
// ~ValueWrapper();
// T& parse(const TiXmlElement& root, const char* name)
// {
// m_value.parse(root.FirstChildElement(name));
// return m_value;
// }
//protected:
// T& m_value;
//};
////特化一些版本供使用
//template<>
//class ValueWrapper
//{
//public:
// ValueWrapper(int& value)m_value(value){}
// ~ValueWrapper();
// int& parse(const TiXmlElement& root, const char* name)
// {
// root.Attribute(name, &m_value);
// return m_value;
// }
//protected:
// T& m_value;
//};
//template<>
//class ValueWrapper
//{
//public:
// ValueWrapper(double& value)m_value(value){}
// ~ValueWrapper();
// double& parse(const TiXmlElement& root, const char* name)
// {
// root.Attribute(name, &m_value);
// return m_value;
// }
//protected:
// T& m_value;
//};
//template<>
//class ValueWrapper
//{
//public:
// ValueWrapper(float& value)m_value(value){}
// ~ValueWrapper();
// float& parse(const TiXmlElement& root, const char* name)
// {
// root.QueryFloatAttribute(name, &m_value);
// return m_value;
// }
//protected:
// T& m_value;
//};
//struct aStruct
//{
// int a;
// double b;
// struct anInner
// {
// std::string s;
// void parse(const TiXmlElement& root)
// {
// tinyXmlHelper helper(root);
// helper.parse("s", s);
// }
// };
// anInner ai;
// std::vector<int> vLists;
// void parse(const TiXmlElement& root)
// {
// tinyXmlHelper helper(root);
// helper.parse("a", a);
// helper.parse("b", b);
// ai.parse(root.FirstChildElement("ai"));
// helper.parse(root.FirstChildElement("vLists"), "value", vLists));
// }
//};