1 #ifndef sensei_XMLUtils_h 2 #define sensei_XMLUtils_h 12 #include <pugixml.hpp> 33 int RequireChild(
const pugi::xml_node &node,
const char *childName);
40 int Parse(MPI_Comm comm,
const std::string &filename, pugi::xml_document &doc);
46 template <
typename num_t>
struct numeric_traits;
48 #define declare_numeric_traits(cpp_t, func) \ 49 template <> struct numeric_traits<cpp_t> \ 52 cpp_t convert(const std::string &str) \ 53 { return (cpp_t)func(str); } \ 56 declare_numeric_traits(
int, std::stol)
57 declare_numeric_traits(
unsigned int, std::stoul)
58 declare_numeric_traits(
long, std::stol)
59 declare_numeric_traits(
unsigned long, std::stoul)
60 declare_numeric_traits(
long long, std::stol)
61 declare_numeric_traits(
unsigned long long, std::stoul)
62 declare_numeric_traits(
float, std::stof)
63 declare_numeric_traits(
double, std::stod)
70 template <
typename num_t>
71 int ParseNumeric(
const pugi::xml_node &node, std::vector<num_t> &numData)
73 std::string strData = node.text().as_string();
74 std::string delims =
" ,\t\n";
76 std::size_t curr = strData.find_first_not_of(delims, 0);
77 std::size_t next = std::string::npos;
79 while (curr != std::string::npos)
81 next = strData.find_first_of(delims, curr + 1);
82 std::string tmp = strData.substr(curr, next - curr);
83 numData.push_back(numeric_traits<num_t>::convert(tmp));
84 curr = strData.find_first_not_of(delims, next);
91 template <
typename num_t,
unsigned long n>
92 int ParseNumeric(
const pugi::xml_node &node, std::array<num_t,n> &numData)
94 std::string strData = node.text().as_string();
95 std::string delims =
" ,\t";
97 std::size_t curr = strData.find_first_not_of(delims, 0);
98 std::size_t next = std::string::npos;
101 while ((curr != std::string::npos) && (i < n))
103 next = strData.find_first_of(delims, curr + 1);
104 std::string tmp = strData.substr(curr, next - curr);
105 numData[i] = numeric_traits<num_t>::convert(tmp);
106 curr = strData.find_first_not_of(delims, next);
112 SENSEI_ERROR(<<
"Missmatch in the nuber of values detected. " 113 << node.name() <<
" requires " << n <<
" values")
122 std::vector<std::string> &names, std::vector<std::string> &values);
136 int ParseList(pugi::xml_node node, std::vector<std::string> &listOut);
int ParseNameValuePairs(const pugi::xml_node &node, std::vector< std::string > &names, std::vector< std::string > &values)
process a sequence of "name = value" pairs in a node's text.
int ParseNumeric(const pugi::xml_node &node, std::vector< num_t > &numData)
parse text data in the node of unknown length, return in the vector.
Definition: XMLUtils.h:71
SENSEI_EXPORT int RequireChild(const pugi::xml_node &node, const char *childName)
check that a child element of the passed in name exists return of 0 indicates that it does...
SENSEI_EXPORT int RequireAttribute(const pugi::xml_node &node, const char *attributeName)
check that an attribute of the passed in name exists return of 0 indicates that it does...
SENSEI.
Definition: ADIOS2AnalysisAdaptor.h:27
SENSEI_EXPORT int Parse(MPI_Comm comm, const std::string &filename, pugi::xml_document &doc)
Parallel collective read, parse, and distribute the XML file.
int ParseList(pugi::xml_node node, std::vector< std::string > &listOut)
process a list in a node's text.