diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-07-29 02:03:39 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-07-29 02:03:39 +0300 |
commit | dc6afb20dd1af4e9e3a8ff4d3f2f3fcf5cd87734 (patch) | |
tree | 8d944bed5a0e296b544440e26781931e20d66879 /src/utils | |
parent | f83dce6cb491c66721ff319ab90d9aad23a349eb (diff) | |
download | manaverse-dc6afb20dd1af4e9e3a8ff4d3f2f3fcf5cd87734.tar.gz manaverse-dc6afb20dd1af4e9e3a8ff4d3f2f3fcf5cd87734.tar.bz2 manaverse-dc6afb20dd1af4e9e3a8ff4d3f2f3fcf5cd87734.tar.xz manaverse-dc6afb20dd1af4e9e3a8ff4d3f2f3fcf5cd87734.zip |
Add function for load xml data to std::map with strings.
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/xmlutils.cpp | 39 | ||||
-rw-r--r-- | src/utils/xmlutils.h | 9 |
2 files changed, 48 insertions, 0 deletions
diff --git a/src/utils/xmlutils.cpp b/src/utils/xmlutils.cpp index 232ec92b1..937695d41 100644 --- a/src/utils/xmlutils.cpp +++ b/src/utils/xmlutils.cpp @@ -61,3 +61,42 @@ void readXmlIntVector(const std::string &fileName, } } } + +void readXmlStringMap(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<std::string, std::string> &arr) +{ + arr.clear(); + XML::Document doc(fileName, UseResman_true, SkipError_false); + 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())) + continue; + + const std::string key = XML::getProperty(childNode, + attributeKeyName.c_str(), ""); + if (key.empty()) + continue; + const std::string val = XML::getProperty(childNode, + attributeValueName.c_str(), ""); + + arr[key] = val; + } + } +} diff --git a/src/utils/xmlutils.h b/src/utils/xmlutils.h index 9715b005a..e5ac40f5c 100644 --- a/src/utils/xmlutils.h +++ b/src/utils/xmlutils.h @@ -22,6 +22,7 @@ #define UTILS_XMLUTILS_H #include <string> +#include <map> #include <vector> void readXmlIntVector(const std::string &fileName, @@ -31,4 +32,12 @@ void readXmlIntVector(const std::string &fileName, const std::string &attributeName, std::vector<int> &arr); +void readXmlStringMap(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<std::string, std::string> &arr); + #endif // UTILS_XMLUTILS_H |