2018-08-20 14:40:32 -05:00
|
|
|
#ifndef OPENMC_XML_INTERFACE_H
|
|
|
|
|
#define OPENMC_XML_INTERFACE_H
|
2018-01-23 22:26:48 -05:00
|
|
|
|
2018-08-28 06:59:39 -05:00
|
|
|
#include <cstddef> // for size_t
|
2018-07-05 07:01:19 -05:00
|
|
|
#include <sstream> // for stringstream
|
2018-01-23 22:26:48 -05:00
|
|
|
#include <string>
|
|
|
|
|
|
2018-06-20 10:56:28 -05:00
|
|
|
#include "pugixml.hpp"
|
2018-08-28 06:59:39 -05:00
|
|
|
#include "xtensor/xadapt.hpp"
|
|
|
|
|
#include "xtensor/xarray.hpp"
|
2018-01-23 22:26:48 -05:00
|
|
|
|
2022-10-11 11:21:31 -05:00
|
|
|
#include "openmc/position.h"
|
2021-04-22 16:46:23 -04:00
|
|
|
#include "openmc/vector.h"
|
|
|
|
|
|
2018-01-31 15:28:36 -05:00
|
|
|
namespace openmc {
|
|
|
|
|
|
|
|
|
|
inline bool check_for_node(pugi::xml_node node, const char* name)
|
2018-01-23 22:26:48 -05:00
|
|
|
{
|
2018-01-31 15:28:36 -05:00
|
|
|
return node.attribute(name) || node.child(name);
|
2018-01-23 22:26:48 -05:00
|
|
|
}
|
|
|
|
|
|
2018-08-15 10:07:40 -05:00
|
|
|
std::string get_node_value(pugi::xml_node node, const char* name,
|
2018-08-16 14:28:28 -04:00
|
|
|
bool lowercase = false, bool strip = false);
|
2018-01-23 22:26:48 -05:00
|
|
|
|
2018-08-15 10:07:40 -05:00
|
|
|
bool get_node_value_bool(pugi::xml_node node, const char* name);
|
|
|
|
|
|
2021-04-22 16:46:23 -04:00
|
|
|
template<typename T>
|
|
|
|
|
vector<T> get_node_array(
|
|
|
|
|
pugi::xml_node node, const char* name, bool lowercase = false)
|
2018-07-05 07:01:19 -05:00
|
|
|
{
|
|
|
|
|
// Get value of node attribute/child
|
2018-08-16 14:28:28 -04:00
|
|
|
std::string s {get_node_value(node, name, lowercase)};
|
2018-07-05 07:01:19 -05:00
|
|
|
|
|
|
|
|
// Read values one by one into vector
|
|
|
|
|
std::stringstream iss {s};
|
|
|
|
|
T value;
|
2021-04-22 16:46:23 -04:00
|
|
|
vector<T> values;
|
2018-07-05 07:01:19 -05:00
|
|
|
while (iss >> value)
|
|
|
|
|
values.push_back(value);
|
|
|
|
|
|
|
|
|
|
return values;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-28 06:59:39 -05:00
|
|
|
template<typename T>
|
|
|
|
|
xt::xarray<T> get_node_xarray(
|
|
|
|
|
pugi::xml_node node, const char* name, bool lowercase = false)
|
|
|
|
|
{
|
2021-04-22 16:46:23 -04:00
|
|
|
vector<T> v = get_node_array<T>(node, name, lowercase);
|
|
|
|
|
vector<std::size_t> shape = {v.size()};
|
2018-08-28 06:59:39 -05:00
|
|
|
return xt::adapt(v, shape);
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-11 11:21:31 -05:00
|
|
|
Position get_node_position(
|
|
|
|
|
pugi::xml_node node, const char* name, bool lowercase = false);
|
|
|
|
|
|
2018-01-31 15:28:36 -05:00
|
|
|
} // namespace openmc
|
2018-08-20 14:40:32 -05:00
|
|
|
#endif // OPENMC_XML_INTERFACE_H
|