make formatting and doxygen decorations for utils functions consistent
This commit is contained in:
@ -352,7 +352,7 @@ tagint utils::tnumeric(const char *file, int line, const char *str,
|
||||
Return string without leading or trailing whitespace
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
std::string utils::trim(const std::string & line) {
|
||||
std::string utils::trim(const std::string &line) {
|
||||
int beg = re_match(line.c_str(),"\\S+");
|
||||
int end = re_match(line.c_str(),"\\s+$");
|
||||
if (beg < 0) beg = 0;
|
||||
@ -365,7 +365,7 @@ std::string utils::trim(const std::string & line) {
|
||||
Return string without trailing # comment
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
std::string utils::trim_comment(const std::string & line) {
|
||||
std::string utils::trim_comment(const std::string &line) {
|
||||
auto end = line.find_first_of("#");
|
||||
if (end != std::string::npos) {
|
||||
return line.substr(0, end);
|
||||
@ -377,7 +377,7 @@ std::string utils::trim_comment(const std::string & line) {
|
||||
return number of words
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
size_t utils::count_words(const char * text) {
|
||||
size_t utils::count_words(const char *text) {
|
||||
size_t count = 0;
|
||||
const char * buf = text;
|
||||
char c = *buf;
|
||||
@ -406,7 +406,7 @@ size_t utils::count_words(const char * text) {
|
||||
return number of words
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
size_t utils::count_words(const std::string & text) {
|
||||
size_t utils::count_words(const std::string &text) {
|
||||
return utils::count_words(text.c_str());
|
||||
}
|
||||
|
||||
@ -414,7 +414,7 @@ size_t utils::count_words(const std::string & text) {
|
||||
Return number of words
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
size_t utils::count_words(const std::string & text, const std::string & separators) {
|
||||
size_t utils::count_words(const std::string &text, const std::string &separators) {
|
||||
size_t count = 0;
|
||||
size_t start = text.find_first_not_of(separators);
|
||||
|
||||
@ -435,7 +435,7 @@ size_t utils::count_words(const std::string & text, const std::string & separato
|
||||
Trim comment from string and return number of words
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
size_t utils::trim_and_count_words(const std::string & text, const std::string & separators) {
|
||||
size_t utils::trim_and_count_words(const std::string &text, const std::string &separators) {
|
||||
return utils::count_words(utils::trim_comment(text), separators);
|
||||
}
|
||||
|
||||
@ -526,7 +526,7 @@ std::vector<std::string> utils::split_words(const std::string &text)
|
||||
Return whether string is a valid integer number
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
bool utils::is_integer(const std::string & str) {
|
||||
bool utils::is_integer(const std::string &str) {
|
||||
if (str.size() == 0) {
|
||||
return false;
|
||||
}
|
||||
@ -542,7 +542,7 @@ bool utils::is_integer(const std::string & str) {
|
||||
Return whether string is a valid floating-point number
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
bool utils::is_double(const std::string & str) {
|
||||
bool utils::is_double(const std::string &str) {
|
||||
if (str.size() == 0) {
|
||||
return false;
|
||||
}
|
||||
@ -560,7 +560,7 @@ bool utils::is_double(const std::string & str) {
|
||||
strip off leading part of path, return just the filename
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
std::string utils::path_basename(const std::string & path) {
|
||||
std::string utils::path_basename(const std::string &path) {
|
||||
#if defined(_WIN32)
|
||||
size_t start = path.find_last_of("/\\");
|
||||
#else
|
||||
@ -580,7 +580,7 @@ std::string utils::path_basename(const std::string & path) {
|
||||
join two paths
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
std::string utils::path_join(const std::string & a, const std::string & b) {
|
||||
std::string utils::path_join(const std::string &a, const std::string &b) {
|
||||
#if defined(_WIN32)
|
||||
return fmt::format("{}\\{}", a, b);
|
||||
#else
|
||||
@ -592,7 +592,7 @@ std::string utils::path_join(const std::string & a, const std::string & b) {
|
||||
try to open file for reading
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
bool utils::file_is_readable(const std::string & path) {
|
||||
bool utils::file_is_readable(const std::string &path) {
|
||||
FILE * fp = fopen(path.c_str(), "r");
|
||||
if(fp) {
|
||||
fclose(fp);
|
||||
@ -607,7 +607,7 @@ bool utils::file_is_readable(const std::string & path) {
|
||||
specified
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
std::string utils::get_potential_file_path(const std::string& path) {
|
||||
std::string utils::get_potential_file_path(const std::string &path) {
|
||||
std::string filepath = path;
|
||||
std::string filename = utils::path_basename(path);
|
||||
|
||||
@ -634,7 +634,7 @@ std::string utils::get_potential_file_path(const std::string& path) {
|
||||
if it has a DATE field, return the following word
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
std::string utils::get_potential_date(const std::string & path, const std::string & potential_name) {
|
||||
std::string utils::get_potential_date(const std::string &path, const std::string &potential_name) {
|
||||
TextFileReader reader(path, potential_name);
|
||||
reader.ignore_comments = false;
|
||||
|
||||
@ -657,7 +657,7 @@ std::string utils::get_potential_date(const std::string & path, const std::strin
|
||||
if it has UNITS field, return following word
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
std::string utils::get_potential_units(const std::string & path, const std::string & potential_name) {
|
||||
std::string utils::get_potential_units(const std::string &path, const std::string &potential_name) {
|
||||
TextFileReader reader(path, potential_name);
|
||||
reader.ignore_comments = false;
|
||||
|
||||
@ -710,7 +710,7 @@ double utils::get_conversion_factor(const int property, const int conversion)
|
||||
the strings "off" and "unlimited" result in -1.0;
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
double utils::timespec2seconds(const std::string & timespec)
|
||||
double utils::timespec2seconds(const std::string ×pec)
|
||||
{
|
||||
double vals[3];
|
||||
int i = 0;
|
||||
@ -728,7 +728,7 @@ double utils::timespec2seconds(const std::string & timespec)
|
||||
if (!values.has_next()) break;
|
||||
vals[i] = values.next_int();
|
||||
}
|
||||
} catch (TokenizerException & e) {
|
||||
} catch (TokenizerException &e) {
|
||||
return -1.0;
|
||||
}
|
||||
|
||||
|
||||
130
src/utils.h
130
src/utils.h
@ -29,7 +29,7 @@ namespace LAMMPS_NS {
|
||||
|
||||
namespace utils {
|
||||
|
||||
/** \brief Match text against a simplified regex pattern
|
||||
/** Match text against a simplified regex pattern
|
||||
*
|
||||
* \param text the text to be matched against the pattern
|
||||
* \param pattern the search pattern, which may contain regexp markers
|
||||
@ -37,14 +37,14 @@ namespace LAMMPS_NS {
|
||||
*/
|
||||
bool strmatch(const std::string &text, const std::string &pattern);
|
||||
|
||||
/** \brief Send message to screen and logfile, if available
|
||||
/** Send message to screen and logfile, if available
|
||||
*
|
||||
* \param lmp pointer to LAMMPS class instance
|
||||
* \param mesg message to be printed
|
||||
*/
|
||||
void logmesg(LAMMPS *lmp, const std::string &mesg);
|
||||
|
||||
/** \brief return a string representing the current system error status
|
||||
/** return a string representing the current system error status
|
||||
*
|
||||
* This is a wrapper around calling strerror(errno).
|
||||
*
|
||||
@ -52,7 +52,7 @@ namespace LAMMPS_NS {
|
||||
*/
|
||||
std::string getsyserror();
|
||||
|
||||
/** \brief safe wrapper around fgets() which aborts on errors
|
||||
/** safe wrapper around fgets() which aborts on errors
|
||||
* or EOF and prints a suitable error message to help debugging
|
||||
*
|
||||
* \param srcname name of the calling source file (from FLERR macro)
|
||||
@ -66,7 +66,7 @@ namespace LAMMPS_NS {
|
||||
void sfgets(const char *srcname, int srcline, char *s, int size,
|
||||
FILE *fp, const char *filename, Error *error);
|
||||
|
||||
/** \brief safe wrapper around fread() which aborts on errors
|
||||
/** safe wrapper around fread() which aborts on errors
|
||||
* or EOF and prints a suitable error message to help debugging
|
||||
*
|
||||
* \param srcname name of the calling source file (from FLERR macro)
|
||||
@ -81,7 +81,7 @@ namespace LAMMPS_NS {
|
||||
void sfread(const char *srcname, int srcline, void *s, size_t size,
|
||||
size_t num, FILE *fp, const char *filename, Error *error);
|
||||
|
||||
/** \brief Report if a requested style is in a package or may have a typo
|
||||
/** Report if a requested style is in a package or may have a typo
|
||||
*
|
||||
* \param style type of style that is to be checked for
|
||||
* \param name name of style that was not found
|
||||
@ -91,8 +91,8 @@ namespace LAMMPS_NS {
|
||||
std::string check_packages_for_style(const std::string &style,
|
||||
const std::string &name, LAMMPS *lmp);
|
||||
|
||||
/** \brief Convert a string to a floating point number while checking
|
||||
if it is a valid floating point or integer number
|
||||
/** Convert a string to a floating point number while checking
|
||||
* if it is a valid floating point or integer number
|
||||
*
|
||||
* \param file name of source file for error message
|
||||
* \param line in source file for error message
|
||||
@ -104,8 +104,8 @@ namespace LAMMPS_NS {
|
||||
double numeric(const char *file, int line, const char *str,
|
||||
bool do_abort, LAMMPS *lmp);
|
||||
|
||||
/** \brief Convert a string to an integer number while checking
|
||||
if it is a valid integer number (regular int)
|
||||
/** Convert a string to an integer number while checking
|
||||
* if it is a valid integer number (regular int)
|
||||
*
|
||||
* \param file name of source file for error message
|
||||
* \param line in source file for error message
|
||||
@ -117,8 +117,8 @@ namespace LAMMPS_NS {
|
||||
int inumeric(const char *file, int line, const char *str,
|
||||
bool do_abort, LAMMPS *lmp);
|
||||
|
||||
/** \brief Convert a string to an integer number while checking
|
||||
if it is a valid integer number (bigint)
|
||||
/** Convert a string to an integer number while checking
|
||||
* if it is a valid integer number (bigint)
|
||||
*
|
||||
* \param file name of source file for error message
|
||||
* \param line in source file for error message
|
||||
@ -130,8 +130,8 @@ namespace LAMMPS_NS {
|
||||
bigint bnumeric(const char *file, int line, const char *str,
|
||||
bool do_abort, LAMMPS *lmp);
|
||||
|
||||
/** \brief Convert a string to an integer number while checking
|
||||
if it is a valid integer number (tagint)
|
||||
/** Convert a string to an integer number while checking
|
||||
* if it is a valid integer number (tagint)
|
||||
*
|
||||
* \param file name of source file for error message
|
||||
* \param line in source file for error message
|
||||
@ -143,54 +143,51 @@ namespace LAMMPS_NS {
|
||||
tagint tnumeric(const char *file, int line, const char *str,
|
||||
bool do_abort, LAMMPS *lmp);
|
||||
|
||||
/**
|
||||
* \brief Trim leading and trailing whitespace. Like TRIM() in Fortran.
|
||||
/** Trim leading and trailing whitespace. Like TRIM() in Fortran.
|
||||
*
|
||||
* \param line string that should be trimmed
|
||||
* \return new string without whitespace (string)
|
||||
*/
|
||||
std::string trim(const std::string &line);
|
||||
|
||||
/**
|
||||
* \brief Trim anything from '#' onward
|
||||
/** Trim anything from '#' onward
|
||||
*
|
||||
* \param line string that should be trimmed
|
||||
* \return new string without comment (string)
|
||||
*/
|
||||
std::string trim_comment(const std::string &line);
|
||||
|
||||
/**
|
||||
* \brief Count words in string
|
||||
/** Count words in string
|
||||
*
|
||||
* \param text string that should be searched
|
||||
* \param separators string containing characters that will be treated as whitespace
|
||||
* \return number of words found
|
||||
*/
|
||||
size_t count_words(const std::string & text, const std::string & separators);
|
||||
size_t count_words(const std::string &text, const std::string &separators);
|
||||
|
||||
/**
|
||||
* \brief Count words in string, ignore any whitespace matching " \t\r\n\f"
|
||||
/** Count words in string, ignore any whitespace matching " \t\r\n\f"
|
||||
*
|
||||
* \param text string that should be searched
|
||||
* \param separators string containing characters that will be treated as whitespace
|
||||
* \return number of words found
|
||||
*/
|
||||
size_t count_words(const std::string & text);
|
||||
size_t count_words(const std::string &text);
|
||||
|
||||
/**
|
||||
* \brief Count words in C-string, ignore any whitespace matching " \t\r\n\f"
|
||||
/** Count words in C-string, ignore any whitespace matching " \t\r\n\f"
|
||||
*
|
||||
* \param text string that should be searched
|
||||
* \param separators string containing characters that will be treated as whitespace
|
||||
* \return number of words found
|
||||
*/
|
||||
size_t count_words(const char * text);
|
||||
size_t count_words(const char *text);
|
||||
|
||||
/**
|
||||
* \brief Count words in a single line, trim anything from '#' onward
|
||||
/** Count words in a single line, trim anything from '#' onward
|
||||
*
|
||||
* \param text string that should be trimmed and searched
|
||||
* \param separators string containing characters that will be treated as whitespace
|
||||
* \return number of words found
|
||||
*/
|
||||
size_t trim_and_count_words(const std::string & text, const std::string & separators = " \t\r\n\f");
|
||||
size_t trim_and_count_words(const std::string &text, const std::string &separators = " \t\r\n\f");
|
||||
|
||||
/**
|
||||
* \brief Take text and split into non-whitespace words.
|
||||
/** Take text and split into non-whitespace words.
|
||||
*
|
||||
* This can handle single and double quotes, escaped quotes,
|
||||
* and escaped codes within quotes, but due to using an STL
|
||||
@ -203,21 +200,21 @@ namespace LAMMPS_NS {
|
||||
*/
|
||||
std::vector<std::string> split_words(const std::string &text);
|
||||
|
||||
/**
|
||||
* \brief Check if string can be converted to valid integer
|
||||
* \param text string that should be checked
|
||||
/** Check if string can be converted to valid integer
|
||||
*
|
||||
* \param str string that should be checked
|
||||
* \return true, if string contains valid integer, false otherwise
|
||||
*/
|
||||
bool is_integer(const std::string & str);
|
||||
bool is_integer(const std::string &str);
|
||||
|
||||
/**
|
||||
* \brief Check if string can be converted to valid floating-point number
|
||||
* \param text string that should be checked
|
||||
/** Check if string can be converted to valid floating-point number
|
||||
*
|
||||
* \param str string that should be checked
|
||||
* \return true, if string contains valid floating-point number, false otherwise
|
||||
*/
|
||||
bool is_double(const std::string & str);
|
||||
bool is_double(const std::string &str);
|
||||
|
||||
/** \brief try to detect pathname from FILE pointer.
|
||||
/** Try to detect pathname from FILE pointer.
|
||||
*
|
||||
* Currently only supported on Linux, otherwise will report "(unknown)".
|
||||
*
|
||||
@ -228,12 +225,12 @@ namespace LAMMPS_NS {
|
||||
*/
|
||||
const char *guesspath(char *buf, int len, FILE *fp);
|
||||
|
||||
/**
|
||||
* \brief Strip off leading part of path, return just the filename
|
||||
/** Strip off leading part of path, return just the filename
|
||||
*
|
||||
* \param path file path
|
||||
* \return file name
|
||||
*/
|
||||
std::string path_basename(const std::string & path);
|
||||
std::string path_basename(const std::string &path);
|
||||
|
||||
/**
|
||||
* \brief Join two paths
|
||||
@ -241,64 +238,65 @@ namespace LAMMPS_NS {
|
||||
* \param b second path
|
||||
* \return combined path
|
||||
*/
|
||||
std::string path_join(const std::string & a, const std::string & b);
|
||||
std::string path_join(const std::string &a, const std::string &b);
|
||||
|
||||
/**
|
||||
* \brief Check if file exists and is readable
|
||||
* \param path file path
|
||||
* \return true if file exists and is readable
|
||||
*/
|
||||
bool file_is_readable(const std::string & path);
|
||||
bool file_is_readable(const std::string &path);
|
||||
|
||||
/**
|
||||
* \brief Determine full path of potential file
|
||||
* If file is not found in current directory, search LAMMPS_POTENTIALS folder
|
||||
/** Determine full path of potential file. If file is not found in current directory,
|
||||
* search LAMMPS_POTENTIALS folder
|
||||
*
|
||||
* \param path file path
|
||||
* \return full path to potential file
|
||||
*/
|
||||
std::string get_potential_file_path(const std::string& path);
|
||||
std::string get_potential_file_path(const std::string &path);
|
||||
|
||||
/**
|
||||
* \brief Read potential file and return DATE field if it is present
|
||||
/** Read potential file and return DATE field if it is present
|
||||
*
|
||||
* \param path file path
|
||||
* \param potential_name name of potential that is being read
|
||||
* \return DATE field if present
|
||||
*/
|
||||
std::string get_potential_date(const std::string & path, const std::string & potential_name);
|
||||
std::string get_potential_date(const std::string &path, const std::string &potential_name);
|
||||
|
||||
/**
|
||||
* \brief Read potential file and return UNITS field if it is present
|
||||
/** Read potential file and return UNITS field if it is present
|
||||
*
|
||||
* \param path file path
|
||||
* \param potential_name name of potential that is being read
|
||||
* \return UNITS field if present
|
||||
*/
|
||||
std::string get_potential_units(const std::string & path, const std::string & potential_name);
|
||||
std::string get_potential_units(const std::string &path, const std::string &potential_name);
|
||||
|
||||
enum { NOCONVERT = 0, METAL2REAL = 1, REAL2METAL = 1<<1 };
|
||||
enum { UNKNOWN = 0, ENERGY };
|
||||
|
||||
/**
|
||||
* \brief Return bitmask of available conversion factors for a given propert
|
||||
/** Return bitmask of available conversion factors for a given property
|
||||
*
|
||||
* \param property property to be converted
|
||||
* \return bitmask indicating available conversions
|
||||
*/
|
||||
int get_supported_conversions(const int property);
|
||||
|
||||
/**
|
||||
* \brief Return unit conversion factor for given property and selected from/to units
|
||||
/** Return unit conversion factor for given property and selected from/to units
|
||||
*
|
||||
* \param property property to be converted
|
||||
* \param conversion constant indicating the conversion
|
||||
* \return conversion factor
|
||||
*/
|
||||
double get_conversion_factor(const int property, const int conversion);
|
||||
|
||||
/**
|
||||
* \brief Convert a time string to seconds
|
||||
* The strings "off" and "unlimited" result in -1
|
||||
/** Convert a time string to seconds
|
||||
*
|
||||
* The strings "off" and "unlimited" result in -1
|
||||
*
|
||||
* \param timespec a string in the following format: ([[HH:]MM:]SS)
|
||||
* \return total in seconds
|
||||
*/
|
||||
double timespec2seconds(const std::string & timespec);
|
||||
double timespec2seconds(const std::string ×pec);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user