mirror of
https://github.com/aportelli/LatAnalyze.git
synced 2025-04-10 19:20:44 +01:00
XmlReader: additional reading functions
This commit is contained in:
parent
5787cf0544
commit
dc659991d0
@ -23,6 +23,7 @@
|
|||||||
#include <LatAnalyze/Global.hpp>
|
#include <LatAnalyze/Global.hpp>
|
||||||
#include <LatAnalyze/XML/tinyxml2.hpp>
|
#include <LatAnalyze/XML/tinyxml2.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
BEGIN_NAMESPACE
|
BEGIN_NAMESPACE
|
||||||
|
|
||||||
@ -40,7 +41,13 @@ public:
|
|||||||
// IO
|
// IO
|
||||||
template <typename T, typename... Strs>
|
template <typename T, typename... Strs>
|
||||||
T getFirstValue(const std::string &nodeName, Strs... nodeNames);
|
T getFirstValue(const std::string &nodeName, Strs... nodeNames);
|
||||||
|
template <typename T, typename... Strs>
|
||||||
|
std::vector<T> getAllValues(const std::string &nodeName, Strs... nodeNames);
|
||||||
void open(const std::string &fileName);
|
void open(const std::string &fileName);
|
||||||
|
private:
|
||||||
|
template <typename... Strs>
|
||||||
|
tinyxml2::XMLElement * getFirstNode(const std::string &nodeName,
|
||||||
|
Strs... nodeNames);
|
||||||
private:
|
private:
|
||||||
std::string name_;
|
std::string name_;
|
||||||
tinyxml2::XMLDocument doc_;
|
tinyxml2::XMLDocument doc_;
|
||||||
@ -52,6 +59,45 @@ private:
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
template <typename T, typename... Strs>
|
template <typename T, typename... Strs>
|
||||||
T XmlReader::getFirstValue(const std::string &nodeName, Strs... nodeNames)
|
T XmlReader::getFirstValue(const std::string &nodeName, Strs... nodeNames)
|
||||||
|
{
|
||||||
|
tinyxml2::XMLElement *node = getFirstNode(nodeName, nodeNames...);
|
||||||
|
|
||||||
|
if (node->GetText())
|
||||||
|
{
|
||||||
|
return strTo<T>(node->GetText());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return T();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, typename... Strs>
|
||||||
|
std::vector<T> XmlReader::getAllValues(const std::string &nodeName,
|
||||||
|
Strs... nodeNames)
|
||||||
|
{
|
||||||
|
tinyxml2::XMLElement *node = getFirstNode(nodeName, nodeNames...);
|
||||||
|
std::vector<T> value;
|
||||||
|
|
||||||
|
while (node)
|
||||||
|
{
|
||||||
|
if (node->GetText())
|
||||||
|
{
|
||||||
|
value.push_back(strTo<T>(node->GetText()));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
value.push_back(T());
|
||||||
|
}
|
||||||
|
node = node->NextSiblingElement();
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename... Strs>
|
||||||
|
tinyxml2::XMLElement * XmlReader::getFirstNode(const std::string &nodeName,
|
||||||
|
Strs... nodeNames)
|
||||||
{
|
{
|
||||||
static_assert(static_or<std::is_assignable<std::string, Strs>::value...>::value,
|
static_assert(static_or<std::is_assignable<std::string, Strs>::value...>::value,
|
||||||
"getFirstValue arguments are not compatible with std::string");
|
"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");
|
LATAN_ERROR(Parsing, "XML node " + name[i] + " not found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (node->GetText())
|
|
||||||
{
|
return node;
|
||||||
return strTo<T>(node->GetText());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return T();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
END_NAMESPACE
|
END_NAMESPACE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user