diff --git a/lib/XmlReader.hpp b/lib/XmlReader.hpp index 86b13dc..4027dbc 100644 --- a/lib/XmlReader.hpp +++ b/lib/XmlReader.hpp @@ -23,6 +23,7 @@ #include #include #include +#include BEGIN_NAMESPACE @@ -40,7 +41,13 @@ public: // IO template T getFirstValue(const std::string &nodeName, Strs... nodeNames); + template + std::vector getAllValues(const std::string &nodeName, Strs... nodeNames); void open(const std::string &fileName); +private: + template + tinyxml2::XMLElement * getFirstNode(const std::string &nodeName, + Strs... nodeNames); private: std::string name_; tinyxml2::XMLDocument doc_; @@ -52,6 +59,45 @@ private: ******************************************************************************/ template T XmlReader::getFirstValue(const std::string &nodeName, Strs... nodeNames) +{ + tinyxml2::XMLElement *node = getFirstNode(nodeName, nodeNames...); + + if (node->GetText()) + { + return strTo(node->GetText()); + } + else + { + return T(); + } +} + +template +std::vector XmlReader::getAllValues(const std::string &nodeName, + Strs... nodeNames) +{ + tinyxml2::XMLElement *node = getFirstNode(nodeName, nodeNames...); + std::vector value; + + while (node) + { + if (node->GetText()) + { + value.push_back(strTo(node->GetText())); + } + else + { + value.push_back(T()); + } + node = node->NextSiblingElement(); + } + + return value; +} + +template +tinyxml2::XMLElement * XmlReader::getFirstNode(const std::string &nodeName, + Strs... nodeNames) { static_assert(static_or::value...>::value, "getFirstValue arguments are not compatible with std::string"); @@ -72,14 +118,8 @@ T XmlReader::getFirstValue(const std::string &nodeName, Strs... nodeNames) LATAN_ERROR(Parsing, "XML node " + name[i] + " not found"); } } - if (node->GetText()) - { - return strTo(node->GetText()); - } - else - { - return T(); - } + + return node; } END_NAMESPACE