From dca3de26978bf0a9d7ac9df8524c90b85f8920da Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 13 Sep 2016 18:31:30 +0300 Subject: Add into xmlutils function for read xml file into int map. --- src/utils/xmlutils.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'src/utils/xmlutils.cpp') diff --git a/src/utils/xmlutils.cpp b/src/utils/xmlutils.cpp index fdcc272ec..5cc14f517 100644 --- a/src/utils/xmlutils.cpp +++ b/src/utils/xmlutils.cpp @@ -130,3 +130,57 @@ void readXmlStringMap(const std::string &fileName, } } } + +void readXmlIntMap(const std::string &fileName, + const std::string &rootName, + const std::string §ionName, + const std::string &itemName, + const std::string &attributeKeyName, + const std::string &attributeValueName, + std::map &arr, + const SkipError skipError) +{ + XML::Document doc(fileName, UseResman_true, skipError); + const XmlNodePtrConst rootNode = doc.rootNode(); + + if (!rootNode || !xmlNameEqual(rootNode, rootName.c_str())) + { + logger->log("Error while loading %s!", fileName.c_str()); + return; + } + + for_each_xml_child_node(sectionNode, rootNode) + { + if (!xmlNameEqual(sectionNode, sectionName.c_str())) + continue; + for_each_xml_child_node(childNode, sectionNode) + { + if (xmlNameEqual(childNode, itemName.c_str())) + { + const std::string key = XML::getProperty(childNode, + attributeKeyName.c_str(), ""); + if (key.empty()) + continue; + const int32_t val = XML::getProperty(childNode, + attributeValueName.c_str(), 0); + arr[atoi(key.c_str())] = val; + } + else if (xmlNameEqual(childNode, "include")) + { + const std::string name = XML::getProperty( + childNode, "name", ""); + if (!name.empty()) + { + readXmlIntMap(name, + rootName, + sectionName, + itemName, + attributeKeyName, + attributeValueName, + arr, + skipError); + } + } + } + } +} -- cgit v1.2.3-60-g2f50