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 dd7bc1d34e
commit 63bebf58fd
2 changed files with 17 additions and 0 deletions

View File

@ -540,6 +540,22 @@ void Variable::set(int narg, char **arg)
nvar++; 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 INDEX variable created by command-line argument
make it INDEX rather than STRING so cannot be re-defined in input script make it INDEX rather than STRING so cannot be re-defined in input script

View File

@ -24,6 +24,7 @@ class Variable : protected Pointers {
public: public:
Variable(class LAMMPS *); Variable(class LAMMPS *);
~Variable(); ~Variable();
void set(const std::string &);
void set(int, char **); void set(int, char **);
void set(char *, int, char **); void set(char *, int, char **);
int set_string(char *, char *); int set_string(char *, char *);