20 #define combineParamNames1(X, Y) X##Y 21 #define combineParamNames(X, Y) combineParamNames1(X, Y) 24 #define registerScalarParameter(type) \ 25 static char combineParamNames(dummyvar_reg_param, __COUNTER__) = \ 26 Moose::ParameterRegistry::get().add<type>( \ 27 [](type & value, const hit::Field & field) \ 28 { Moose::ParameterRegistration::setScalarValue<type>(value, field); }) 29 #define registerVectorParameter(type) \ 31 static char combineParamNames(dummyvar_reg_param, __COUNTER__) = \ 32 Moose::ParameterRegistry::get().add<std::vector<type>>( \ 33 [](std::vector<type> & value, const hit::Field & field) \ 34 { Moose::ParameterRegistration::setVectorValue<type>(value, field); }) 35 #define registerDoubleVectorParameter(type) \ 37 static char combineParamNames(dummyvar_reg_param, __COUNTER__) = \ 38 Moose::ParameterRegistry::get().add<std::vector<std::vector<type>>>( \ 39 [](std::vector<std::vector<type>> & value, const hit::Field & field) \ 40 { Moose::ParameterRegistration::setDoubleVectorValue<type>(value, field); }) 41 #define registerTripleVectorParameter(type) \ 43 static char combineParamNames(dummyvar_reg_param, __COUNTER__) = \ 44 Moose::ParameterRegistry::get().add<std::vector<std::vector<std::vector<type>>>>( \ 45 [](std::vector<std::vector<std::vector<type>>> & value, const hit::Field & field) \ 46 { Moose::ParameterRegistration::setTripleVectorValue<type>(value, field); }) 47 #define registerParameter(type) \ 49 registerScalarParameter(type); \ 50 registerVectorParameter(type); \ 51 registerDoubleVectorParameter(type); \ 52 registerTripleVectorParameter(type) 53 #define registerMapParameter(key_type, value_type) \ 55 static char combineParamNames(dummyvar_reg_param, __COUNTER__) = \ 56 Moose::ParameterRegistry::get().add<std::map<key_type, value_type>>( \ 57 [](std::map<key_type, value_type> & value, const hit::Field & field) \ 58 { Moose::ParameterRegistration::setMapValue<key_type, value_type>(value, field); }) 86 const hit::Field & field);
91 template <
class Key,
class Value>
102 const auto strval = field.param<std::string>();
103 if constexpr (std::is_base_of_v<std::string, T>)
109 if (!MooseUtils::convert<T>(strval,
value,
false))
110 throw std::invalid_argument(
"invalid syntax for " + MooseUtils::prettyCppType<T>() +
111 " parameter: " + field.fullpath() +
"='" + strval +
"'");
120 const auto base_values = field.param<std::vector<std::string>>();
121 if constexpr (std::is_base_of_v<std::string, T>)
123 std::copy(base_values.begin(), base_values.end(), std::back_inserter(
value));
127 value.resize(base_values.size());
130 if constexpr (std::is_same_v<bool, T>)
132 if (base_values[i] ==
"1")
137 else if (base_values[i] ==
"0")
142 else if (
bool bool_val; hit::toBool(base_values[i], &bool_val))
150 if (MooseUtils::convert<T>(base_values[i],
value[i],
false))
154 throw std::invalid_argument(
"invalid syntax for " + MooseUtils::prettyCppType<T>() +
155 " vector parameter: " + field.fullpath() +
"[" +
156 std::to_string(i) +
"]='" + base_values[i] +
"'");
175 value.resize(tokens.size());
179 if (!MooseUtils::tokenizeAndConvert<T>(
token,
value[i]))
180 throw std::invalid_argument(
"invalid syntax for " + MooseUtils::prettyCppType<T>() +
181 " double vector parameter: " + field.fullpath() +
"[" +
182 std::to_string(i) +
"]='" +
token +
"'");
191 const auto value_string = field.param<std::string>();
192 if (value_string.find_first_not_of(
' ', 0) == std::string::npos)
198 buffer.push_back(value_string[0]);
199 if (buffer[0] ==
'|' || buffer[0] ==
';')
200 buffer =
' ' + buffer;
201 for (std::string::size_type i = 1; i < value_string.size(); i++)
203 const auto val = value_string[i];
204 const auto last_val = value_string[i - 1];
205 if ((last_val ==
'|' || last_val ==
';') && (val ==
'|' || val ==
';'))
206 buffer.push_back(
' ');
207 buffer.push_back(val);
209 if (buffer.back() ==
'|' || buffer.back() ==
';')
210 buffer.push_back(
' ');
213 std::vector<std::string> outer_tokens;
215 value.resize(outer_tokens.size());
218 const auto & inner_token = outer_tokens[i];
219 auto & inner_value =
value[i];
222 if (inner_token.find_first_not_of(
' ', 0) == std::string::npos)
224 mooseAssert(inner_value.empty(),
"Should be empty");
230 std::vector<std::string> inner_tokenized;
232 inner_value.resize(inner_tokenized.size());
236 if (!MooseUtils::tokenizeAndConvert<T>(
token, inner_value[j]))
237 throw std::invalid_argument(
"invalid syntax for " + MooseUtils::prettyCppType<T>() +
238 " triple vector parameter: " + field.fullpath() +
"[" +
239 std::to_string(i) +
"][" + std::to_string(j) +
"]='" +
token +
245 template <
class Key,
class Value>
247 setMapValue(std::map<Key, Value> & value,
const hit::Field & field)
251 const auto string_vec = field.param<std::vector<std::string>>();
252 auto it = string_vec.begin();
253 while (it != string_vec.end())
255 const auto & string_key = *(it++);
256 if (it == string_vec.end())
257 throw std::invalid_argument(
258 "odd number of entries for map parameter '" + field.fullpath() +
259 "'; there must be an even number or else you will end up with a key without a value");
260 const auto & string_value = *(it++);
262 std::pair<Key, Value> pr;
265 if (!MooseUtils::convert<Key>(string_key, pr.first,
false))
266 throw std::invalid_argument(
"invalid " + MooseUtils::prettyCppType<Key>() +
267 " syntax for map parameter '" + field.fullpath() +
"' key: '" +
271 if (!MooseUtils::convert<Value>(string_value, pr.second,
false))
272 throw std::invalid_argument(
"invalid " + MooseUtils::prettyCppType<Value>() +
273 " syntax for map parameter '" + field.fullpath() +
"' value: '" +
276 if (!
value.insert(std::move(pr)).second)
277 throw std::invalid_argument(
"duplicate entry for map parameter: '" + field.fullpath() +
278 "'; key '" + string_key +
"' appears multiple times");
void tokenize(const std::string &str, std::vector< T > &elements, unsigned int min_len=1, const std::string &delims="/")
This function will split the passed in string on a set of delimiters appending the substrings to the ...
void setScalarValue(T &value, const hit::Field &field)
Converts the given field node into a scalar of the given type.
void setDoubleVectorValue(std::vector< std::vector< T >> &value, const hit::Field &field)
Converts the given field node into a vector-of-vectors of the given type.
void setVectorValue(std::vector< T > &value, const hit::Field &field)
Converts the given field node into a vector of the given type.
std::vector< std::string > split(const std::string &str, const std::string &delimiter, std::size_t max_count=std::numeric_limits< std::size_t >::max())
Python like split functions for strings.
void setMapValue(std::map< Key, Value > &value, const hit::Field &field)
Converts the given field node into a map with the given types.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
std::string trim(const std::string &str, const std::string &white_space=" \\\)
Standard scripting language trim function.
auto index_range(const T &sizable)
void setTripleVectorValue(std::vector< std::vector< std::vector< T >>> &value, const hit::Field &field)
Converts the given field node into a triple-indexed vector of the given type.