MolSim
Loading...
Searching...
No Matches
Functions | Variables
CLIUtils Namespace Reference

Namespace defining utility functions for handling console output. More...

Functions

static std::string getCompilerName ()
 Gets the name of the compiler used to build the program executable (or "unknown" if the compiler is not identifiable via macros).
 
static std::string getBuildDate ()
 Gets the build date and time of the built executable as a string.
 
static void printUsage ()
 Prints a usage string explaining the syntax of the main program.
 
static void printHelp ()
 Prints a help string explaining the functionality of the main program.
 
static int getPercentage (int x, int y)
 Gets the percentage as an integer from a fraction x / y.
 
static void error (const char *msg, const std::string &opt="", bool usage=true, bool close=true)
 Prints an error message to stderr with the prefix "ERROR: ", optionally prints the usage string and exits with EXIT_FAILURE.
 

Variables

static std::string_view filename {"./MolSim"}
 The filename of the executable (default: "./MolSim").
 
static std::unordered_map< char, std::string > optionNames
 Mapping from getopt option characters to their full names.
 

Detailed Description

Namespace defining utility functions for handling console output.

Function Documentation

◆ error()

static void CLIUtils::error ( const char *  msg,
const std::string &  opt = "",
bool  usage = true,
bool  close = true 
)
inlinestatic

Prints an error message to stderr with the prefix "ERROR: ", optionally prints the usage string and exits with EXIT_FAILURE.

This is typically used when the user does something wrong and has a different format to error logs printed with spdlog.

Parameters
msgThe message to be printed to stderr.
optAn optional extra string to be appended at the end (default: empty).
usageAn optional boolean which defines whether or not the usage string should be printed.
closeAn optional boolean which defines whether or not the program should completely exit afterwards.

◆ getBuildDate()

static std::string CLIUtils::getBuildDate ( )
inlinestatic

Gets the build date and time of the built executable as a string.

Returns
The build date and time of the built executable.

◆ getCompilerName()

static std::string CLIUtils::getCompilerName ( )
inlinestatic

Gets the name of the compiler used to build the program executable (or "unknown" if the compiler is not identifiable via macros).

Returns
The name of the compiler used to build the executable or "unknown".

◆ getPercentage()

static int CLIUtils::getPercentage ( int  x,
int  y 
)
inlinestatic

Gets the percentage as an integer from a fraction x / y.

Parameters
xThe numerator.
yThe denominator. If this is 0, 100 is returned.
Returns
The percentage as a truncated integer.

◆ printHelp()

static void CLIUtils::printHelp ( )
inlinestatic

Prints a help string explaining the functionality of the main program.

◆ printUsage()

static void CLIUtils::printUsage ( )
inlinestatic

Prints a usage string explaining the syntax of the main program.

Variable Documentation

◆ filename

std::string_view CLIUtils::filename {"./MolSim"}
inlinestatic

The filename of the executable (default: "./MolSim").

◆ optionNames

std::unordered_map<char, std::string> CLIUtils::optionNames
inlinestatic
Initial value:
= {
{'s', "Start time"}, {'e', "End time"},
{'d', "Timestep"}, {'b', "Basename"},
{'f', "Output frequency"}, {'g', "Gravity"},
{'o', "Output type"}, {'p', "Parallelization type"},
{'t', "Simulation type"}, {'B', "Boundary Conditions"},
{'D', "Domain Size"}, {'R', "Cutoff Radius"}}

Mapping from getopt option characters to their full names.