mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-21 06:25:30 -04:00
58 lines
1.4 KiB
C++
58 lines
1.4 KiB
C++
#ifndef OPENMC_XML_INTERFACE_H
|
|
#define OPENMC_XML_INTERFACE_H
|
|
|
|
#include <cstddef> // for size_t
|
|
#include <sstream> // for stringstream
|
|
#include <string>
|
|
|
|
#include "openmc/tensor.h"
|
|
#include "pugixml.hpp"
|
|
|
|
#include "openmc/position.h"
|
|
#include "openmc/vector.h"
|
|
|
|
namespace openmc {
|
|
|
|
inline bool check_for_node(pugi::xml_node node, const char* name)
|
|
{
|
|
return node.attribute(name) || node.child(name);
|
|
}
|
|
|
|
std::string get_node_value(pugi::xml_node node, const char* name,
|
|
bool lowercase = false, bool strip = false);
|
|
|
|
bool get_node_value_bool(pugi::xml_node node, const char* name);
|
|
|
|
template<typename T>
|
|
vector<T> get_node_array(
|
|
pugi::xml_node node, const char* name, bool lowercase = false)
|
|
{
|
|
// Get value of node attribute/child
|
|
std::string s {get_node_value(node, name, lowercase)};
|
|
|
|
// Read values one by one into vector
|
|
std::stringstream iss {s};
|
|
T value;
|
|
vector<T> values;
|
|
while (iss >> value)
|
|
values.push_back(value);
|
|
|
|
return values;
|
|
}
|
|
|
|
template<typename T>
|
|
tensor::Tensor<T> get_node_tensor(
|
|
pugi::xml_node node, const char* name, bool lowercase = false)
|
|
{
|
|
vector<T> v = get_node_array<T>(node, name, lowercase);
|
|
return tensor::Tensor<T>(v.data(), v.size());
|
|
}
|
|
|
|
std::vector<Position> get_node_position_array(
|
|
pugi::xml_node node, const char* name, bool lowercase = false);
|
|
|
|
Position get_node_position(
|
|
pugi::xml_node node, const char* name, bool lowercase = false);
|
|
|
|
} // namespace openmc
|
|
#endif // OPENMC_XML_INTERFACE_H
|