From f7f56a69d0e6aae9d68a338af1e779b3c6573f73 Mon Sep 17 00:00:00 2001 From: zoeprieto Date: Wed, 7 Aug 2024 14:42:42 -0500 Subject: [PATCH] unify concatenate function --- include/openmc/string_utils.h | 12 +++++++++--- src/mgxs.cpp | 2 +- src/nuclide.cpp | 2 +- src/string_utils.cpp | 18 ------------------ src/thermal.cpp | 3 +-- 5 files changed, 12 insertions(+), 25 deletions(-) diff --git a/include/openmc/string_utils.h b/include/openmc/string_utils.h index 827d2a28cbb..6b197fd63ad 100644 --- a/include/openmc/string_utils.h +++ b/include/openmc/string_utils.h @@ -25,9 +25,15 @@ bool ends_with(const std::string& value, const std::string& ending); bool starts_with(const std::string& value, const std::string& beginning); -std::string concatenate_vec(const std::vector& temps); - -std::string concatenate_xt(const xt::xarray& temps); +template +inline std::string concatenate(const T& temps) +{ + std::ostringstream oss; + for (const auto& temp : temps) { + oss << temp << " "; + } + return oss.str(); +} } // namespace openmc #endif // OPENMC_STRING_UTILS_H diff --git a/src/mgxs.cpp b/src/mgxs.cpp index 84aa408c8d5..5f539710610 100644 --- a/src/mgxs.cpp +++ b/src/mgxs.cpp @@ -112,7 +112,7 @@ void Mgxs::metadata_from_hdf5(hid_t xs_id, const vector& temperature, "for {} at or near {} K. Available temperatures " "are {} K consider making use of openmc.Settings.temperature " "to specify how intermediate temperatures are treated.", - in_name, std::round(T), concatenate_xt(temps_available))); + in_name, std::round(T), concatenate(temps_available))); } } break; diff --git a/src/nuclide.cpp b/src/nuclide.cpp index 35cdf8fd0e7..c7cd9ac987c 100644 --- a/src/nuclide.cpp +++ b/src/nuclide.cpp @@ -163,7 +163,7 @@ Nuclide::Nuclide(hid_t group, const vector& temperature) "for {} at or near {} K. Available temperatures " "are {} K consider making use of openmc.Settings.temperature " "to specify how intermediate temperatures are treated.", - name_, std::to_string(T_desired), concatenate_vec(temps_available))); + name_, std::to_string(T_desired), concatenate(temps_available))); } } break; diff --git a/src/string_utils.cpp b/src/string_utils.cpp index 05b96870886..b81dbc3d6c7 100644 --- a/src/string_utils.cpp +++ b/src/string_utils.cpp @@ -88,22 +88,4 @@ bool starts_with(const std::string& value, const std::string& beginning) return std::equal(beginning.begin(), beginning.end(), value.begin()); } -std::string concatenate_vec(const std::vector& temps) -{ - std::ostringstream oss; - for (const auto& temp : temps) { - oss << temp << " "; - } - return oss.str(); -} - -std::string concatenate_xt(const xt::xarray& temps) -{ - std::ostringstream oss; - for (const auto& temp : temps) { - oss << temp << " "; - } - return oss.str(); -} - } // namespace openmc diff --git a/src/thermal.cpp b/src/thermal.cpp index eb4d8b2b91c..26e5577c2ed 100644 --- a/src/thermal.cpp +++ b/src/thermal.cpp @@ -95,8 +95,7 @@ ThermalScattering::ThermalScattering( "for {} at or near {} K. Available temperatures " "are {} K consider making use of openmc.Settings.temperature " "to specify how intermediate temperatures are treated.", - name_, std::to_string(std::round(T)), - concatenate_xt(temps_available))); + name_, std::to_string(std::round(T)), concatenate(temps_available))); } } break;