19#include <unordered_map>
23static inline const std::unordered_map<std::string, WriterType>
writerTable = {
27static inline const std::unordered_map<std::string, SimulationType>
simulationTable = {
36 std::unordered_map<WriterType, std::string> reverseMap;
38 reverseMap[pair.second] = pair.first;
44 std::unordered_map<SimulationType, std::string> reverseMap;
46 reverseMap[pair.second] = pair.first;
52 std::unordered_map<ParallelizationType, std::string> reverseMap;
54 reverseMap[pair.second] = pair.first;
68static inline bool findStringIC(
const std::string &haystack,
const std::string &needle) {
69 auto it = std::search(haystack.begin(), haystack.end(), needle.begin(), needle.end(),
70 [](
unsigned char ch1,
unsigned char ch2) { return std::toupper(ch1) == std::toupper(ch2); });
71 return (it != haystack.end());
82static inline double toDouble(
const std::string &str) {
86 throw std::invalid_argument(
"Invalid number");
90 double converted = std::stod(str, &idx);
91 if (idx != str.length())
92 throw std::invalid_argument(
"Invalid number");
94 }
catch (
const std::invalid_argument &ia) {
96 }
catch (
const std::out_of_range &oor) {
109static inline double toInt(
const std::string &str) {
112 int converted = std::stoi(str, &idx);
113 if (idx != str.length())
114 throw std::invalid_argument(
"Invalid number");
116 }
catch (
const std::invalid_argument &ia) {
118 }
catch (
const std::out_of_range &oor) {
139template <
size_t N>
static inline std::array<int, N>
toIntArray(
const std::string &str) {
140 if (str.empty() || N == 0)
143 if (str.front() !=
'{' || str.back() !=
'}')
146 std::array<int, N> arr = {};
148 std::string numbers = str.substr(1, str.size() - 2);
149 std::stringstream ss(numbers);
152 while (i < N && std::getline(ss, tmp,
',')) {
175template <
size_t N>
static inline std::array<double, N>
toDoubleArray(
const std::string &str,
bool reqBrackets =
true) {
176 if (str.empty() || N == 0)
179 if (reqBrackets && (str.front() !=
'{' || str.back() !=
'}'))
182 std::array<double, N> arr = {};
184 std::string numbers = reqBrackets ? str.substr(1, str.size() - 2) : str;
185 std::stringstream ss(numbers);
188 while (i < N && std::getline(ss, tmp,
',')) {
286template <
typename T> std::string
static inline fromNumber(T number) {
return std::to_string(number); }
294template <
typename T>
static inline std::string
fromVector(
const std::vector<T> &vec) {
295 std::stringstream ss;
297 for (
size_t i = 0; i < vec.size(); ++i) {
299 if (i != vec.size() - 1)
Configurable program and simulation arguments.
ParallelizationType
Enum containing each possible parallelization strategy.
Definition Arguments.h:26
SimulationType
Enum containg each possible Simulation to be performed.
Definition Arguments.h:23
WriterType
Enum containing each (valid) type of output writer.
Definition Arguments.h:20
Utility functions for console input / output.
static const std::unordered_map< ParallelizationType, std::string > parallelizationStringTable
Reverse map containing conversion information for converting a ParallelizationType enum to a string.
Definition StringUtils.h:51
static const std::unordered_map< WriterType, std::string > writerStringTable
Reverse map containing conversion information for converting a WriterType enum to a string.
Definition StringUtils.h:35
static const std::unordered_map< std::string, WriterType > writerTable
Map containing conversion information for converting a string to a WriterType enum.
Definition StringUtils.h:23
static const std::unordered_map< std::string, SimulationType > simulationTable
Map containing conversion information for converting a string to a SimulationType enum.
Definition StringUtils.h:27
static const std::unordered_map< SimulationType, std::string > simulationStringTable
Reverse map containing conversion information for converting a SimulationType enum to a string.
Definition StringUtils.h:43
static bool findStringIC(const std::string &haystack, const std::string &needle)
Finds a given substring in a string. Case-insensitive.
Definition StringUtils.h:68
static const std::unordered_map< std::string, ParallelizationType > parallelizationTable
Map containing conversion information for converting a string to a ParallelizationType enum.
Definition StringUtils.h:31
Enumeration class corresponding to the type schema type.
Definition vtk-unstructured.h:2125
static void error(const char *msg, const std::string &opt="", bool usage=true, bool close=true)
Prints an error message to stderr with the prefix "ERROR: ", optionally prints the usage string and e...
Definition CLIUtils.h:149
Namespace defining utility functions for working with strings.
Definition StringUtils.h:75
static SimulationType toSimulationType(const std::string &type)
Converts a string to a SimulationType enum using a dedicated map.
Definition StringUtils.h:216
static double toDouble(const std::string &str)
Converts a string to a double.
Definition StringUtils.h:82
static std::string fromNumber(T number)
Converts a number to a string.
Definition StringUtils.h:286
static std::string fromParallelizationType(ParallelizationType parallelizationType)
Converts a ParallelizationType to a string.
Definition StringUtils.h:275
static ParallelizationType toParallelizationType(const std::string &type)
Converts a string to a ParallelizationType enum using a dedicated map.
Definition StringUtils.h:231
static std::string fromChar(char c)
Converts a char to a string.
Definition StringUtils.h:246
static std::string fromVector(const std::vector< T > &vec)
Converts a vector to a string.
Definition StringUtils.h:294
static double toInt(const std::string &str)
Converts a string to an integer.
Definition StringUtils.h:109
static std::array< int, N > toIntArray(const std::string &str)
Converts a string into an integer array.
Definition StringUtils.h:139
static std::string fromSimulationType(SimulationType simulationType)
Converts a SimulationType to a string.
Definition StringUtils.h:265
static std::string fromWriterType(WriterType writerType)
Converts a WriterType to a string.
Definition StringUtils.h:257
static std::array< double, N > toDoubleArray(const std::string &str, bool reqBrackets=true)
Converts a string into a double array.
Definition StringUtils.h:175
static WriterType toWriterType(const std::string &type)
Converts a string to a WriterType enum using a dedicated map.
Definition StringUtils.h:201