bounds() wrapper for type labels

This commit is contained in:
Jacob Gissinger
2024-05-12 14:30:55 -04:00
parent 61b9469fd1
commit 44b99b6b76
2 changed files with 38 additions and 1 deletions

View File

@ -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 <typename TYPE>
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
/* -------------------------------------------------------------------------