Unverified Commit b3bd3694 authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

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

parent e2efabc6
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -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
+1 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ class Variable : protected Pointers {
 public:
  Variable(class LAMMPS *);
  ~Variable();
  void set(const std::string &);
  void set(int, char **);
  void set(char *, int, char **);
  int set_string(char *, char *);