From eec037ac5e65760bd8e435ba5c8383f2a169f0a4 Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Thu, 18 Apr 2024 13:41:51 -0400 Subject: [PATCH] make use of refactored expand_type elsewhere --- src/set.cpp | 50 ++++++++++++++++---------------------------------- 1 file changed, 16 insertions(+), 34 deletions(-) diff --git a/src/set.cpp b/src/set.cpp index cee769a573..ab9b879849 100644 --- a/src/set.cpp +++ b/src/set.cpp @@ -90,22 +90,16 @@ void Set::command(int narg, char **arg) if (strcmp(arg[iarg],"type") == 0) { if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "set type", error); - if (utils::strmatch(arg[iarg+1],"^v_")) varparse(arg[iarg+1],1); - else { - char *typestr = utils::expand_type(FLERR,arg[iarg+1],Atom::ATOM,lmp); - ivalue = utils::inumeric(FLERR,typestr?typestr:arg[iarg+1],false,lmp); - delete[] typestr; - } + if (utils::strmatch(arg[iarg+1],"^v_")) varparse(arg[iarg+1], 1); + else ivalue = utils::expand_type_int(FLERR, arg[iarg+1], Atom::ATOM, lmp); set(TYPE); iarg += 2; } else if (strcmp(arg[iarg],"type/fraction") == 0) { if (iarg+4 > narg) utils::missing_cmd_args(FLERR, "set type/fraction", error); - char *typestr = utils::expand_type(FLERR,arg[iarg+1],Atom::ATOM,lmp); - newtype = utils::inumeric(FLERR,typestr?typestr:arg[iarg+1],false,lmp); - delete[] typestr; - fraction = utils::numeric(FLERR,arg[iarg+2],false,lmp); - ivalue = utils::inumeric(FLERR,arg[iarg+3],false,lmp); + newtype = utils::expand_type_int(FLERR, arg[iarg+1], Atom::ATOM, lmp); + fraction = utils::numeric(FLERR, arg[iarg+2], false, lmp); + ivalue = utils::inumeric(FLERR, arg[iarg+3], false, lmp); if (newtype <= 0 || newtype > atom->ntypes) error->all(FLERR,"Invalid type value {} in set type/fraction command", newtype); if (fraction < 0.0 || fraction > 1.0) @@ -117,11 +111,9 @@ void Set::command(int narg, char **arg) } else if (strcmp(arg[iarg],"type/ratio") == 0) { if (iarg+4 > narg) utils::missing_cmd_args(FLERR, "set type/ratio", error); - char *typestr = utils::expand_type(FLERR,arg[iarg+1],Atom::ATOM,lmp); - newtype = utils::inumeric(FLERR,typestr?typestr:arg[iarg+1],false,lmp); - delete[] typestr; - fraction = utils::numeric(FLERR,arg[iarg+2],false,lmp); - ivalue = utils::inumeric(FLERR,arg[iarg+3],false,lmp); + newtype = utils::expand_type_int(FLERR, arg[iarg+1], Atom::ATOM, lmp); + fraction = utils::numeric(FLERR, arg[iarg+2], false, lmp); + ivalue = utils::inumeric(FLERR, arg[iarg+3], false, lmp); if (newtype <= 0 || newtype > atom->ntypes) error->all(FLERR,"Invalid type value {} in set type/ratio command", newtype); if (fraction < 0.0 || fraction > 1.0) @@ -133,11 +125,9 @@ void Set::command(int narg, char **arg) } else if (strcmp(arg[iarg],"type/subset") == 0) { if (iarg+4 > narg) utils::missing_cmd_args(FLERR, "set type/subset", error); - char *typestr = utils::expand_type(FLERR,arg[iarg+1],Atom::ATOM,lmp); - newtype = utils::inumeric(FLERR,typestr?typestr:arg[iarg+1],false,lmp); - delete[] typestr; - nsubset = utils::bnumeric(FLERR,arg[iarg+2],false,lmp); - ivalue = utils::inumeric(FLERR,arg[iarg+3],false,lmp); + newtype = utils::expand_type_int(FLERR, arg[iarg+1], Atom::ATOM, lmp); + nsubset = utils::bnumeric(FLERR, arg[iarg+2], false, lmp); + ivalue = utils::inumeric(FLERR, arg[iarg+3], false, lmp); if (newtype <= 0 || newtype > atom->ntypes) error->all(FLERR,"Invalid type value {} in set type/subset command", newtype); if (nsubset < 0) @@ -485,9 +475,7 @@ void Set::command(int narg, char **arg) } else if (strcmp(arg[iarg],"bond") == 0) { if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "set bond", error); - char *typestr = utils::expand_type(FLERR,arg[iarg+1],Atom::BOND,lmp); - ivalue = utils::inumeric(FLERR,typestr?typestr:arg[iarg+1],false,lmp); - delete[] typestr; + ivalue = utils::expand_type_int(FLERR, arg[iarg+1], Atom::BOND, lmp); if (atom->avec->bonds_allow == 0) error->all(FLERR,"Cannot set attribute {} for atom style {}", arg[iarg], atom->get_style()); if (ivalue <= 0 || ivalue > atom->nbondtypes) @@ -497,9 +485,7 @@ void Set::command(int narg, char **arg) } else if (strcmp(arg[iarg],"angle") == 0) { if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "set angle", error); - char *typestr = utils::expand_type(FLERR,arg[iarg+1],Atom::ANGLE,lmp); - ivalue = utils::inumeric(FLERR,typestr?typestr:arg[iarg+1],false,lmp); - delete[] typestr; + ivalue = utils::expand_type_int(FLERR, arg[iarg+1], Atom::ANGLE, lmp); if (atom->avec->angles_allow == 0) error->all(FLERR,"Cannot set attribute {} for atom style {}", arg[iarg], atom->get_style()); if (ivalue <= 0 || ivalue > atom->nangletypes) @@ -509,9 +495,7 @@ void Set::command(int narg, char **arg) } else if (strcmp(arg[iarg],"dihedral") == 0) { if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "set dihedral", error); - char *typestr = utils::expand_type(FLERR,arg[iarg+1],Atom::DIHEDRAL,lmp); - ivalue = utils::inumeric(FLERR,typestr?typestr:arg[iarg+1],false,lmp); - delete[] typestr; + ivalue = utils::expand_type_int(FLERR, arg[iarg+1], Atom::DIHEDRAL, lmp); if (atom->avec->dihedrals_allow == 0) error->all(FLERR,"Cannot set attribute {} for atom style {}", arg[iarg], atom->get_style()); if (ivalue <= 0 || ivalue > atom->ndihedraltypes) @@ -521,9 +505,7 @@ void Set::command(int narg, char **arg) } else if (strcmp(arg[iarg],"improper") == 0) { if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "set improper", error); - char *typestr = utils::expand_type(FLERR,arg[iarg+1],Atom::IMPROPER,lmp); - ivalue = utils::inumeric(FLERR,typestr?typestr:arg[iarg+1],false,lmp); - delete[] typestr; + ivalue = utils::expand_type_int(FLERR, arg[iarg+1], Atom::IMPROPER, lmp); if (atom->avec->impropers_allow == 0) error->all(FLERR,"Cannot set attribute {} for atom style {}", arg[iarg], atom->get_style()); if (ivalue <= 0 || ivalue > atom->nimpropertypes) @@ -758,7 +740,7 @@ void Set::selection(int n) else select[i] = 0; } else if (style == TYPE_SELECT) { - if (char *typestr = utils::expand_type(FLERR,id,Atom::ATOM,lmp)) { + if (char *typestr = utils::expand_type(FLERR, id, Atom::ATOM, lmp)) { // is this mem leak? delete[] id; id = typestr; }