diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-10-28 09:53:05 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2025-01-18 21:04:16 +0100 |
commit | bbbc318634f3be2c4d755e71d99cdfba5c2b82f3 (patch) | |
tree | 0cf8e417eb33caae0e13192fa128ac69114fd4af /src/configuration.cpp | |
parent | 8ce74a1d4ea65a7a524070ae3589b6d04874a077 (diff) | |
download | mana-bbbc318634f3be2c4d755e71d99cdfba5c2b82f3.tar.gz mana-bbbc318634f3be2c4d755e71d99cdfba5c2b82f3.tar.bz2 mana-bbbc318634f3be2c4d755e71d99cdfba5c2b82f3.tar.xz mana-bbbc318634f3be2c4d755e71d99cdfba5c2b82f3.zip |
Introduced small convenience wrapper to write XML
Might not seem worth it right now, but it will be if we write out more
XML structures.
Diffstat (limited to 'src/configuration.cpp')
-rw-r--r-- | src/configuration.cpp | 36 |
1 files changed, 14 insertions, 22 deletions
diff --git a/src/configuration.cpp b/src/configuration.cpp index f0499b2d..084c8563 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -269,32 +269,30 @@ void Configuration::init(const std::string &filename, bool useResManager) initFromXML(rootNode); } -void ConfigurationObject::writeToXML(xmlTextWriterPtr writer) +void ConfigurationObject::writeToXML(XML::Writer &writer) const { - for (const auto &option : mOptions) + for (auto &[name, value] : mOptions) { - xmlTextWriterStartElement(writer, BAD_CAST "option"); - xmlTextWriterWriteAttribute(writer, - BAD_CAST "name", BAD_CAST option.first.c_str()); - xmlTextWriterWriteAttribute(writer, - BAD_CAST "value", BAD_CAST option.second.c_str()); - xmlTextWriterEndElement(writer); + writer.startElement("option"); + writer.addAttribute("name", name); + writer.addAttribute("value", value); + writer.endElement(); } for (auto &[name, list] : mContainerOptions) { - xmlTextWriterStartElement(writer, BAD_CAST "list"); - xmlTextWriterWriteAttribute(writer, BAD_CAST "name", BAD_CAST name.c_str()); + writer.startElement("list"); + writer.addAttribute("name", name); // Recurse on all elements for (auto element : list) { - xmlTextWriterStartElement(writer, BAD_CAST name.c_str()); + writer.startElement(name.c_str()); element->writeToXML(writer); - xmlTextWriterEndElement(writer); + writer.endElement(); } - xmlTextWriterEndElement(writer); + writer.endElement(); } } @@ -312,9 +310,9 @@ void Configuration::write() fclose(testFile); - xmlTextWriterPtr writer = xmlNewTextWriterFilename(mConfigPath.c_str(), 0); + XML::Writer writer(mConfigPath); - if (!writer) + if (!writer.isValid()) { logger->log("Configuration::write() error while creating writer"); return; @@ -322,12 +320,6 @@ void Configuration::write() logger->log("Configuration::write() writing configuration..."); - xmlTextWriterSetIndent(writer, 1); - xmlTextWriterStartDocument(writer, nullptr, nullptr, nullptr); - xmlTextWriterStartElement(writer, BAD_CAST "configuration"); - + writer.startElement("configuration"); writeToXML(writer); - - xmlTextWriterEndDocument(writer); - xmlFreeTextWriter(writer); } |