add convenience function to allow variable->set() command with a single string argument

This commit is contained in:
Axel Kohlmeyer
2020-07-17 00:46:31 -04:00
parent e2efabc6c4
commit b3bd36947d
2 changed files with 17 additions and 0 deletions

View File

@ -540,6 +540,22 @@ void Variable::set(int narg, char **arg)
nvar++;
}
/* ----------------------------------------------------------------------
convenience function to allow defining a variable from a single string
------------------------------------------------------------------------- */
void Variable::set(const std::string &setcmd)
{
std::vector<std::string> args = utils::split_words(setcmd);
char **newarg = new char*[args.size()];
int i=0;
for (const auto &arg : args) {
newarg[i++] = (char *)arg.c_str();
}
set(args.size(),newarg);
delete[] newarg;
}
/* ----------------------------------------------------------------------
INDEX variable created by command-line argument
make it INDEX rather than STRING so cannot be re-defined in input script