Move constants in cell.h, add default arguments to get_node_value

This commit is contained in:
Paul Romano 2018-08-14 14:44:45 -05:00
parent ee02f02655
commit af6dfe457e
6 changed files with 31 additions and 28 deletions

View file

@ -14,6 +14,17 @@
namespace openmc {
//==============================================================================
// Constants
//==============================================================================
// TODO: Convert to enum
constexpr int32_t OP_LEFT_PAREN {std::numeric_limits<int32_t>::max()};
constexpr int32_t OP_RIGHT_PAREN {std::numeric_limits<int32_t>::max() - 1};
constexpr int32_t OP_COMPLEMENT {std::numeric_limits<int32_t>::max() - 2};
constexpr int32_t OP_INTERSECTION {std::numeric_limits<int32_t>::max() - 3};
constexpr int32_t OP_UNION {std::numeric_limits<int32_t>::max() - 4};
//==============================================================================
// Global variables
//==============================================================================

View file

@ -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<int32_t>::max()};
constexpr int32_t OP_RIGHT_PAREN {std::numeric_limits<int32_t>::max() - 1};
constexpr int32_t OP_COMPLEMENT {std::numeric_limits<int32_t>::max() - 2};
constexpr int32_t OP_INTERSECTION {std::numeric_limits<int32_t>::max() - 3};
constexpr int32_t OP_UNION {std::numeric_limits<int32_t>::max() - 4};
//==============================================================================
// Global variables
//==============================================================================

View file

@ -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") {

View file

@ -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);

View file

@ -1,6 +1,6 @@
#include "xml_interface.h"
#include <algorithm> // for std::transform
#include <algorithm> // for transform
#include <sstream>
#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;
}

View file

@ -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 <typename T>
std::vector<T> 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};