diff --git a/src/cell.cpp b/src/cell.cpp index 844246f64d..798935358f 100644 --- a/src/cell.cpp +++ b/src/cell.cpp @@ -14,6 +14,17 @@ namespace openmc { +//============================================================================== +// Constants +//============================================================================== + +// TODO: Convert to enum +constexpr int32_t OP_LEFT_PAREN {std::numeric_limits::max()}; +constexpr int32_t OP_RIGHT_PAREN {std::numeric_limits::max() - 1}; +constexpr int32_t OP_COMPLEMENT {std::numeric_limits::max() - 2}; +constexpr int32_t OP_INTERSECTION {std::numeric_limits::max() - 3}; +constexpr int32_t OP_UNION {std::numeric_limits::max() - 4}; + //============================================================================== // Global variables //============================================================================== diff --git a/src/cell.h b/src/cell.h index 4aa7c15c30..0b42a656c3 100644 --- a/src/cell.h +++ b/src/cell.h @@ -24,13 +24,6 @@ extern "C" int FILL_MATERIAL; extern "C" int FILL_UNIVERSE; extern "C" int FILL_LATTICE; -// TODO: Convert to enum -constexpr int32_t OP_LEFT_PAREN {std::numeric_limits::max()}; -constexpr int32_t OP_RIGHT_PAREN {std::numeric_limits::max() - 1}; -constexpr int32_t OP_COMPLEMENT {std::numeric_limits::max() - 2}; -constexpr int32_t OP_INTERSECTION {std::numeric_limits::max() - 3}; -constexpr int32_t OP_UNION {std::numeric_limits::max() - 4}; - //============================================================================== // Global variables //============================================================================== diff --git a/src/distribution.cpp b/src/distribution.cpp index 01255f2d75..f513701fb0 100644 --- a/src/distribution.cpp +++ b/src/distribution.cpp @@ -245,7 +245,7 @@ UPtrDist distribution_from_xml(pugi::xml_node node) openmc::fatal_error("Distribution type must be specified."); // Determine type of distribution - std::string type = get_node_value(node, "type"); + std::string type = get_node_value(node, "type", true, true); // Allocate extension of Distribution if (type == "uniform") { diff --git a/src/surface.cpp b/src/surface.cpp index 94c24c82db..261a8d7d24 100644 --- a/src/surface.cpp +++ b/src/surface.cpp @@ -151,7 +151,7 @@ Surface::Surface(pugi::xml_node surf_node) } if (check_for_node(surf_node, "boundary")) { - std::string surf_bc = get_node_value(surf_node, "boundary"); + std::string surf_bc = get_node_value(surf_node, "boundary", true, true); if (surf_bc == "transmission" || surf_bc == "transmit" ||surf_bc.empty()) { bc = BC_TRANSMIT; @@ -1040,7 +1040,7 @@ read_surfaces(pugi::xml_node *node) int i_surf; for (surf_node = node->child("surface"), i_surf = 0; surf_node; surf_node = surf_node.next_sibling("surface"), i_surf++) { - std::string surf_type = get_node_value(surf_node, "type"); + std::string surf_type = get_node_value(surf_node, "type", true, true); if (surf_type == "x-plane") { surfaces_c[i_surf] = new SurfaceXPlane(surf_node); diff --git a/src/xml_interface.cpp b/src/xml_interface.cpp index 7f3222a524..c89e19ef19 100644 --- a/src/xml_interface.cpp +++ b/src/xml_interface.cpp @@ -1,6 +1,6 @@ #include "xml_interface.h" -#include // for std::transform +#include // for transform #include #include "error.h" @@ -9,10 +9,11 @@ namespace openmc { std::string -get_node_value_str(pugi::xml_node node, const char* name) +get_node_value(pugi::xml_node node, const char* name, bool lowercase, + bool strip) { // Search for either an attribute or child tag and get the data as a char*. - const pugi::char_t *value_char; + const pugi::char_t* value_char; if (node.attribute(name)) { value_char = node.attribute(name).value(); } else if (node.child(name)) { @@ -23,20 +24,18 @@ get_node_value_str(pugi::xml_node node, const char* name) << node.name() << "\" XML node"; fatal_error(err_msg); } - return value_char; -} + std::string value {value_char}; + // Convert to lower-case if needed + if (lowercase) { + std::transform(value.begin(), value.end(), value.begin(), ::tolower); + } -std::string -get_node_value(pugi::xml_node node, const char *name) -{ - // Get char* and convert to lowercase string. - std::string value {get_node_value_str(node, name)}; - std::transform(value.begin(), value.end(), value.begin(), ::tolower); - - // Remove whitespace. - value.erase(0, value.find_first_not_of(" \t\r\n")); - value.erase(value.find_last_not_of(" \t\r\n") + 1); + // Strip leading/trailing whitespace if needed + if (strip) { + value.erase(0, value.find_first_not_of(" \t\r\n")); + value.erase(value.find_last_not_of(" \t\r\n") + 1); + } return value; } diff --git a/src/xml_interface.h b/src/xml_interface.h index b12e6185b6..f10143697a 100644 --- a/src/xml_interface.h +++ b/src/xml_interface.h @@ -16,14 +16,14 @@ check_for_node(pugi::xml_node node, const char *name) return node.attribute(name) || node.child(name); } -std::string get_node_value_str(pugi::xml_node node, const char *name); -std::string get_node_value(pugi::xml_node node, const char *name); +std::string get_node_value(pugi::xml_node node, const char *name, + bool lowercase=false, bool strip=false); template std::vector get_node_array(pugi::xml_node node, const char* name) { // Get value of node attribute/child - std::string s {get_node_value_str(node, name)}; + std::string s {get_node_value(node, name)}; // Read values one by one into vector std::stringstream iss {s};