add convenience function for printing a missing arguments error message
This commit is contained in:
@ -211,6 +211,9 @@ Convenience functions
|
||||
.. doxygenfunction:: logmesg(LAMMPS *lmp, const std::string &mesg)
|
||||
:project: progguide
|
||||
|
||||
.. doxygenfunction:: missing_cmd_args
|
||||
:project: progguide
|
||||
|
||||
.. doxygenfunction:: flush_buffers(LAMMPS *lmp)
|
||||
:project: progguide
|
||||
|
||||
|
||||
@ -22,8 +22,8 @@
|
||||
#include "memory.h"
|
||||
#include "modify.h"
|
||||
#include "text_file_reader.h"
|
||||
#include "update.h"
|
||||
#include "universe.h"
|
||||
#include "update.h"
|
||||
|
||||
#include <cctype>
|
||||
#include <cerrno>
|
||||
@ -120,6 +120,12 @@ std::string utils::strfind(const std::string &text, const std::string &pattern)
|
||||
return "";
|
||||
}
|
||||
|
||||
void utils::missing_cmd_args(const std::string &file, int line, const std::string &cmd,
|
||||
Error *error)
|
||||
{
|
||||
if (error) error->all(file, line, "Illegal {} command: missing argument(s)", cmd);
|
||||
}
|
||||
|
||||
/* specialization for the case of just a single string argument */
|
||||
|
||||
void utils::logmesg(LAMMPS *lmp, const std::string &mesg)
|
||||
@ -141,7 +147,7 @@ void utils::flush_buffers(LAMMPS *lmp)
|
||||
{
|
||||
if (lmp->screen) fflush(lmp->screen);
|
||||
if (lmp->logfile) fflush(lmp->logfile);
|
||||
if (lmp->universe->uscreen) fflush(lmp->universe->uscreen);
|
||||
if (lmp->universe->uscreen) fflush(lmp->universe->uscreen);
|
||||
if (lmp->universe->ulogfile) fflush(lmp->universe->ulogfile);
|
||||
}
|
||||
|
||||
@ -566,14 +572,14 @@ void utils::bounds(const char *file, int line, const std::string &str,
|
||||
error->all(file, line, fmt::format("Invalid range string: {}", str));
|
||||
|
||||
if (nlo < nmin)
|
||||
error->all(file, line, fmt::format("Numeric index {} is out of bounds "
|
||||
"({}-{})", nlo, nmin, nmax));
|
||||
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));
|
||||
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));
|
||||
error->all(file, line, fmt::format("Numeric index {} is out of bounds ({}-{})",
|
||||
nlo, nmin, nhi));
|
||||
}
|
||||
}
|
||||
|
||||
@ -805,7 +811,7 @@ std::string utils::star_subst(const std::string &name, bigint step, int pad)
|
||||
auto star = name.find('*');
|
||||
if (star == std::string::npos) return name;
|
||||
|
||||
return fmt::format("{}{:0{}}{}",name.substr(0,star),step,pad,name.substr(star+1));
|
||||
return fmt::format("{}{:0{}}{}", name.substr(0, star), step, pad, name.substr(star + 1));
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
|
||||
14
src/utils.h
14
src/utils.h
@ -21,7 +21,7 @@
|
||||
|
||||
#include <mpi.h>
|
||||
|
||||
#include <vector> // IWYU pragma: export
|
||||
#include <vector> // IWYU pragma: export
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
|
||||
@ -47,6 +47,18 @@ namespace utils {
|
||||
|
||||
std::string strfind(const std::string &text, const std::string &pattern);
|
||||
|
||||
/*! Print error message about missing arguments for command
|
||||
*
|
||||
* This function simplifies the repetitive reporting missing arguments to a command.
|
||||
*
|
||||
* \param file name of source file for error message
|
||||
* \param line line number in source file for error message
|
||||
* \param cmd name of the failing command
|
||||
* \param error pointer to Error class instance (for abort) or nullptr */
|
||||
|
||||
[[noreturn]] void missing_cmd_args(const std::string &file, int line, const std::string &cmd,
|
||||
Error *error);
|
||||
|
||||
/* Internal function handling the argument list for logmesg(). */
|
||||
|
||||
void fmtargs_logmesg(LAMMPS *lmp, fmt::string_view format, fmt::format_args args);
|
||||
|
||||
Reference in New Issue
Block a user