modernize utils::bounds() implementation and remove duplicate definition.
This commit is contained in:
@ -359,27 +359,27 @@ tagint utils::tnumeric(const char *file, int line, const char *str,
|
|||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
compute bounds implied by numeric str with a possible wildcard asterisk
|
compute bounds implied by numeric str with a possible wildcard asterisk
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
template<>
|
template<typename TYPE>
|
||||||
void utils::bounds(const char *file, int line, char *str,
|
void utils::bounds(const char *file, int line, const std::string &str,
|
||||||
bigint nmin, bigint nmax, int &nlo, int &nhi, Error *error)
|
bigint nmin, bigint nmax, TYPE &nlo, TYPE &nhi, Error *error)
|
||||||
{
|
{
|
||||||
char *ptr = strchr(str,'*');
|
size_t found = str.find_first_of("*");
|
||||||
|
|
||||||
nlo = nhi = -1;
|
nlo = nhi = -1;
|
||||||
if (ptr == NULL) {
|
if (found == std::string::npos) { // contains no '*'
|
||||||
nlo = nhi = atoi(str);
|
nlo = nhi = strtol(str.c_str(),NULL,10);
|
||||||
} else if (strlen(str) == 1) {
|
} else if (str.size() == 1) { // is only '*'
|
||||||
nlo = nmin;
|
nlo = nmin;
|
||||||
nhi = nmax;
|
nhi = nmax;
|
||||||
} else if (ptr == str) {
|
} else if (found == 0) { // is '*j'
|
||||||
nlo = nmin;
|
nlo = nmin;
|
||||||
nhi = atoi(ptr+1);
|
nhi = strtol(str.substr(1).c_str(),NULL,10);
|
||||||
} else if (strlen(ptr+1) == 0) {
|
} else if (str.size() == found+1) { // is 'i*'
|
||||||
nlo = atoi(str);
|
nlo = strtol(str.c_str(),NULL,10);
|
||||||
nhi = nmax;
|
nhi = nmax;
|
||||||
} else {
|
} else { // is 'i*j'
|
||||||
nlo = atoi(str);
|
nlo = strtol(str.c_str(),NULL,10);
|
||||||
nhi = atoi(ptr+1);
|
nhi = strtol(str.substr(found+1).c_str(),NULL,10);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
@ -395,46 +395,10 @@ void utils::bounds(const char *file, int line, char *str,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template void utils::bounds<>(const char *, int, const std::string &,
|
||||||
/* ----------------------------------------------------------------------
|
bigint, bigint, int &, int &, Error *);
|
||||||
compute bounds implied by numeric str with a possible wildcard asterisk
|
template void utils::bounds<>(const char *, int, const std::string &,
|
||||||
------------------------------------------------------------------------- */
|
bigint, bigint, long &, long &, Error *);
|
||||||
template <>
|
|
||||||
void utils::bounds(const char *file, int line, char *str,
|
|
||||||
bigint nmin, bigint nmax, bigint &nlo, bigint &nhi,
|
|
||||||
Error *error)
|
|
||||||
{
|
|
||||||
char *ptr = strchr(str,'*');
|
|
||||||
|
|
||||||
nlo = nhi = -1;
|
|
||||||
if (ptr == NULL) {
|
|
||||||
nlo = nhi = ATOBIGINT(str);
|
|
||||||
} else if (strlen(str) == 1) {
|
|
||||||
nlo = nmin;
|
|
||||||
nhi = nmax;
|
|
||||||
} else if (ptr == str) {
|
|
||||||
nlo = nmin;
|
|
||||||
nhi = ATOBIGINT(ptr+1);
|
|
||||||
} else if (strlen(ptr+1) == 0) {
|
|
||||||
nlo = ATOBIGINT(str);
|
|
||||||
nhi = nmax;
|
|
||||||
} else {
|
|
||||||
nlo = ATOBIGINT(str);
|
|
||||||
nhi = ATOBIGINT(ptr+1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (error) {
|
|
||||||
if (nlo < nmin)
|
|
||||||
error->all(file,line,fmt::format("Numeric index {} is out of bounds"
|
|
||||||
"({}-{})",nlo,nmin,nmax));
|
|
||||||
else if (nhi > nmax)
|
|
||||||
error->all(file,line,fmt::format("Numeric index {} is out of bounds"
|
|
||||||
"({}-{})",nhi,nmin,nmax));
|
|
||||||
else if (nlo > nhi)
|
|
||||||
error->all(file,line,fmt::format("Numeric index {} is out of bounds"
|
|
||||||
"({}-{})",nlo,nmin,nhi));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------
|
||||||
Expand list of arguments in arg to earg if arg contains wildcards
|
Expand list of arguments in arg to earg if arg contains wildcards
|
||||||
|
|||||||
@ -163,7 +163,7 @@ namespace LAMMPS_NS {
|
|||||||
* \param nhi upper bound
|
* \param nhi upper bound
|
||||||
* \param error pointer to Error class for out-of-bounds messages */
|
* \param error pointer to Error class for out-of-bounds messages */
|
||||||
template <typename TYPE>
|
template <typename TYPE>
|
||||||
void bounds(const char *file, int line, char *str,
|
void bounds(const char *file, int line, const std::string &str,
|
||||||
bigint nmin, bigint nmax, TYPE &nlo, TYPE &nhi, Error *error);
|
bigint nmin, bigint nmax, TYPE &nlo, TYPE &nhi, Error *error);
|
||||||
|
|
||||||
/** Expand list of arguments when containing fix/compute wildcards
|
/** Expand list of arguments when containing fix/compute wildcards
|
||||||
|
|||||||
Reference in New Issue
Block a user