469_uppsrc.diff
uppsrc/Core/Xmlize.cpp 2013-05-24 21:43:28 +0400 | ||
---|---|---|
178 | 178 |
return AsXML(node); |
179 | 179 |
} |
180 | 180 |
|
181 |
force_inline bool LoadFromXML0(Callback1<XmlIO> xmlize, const String& xml) |
|
182 |
{ |
|
183 |
XmlNode node = ParseXML(xml); |
|
184 |
if(node.GetCount() == 0) |
|
185 |
return false; |
|
186 |
for(int i = 0; i < node.GetCount(); i++) |
|
187 |
if(node.Node(i).IsTag()) { |
|
188 |
Value dummy; |
|
189 |
xmlize(XmlIO(node.At(i), true, dummy)); |
|
190 |
break; |
|
191 |
} |
|
192 |
return true; |
|
193 |
} |
|
194 |
|
|
181 | 195 |
bool LoadFromXML(Callback1<XmlIO> xmlize, const String& xml) |
182 | 196 |
{ |
183 | 197 |
try { |
184 |
XmlNode node = ParseXML(xml); |
|
185 |
if(node.GetCount() == 0) |
|
186 |
return false; |
|
187 |
for(int i = 0; i < node.GetCount(); i++) |
|
188 |
if(node.Node(i).IsTag()) { |
|
189 |
Value dummy; |
|
190 |
xmlize(XmlIO(node.At(i), true, dummy)); |
|
191 |
break; |
|
192 |
} |
|
193 |
return true; |
|
198 |
return LoadFromXML0(xmlize, xml); |
|
194 | 199 |
} |
195 | 200 |
catch(XmlError) {} |
196 | 201 |
return false; |
197 | 202 |
} |
198 | 203 |
|
204 |
bool TryLoadFromXML(Callback1<XmlIO> xmlize, const String& xml) |
|
205 |
{ |
|
206 |
return LoadFromXML0(xmlize, xml); |
|
207 |
} |
|
208 |
|
|
199 | 209 |
static String sXMLFile(const char *file) |
200 | 210 |
{ |
201 | 211 |
return file ? String(file) : ConfigFile(GetExeTitle() + ".xml"); |
... | ... | |
211 | 221 |
return LoadFromXML(xmlize, LoadFile(sXMLFile(file))); |
212 | 222 |
} |
213 | 223 |
|
224 |
bool TryLoadFromXMLFile(Callback1<XmlIO> xmlize, const char *file) |
|
225 |
{ |
|
226 |
return TryLoadFromXML(xmlize, LoadFile(sXMLFile(file))); |
|
227 |
} |
|
214 | 228 |
|
215 | 229 |
void StoreJsonValue(XmlIO& xio, const Value& v) |
216 | 230 |
{ |
uppsrc/Core/Xmlize.h 2013-05-24 21:50:51 +0400 | ||
---|---|---|
216 | 216 |
|
217 | 217 |
String StoreAsXML(Callback1<XmlIO> xmlize, const char *name); |
218 | 218 |
bool LoadFromXML(Callback1<XmlIO> xmlize, const String& xml); |
219 |
bool TryLoadFromXML(Callback1<XmlIO> xmlize, const String& xml); |
|
219 | 220 |
|
220 | 221 |
template <class T> |
221 | 222 |
String StoreAsXML(const T& data, const char *name = NULL) |
... | ... | |
231 | 232 |
return LoadFromXML(callback(&p, &ParamHelper__<T>::Invoke), xml); |
232 | 233 |
} |
233 | 234 |
|
235 |
template <class T> |
|
236 |
bool TryLoadFromXML(T& data, const String& xml) |
|
237 |
{ |
|
238 |
ParamHelper__<T> p(data); |
|
239 |
return TryLoadFromXML(callback(&p, &ParamHelper__<T>::Invoke), xml); |
|
240 |
} |
|
241 |
|
|
234 | 242 |
bool StoreAsXMLFile(Callback1<XmlIO> xmlize, const char *name = NULL, const char *file = NULL); |
235 | 243 |
bool LoadFromXMLFile(Callback1<XmlIO> xmlize, const char *file = NULL); |
244 |
bool TryLoadFromXMLFile(Callback1<XmlIO> xmlize, const char *file = NULL); |
|
236 | 245 |
|
237 | 246 |
template <class T> |
238 | 247 |
bool StoreAsXMLFile(T& data, const char *name = NULL, const char *file = NULL) |
... | ... | |
249 | 258 |
} |
250 | 259 |
|
251 | 260 |
template <class T> |
261 |
bool TryLoadFromXMLFile(T& data, const char *file = NULL) |
|
262 |
{ |
|
263 |
ParamHelper__<T> p(data); |
|
264 |
return TryLoadFromXMLFile(callback(&p, &ParamHelper__<T>::Invoke), file); |
|
265 |
} |
|
266 |
|
|
267 |
template <class T> |
|
252 | 268 |
void XmlizeBySerialize(XmlIO& xio, T& x) |
253 | 269 |
{ |
254 | 270 |
String h; |