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

#include <Parser.h>

Inheritance diagram for EnumerateEvaler:
[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 36 of file Parser.h.

Member Function Documentation

◆ eval()

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

Definition at line 144 of file Parser.C.

145{
146 std::vector<std::string> argv;
147 argv.insert(argv.begin(), args.begin(), args.end());
148
149 if (argv.size() != 3)
150 {
151 exp.errors.emplace_back(
152 "enumerate error: Expected 3 arguments ${enumerate prefix first_index last_index} in '" +
153 n->fullpath() + "'",
154 n);
155 return n->val();
156 }
157
158 const auto & prefix = argv[0];
159 std::array<int, 2> index;
160 for (const auto i : make_range(2))
161 {
162 const auto & arg = argv[i + 1];
163 if (arg.empty() || arg.find_first_not_of("0123456789") != std::string::npos)
164 {
165 exp.errors.emplace_back("enumerate error: index '" + arg +
166 "' is not a non-negative integer in '" + n->fullpath() + "'",
167 n);
168 return n->val();
169 }
170 index[i] = MooseUtils::convert<int>(arg);
171 }
172
173 if (index[1] < index[0])
174 {
175 exp.errors.emplace_back("enumerate error: last index " + argv[2] +
176 " is smaller than first index " + argv[1] + " in '" +
177 n->fullpath() + "'",
178 n);
179 return n->val();
180 }
181
182 std::vector<std::string> names;
183 for (const auto i : make_range(index[0], index[1] + 1))
184 names.push_back(prefix + std::to_string(i));
185
186 return MooseUtils::stringJoin(names);
187}
auto exp(const T &)
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: