bool CSettingsManager::Serialize(TiXmlNode *parent) const { if (parent == NULL) return false; CSharedLock lock(m_settingsCritical); for (SettingMap::const_iterator it = m_settings.begin(); it != m_settings.end(); ++it) { if (it->second.setting->GetType() == SettingTypeAction) continue; std::vector<std::string> parts = StringUtils::Split(it->first, "."); if (parts.size() != 2 || parts.at(0).empty() || parts.at(1).empty()) { CLog::Log(LOGWARNING, "CSettingsManager: unable to save setting \"%s\"", it->first.c_str()); continue; } TiXmlNode *sectionNode = parent->FirstChild(parts.at(0)); if (sectionNode == NULL) { TiXmlElement sectionElement(parts.at(0)); sectionNode = parent->InsertEndChild(sectionElement); if (sectionNode == NULL) { CLog::Log(LOGWARNING, "CSettingsManager: unable to write <%s> tag", parts.at(0).c_str()); continue; } } TiXmlElement settingElement(parts.at(1)); TiXmlNode *settingNode = sectionNode->InsertEndChild(settingElement); if (settingNode == NULL) { CLog::Log(LOGWARNING, "CSetting: unable to write <%s> tag in <%s>", parts.at(1).c_str(), parts.at(0).c_str()); continue; } if (it->second.setting->IsDefault()) { TiXmlElement *settingElem = settingNode->ToElement(); if (settingElem != NULL) settingElem->SetAttribute(SETTING_XML_ELM_DEFAULT, "true"); } TiXmlText value(it->second.setting->ToString()); settingNode->InsertEndChild(value); } return true; }
std::shared_ptr<XMLElement> FormSerializer::sectionToXML(std::shared_ptr<FormSection> section) const { std::shared_ptr<XMLElement> sectionElement(new XMLElement("section")); if (!section->getLabel().empty()) { sectionElement->setAttribute("label", section->getLabel()); } for (const auto& text : section->getTextElements()) { sectionElement->addNode(textToXML(text)); } for (const auto& field : section->getFields()) { sectionElement->addNode(fieldRefToXML(field->getName())); fields_.push_back(field); } for (const auto& reportedRef : section->getReportedRefs()) { (void)reportedRef; sectionElement->addNode(std::make_shared<XMLElement>("reportedref")); } for (const auto& childSection : section->getChildSections()) { sectionElement->addNode(sectionToXML(childSection)); } return sectionElement; }