https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Member Functions | List of all members
RangeEvaler Class Reference

#include <Parser.h>

Inheritance diagram for RangeEvaler:
[legend]

Public Member Functions

virtual std::string eval (hit::Field *n, const std::list< std::string > &args, hit::BraceExpander &exp)
 

Detailed Description

Definition at line 43 of file Parser.h.

Member Function Documentation

◆ eval()

std::string RangeEvaler::eval ( hit::Field *  n,
const std::list< std::string > &  args,
hit::BraceExpander &  exp 
)
virtual

Definition at line 190 of file Parser.C.

191{
192 std::vector<std::string> argv;
193 argv.insert(argv.begin(), args.begin(), args.end());
194
195 if (argv.size() < 2 || argv.size() > 3)
196 {
197 exp.errors.emplace_back("range error: Expected either 2 arguments '${range start stop}' "
198 "or 3 arguments '${range start stop step}' in '" +
199 n->fullpath() + "'",
200 n);
201 return n->val();
202 }
203
204 std::array<int, 3> int_args;
205 for (const auto i : make_range(argv.size()))
206 {
207 bool success = false;
208 if (!argv[i].empty())
209 success = MooseUtils::convert(argv[i], int_args[i], false);
210
211 if (!success)
212 {
213 exp.errors.emplace_back("range error: parameter '" + argv[i] + "' is not an integer in '" +
214 n->fullpath() + "'",
215 n);
216 return n->val();
217 }
218 }
219 if (argv.size() == 2)
220 int_args[2] = 1;
221
222 if (int_args[2] == 0)
223 {
224 exp.errors.emplace_back("range error: step is zero in '" + n->fullpath() + "'", n);
225 return n->val();
226 }
227
228 std::vector<std::string> names;
229 if (int_args[2] > 0)
230 {
231 if (int_args[1] < int_args[0])
232 {
233 exp.errors.emplace_back("range error: end point '" + argv[1] +
234 "' is smaller than the start point '" + argv[0] +
235 "' when the step is positive in '" + n->fullpath() + "'",
236 n);
237 return n->val();
238 }
239
240 for (int i = int_args[0]; i < int_args[1]; i += int_args[2])
241 names.push_back(std::to_string(i));
242 }
243 else
244 {
245 if (int_args[0] < int_args[1])
246 {
247 exp.errors.emplace_back("range error: start point '" + argv[0] +
248 "' is smaller than the end point '" + argv[1] +
249 "' when the step is negative in '" + n->fullpath() + "'",
250 n);
251 return n->val();
252 }
253
254 for (int i = int_args[0]; i > int_args[1]; i += int_args[2])
255 names.push_back(std::to_string(i));
256 }
257
258 return MooseUtils::stringJoin(names);
259}
auto exp(const T &)
bool convert(const std::string &str, T &value, const bool throw_on_failure)
Takes the string representation of a value and converts it to the value.
std::string stringJoin(const std::vector< std::string > &values, const std::string &separator=" ")
Concatenates value into a single string separated by separator.
IntRange< T > make_range(T beg, T end)

The documentation for this class was generated from the following files: