add convenience function to allow variable->set() command with a single string argument
This commit is contained in:
@ -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
|
||||||
|
|||||||
@ -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 *);
|
||||||
|
|||||||
Reference in New Issue
Block a user