diff --git a/src/utils.cpp b/src/utils.cpp index 55b029fc0d..4c299eec15 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -604,7 +604,7 @@ void utils::bounds(const char *file, int line, const std::string &str, { nlo = nhi = -1; - // check for illegal charcters + // check for illegal characters size_t found = str.find_first_not_of("*-0123456789"); if (found != std::string::npos) { if (error) error->all(file, line, "Invalid range string: {}", str); @@ -647,6 +647,30 @@ template void utils::bounds<>(const char *, int, const std::string &, bigint, bigint, long &, long &, Error *); template void utils::bounds<>(const char *, int, const std::string &, bigint, bigint, long long &, long long &, Error *); + +/* ---------------------------------------------------------------------- + wrapper for bounds() that accepts type label input +------------------------------------------------------------------------- */ + +template +void utils::bounds_typelabel(const char *file, int line, const std::string &str, bigint nmin, + bigint nmax, TYPE &nlo, TYPE &nhi, Error *error, LAMMPS *lmp, int mode) +{ + nlo = nhi = -1; + char *typestr; + if ( typestr = utils::expand_type(FLERR, str, mode, lmp) ) + nlo = nhi = utils::inumeric(FLERR, typestr, false, lmp); + delete[] typestr; + if (nlo > -1) return; + else utils::bounds(file, line, str, nmin, nmax, nlo, nhi, error); +} + +template void utils::bounds_typelabel<>(const char *, int, const std::string &, + bigint, bigint, int &, int &, Error *, LAMMPS *, int); +template void utils::bounds_typelabel<>(const char *, int, const std::string &, + bigint, bigint, long &, long &, Error *, LAMMPS *, int); +template void utils::bounds_typelabel<>(const char *, int, const std::string &, + bigint, bigint, long long &, long long &, Error *, LAMMPS *, int); // clang-format on /* ------------------------------------------------------------------------- diff --git a/src/utils.h b/src/utils.h index 383927ad34..01264bdb8e 100644 --- a/src/utils.h +++ b/src/utils.h @@ -331,6 +331,19 @@ namespace utils { void bounds(const char *file, int line, const std::string &str, bigint nmin, bigint nmax, TYPE &nlo, TYPE &nhi, Error *error); + /*! Same as bounds(), but supports type labels + * + * This functions adds the following case: + * + * - a single type label, typestr: nlo = nhi = label2type(typestr) + * + * \param lmp pointer to top-level LAMMPS class instance + * \param mode select labelmap using constants from Atom class */ + + template + void bounds_typelabel(const char *file, int line, const std::string &str, bigint nmin, bigint nmax, + TYPE &nlo, TYPE &nhi, Error *error, LAMMPS *lmp, int mode); + /*! Expand list of arguments when containing fix/compute wildcards * * This function searches the list of arguments in *arg* for strings