OpenMC/include/openmc/xml_interface.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

59 lines
1.4 KiB
C
Raw Permalink Normal View History

#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
#include <sstream> // for stringstream
2018-01-23 22:26:48 -05:00
#include <string>
#include "openmc/tensor.h"
2018-06-20 10:56:28 -05:00
#include "pugixml.hpp"
2018-01-23 22:26:48 -05:00
#include "openmc/position.h"
#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
}
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
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
2018-08-16 14:28:28 -04:00
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;
}
2018-08-28 06:59:39 -05:00
template<typename T>
tensor::Tensor<T> get_node_tensor(
2018-08-28 06:59:39 -05:00
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());
2018-08-28 06:59:39 -05:00
}
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);
2018-01-31 15:28:36 -05:00
} // namespace openmc
#endif // OPENMC_XML_INTERFACE_H