MCPcopy Create free account
hub / github.com/DFHack/dfhack / loadFile

Method loadFile

library/VersionInfoFactory.cpp:230–286  ·  view source on GitHub ↗

load the XML file with offsets

Source from the content-addressed store, hash-verified

228
229// load the XML file with offsets
230bool VersionInfoFactory::loadFile(std::filesystem::path path_to_xml)
231{
232 TiXmlDocument doc( path_to_xml.string().c_str() );
233 std::cerr << "Loading " << path_to_xml << " ... ";
234 //bool loadOkay = doc.LoadFile();
235 if (!doc.LoadFile())
236 {
237 error = true;
238 cerr << "failed!\n";
239 throw Error::SymbolsXmlParse(doc.ErrorDesc(), doc.ErrorId(), doc.ErrorRow(), doc.ErrorCol());
240 }
241 else
242 {
243 cerr << "OK\n";
244 }
245 TiXmlHandle hDoc(&doc);
246 TiXmlElement* pElem;
247 TiXmlHandle hRoot(0);
248
249 // block: name
250 {
251 pElem=hDoc.FirstChildElement().Element();
252 // should always have a valid root but handle gracefully if it does
253 if (!pElem)
254 {
255 error = true;
256 throw Error::SymbolsXmlNoRoot();
257 }
258 string m_name=pElem->Value();
259 if(m_name != "data-definition")
260 {
261 error = true;
262 throw Error::SymbolsXmlNoRoot();
263 }
264 // save this for later
265 hRoot=TiXmlHandle(pElem);
266 }
267 // transform elements
268 {
269 clear();
270 // For each version
271 TiXmlElement * pMemInfo=hRoot.FirstChild( "symbol-table" ).Element();
272 for( ; pMemInfo; pMemInfo=pMemInfo->NextSiblingElement("symbol-table"))
273 {
274 const char *name = pMemInfo->Attribute("name");
275 if(name)
276 {
277 auto version = std::make_shared<VersionInfo>();
278 ParseVersion( pMemInfo , version.get() );
279 versions.push_back(version);
280 }
281 }
282 }
283 error = false;
284 std::cerr << "Loaded " << versions.size() << " DF symbol tables." << std::endl;
285 return true;
286}

Callers 1

InitMainThreadMethod · 0.80

Calls 15

TiXmlHandleClass · 0.85
c_strMethod · 0.80
ErrorDescMethod · 0.80
ErrorIdMethod · 0.80
ErrorRowMethod · 0.80
ErrorColMethod · 0.80
ElementMethod · 0.80
AttributeMethod · 0.80
clearFunction · 0.70
LoadFileMethod · 0.45
FirstChildElementMethod · 0.45
ValueMethod · 0.45

Tested by

no test coverage detected