MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / getRoot

Method getRoot

framework/serialization/serialize.cpp:188–229  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

186}
187
188SerializationNode *XMLSerializationArchive::getRoot(const UString &prefix, const char *name)
189{
190 auto path = prefix + name + ".xml";
191 if (dataProvider == nullptr)
192 {
193 LogWarning("Reading from not opened archive: %s!", path);
194 return nullptr;
195 }
196
197 auto it = this->docRoots.find(path);
198 if (it == this->docRoots.end())
199 {
200 UString content;
201 if (dataProvider->readDocument(path, content))
202 {
203 // FIXME: Make this actually read from the root and load the xinclude tags properly?
204 auto &doc = this->docRoots[path];
205 auto parse_result = doc.load_string(content.c_str());
206 if (!parse_result)
207 {
208 LogInfo("Failed to parse \"%s\" : \"%s\" at \"%llu\"", path,
209 parse_result.description(), (unsigned long long)parse_result.offset);
210 return nullptr;
211 }
212 it = this->docRoots.find(path);
213 LogInfo("Parsed \"%s\"", path);
214 }
215 }
216 if (it == this->docRoots.end())
217 {
218 return nullptr;
219 }
220
221 auto root = it->second.child(name);
222 if (!root)
223 {
224 LogWarning("Failed to find root with name \"%s\" in \"%s\"", name, path);
225 return nullptr;
226 }
227 const UString *newPrefix = &this->prefixes.emplace_back(prefix + name + "/");
228 return &this->nodes.emplace_back(this, root, newPrefix);
229}
230
231bool XMLSerializationArchive::write(const UString &path, bool pack, bool pretty)
232{

Callers 4

deserializeManifestMethod · 0.80
deserializeMethod · 0.80
deserializeFunction · 0.80
getSectionOptMethod · 0.80

Calls 2

endMethod · 0.80
readDocumentMethod · 0.45

Tested by

no test coverage detected