Gromacs  2020.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
#include <functional>
#include <memory>
#include "gromacs/commandline/cmdlineprogramcontext.h"
+ Include dependency graph for cmdlineinit.h:
+ This graph shows which files directly or indirectly include this file:


Declares functions for initializing the GROMACS library for command line use.

Teemu Murtola


CommandLineProgramContext & gmx::initForCommandLine (int *argc, char ***argv)
 Initializes the GROMACS library for command-line use. More...
void gmx::finalizeForCommandLine ()
 Deinitializes the GROMACS library after initForCommandLine(). More...
int gmx::processExceptionAtExitForCommandLine (const std::exception &ex)
 Handles an exception and deinitializes after initForCommandLine. More...
int gmx::runCommandLineModule (int argc, char *argv[], ICommandLineModule *module)
 Implements a main() method that runs a single module. More...
int gmx::runCommandLineModule (int argc, char *argv[], const char *name, const char *description, std::function< std::unique_ptr< ICommandLineOptionsModule >()> factory)
 Implements a main() method that runs a single module. More...
int gmx_run_cmain (int argc, char *argv[], int(*mainFunction)(int, char *[]))
 Implements a main() method that runs a given C main function. More...

Function Documentation

int gmx_run_cmain ( int  argc,
char *  argv[],
int(*)(int, char *[])  mainFunction 

Implements a main() method that runs a given C main function.

argcargc passed to main().
argvargv passed to main().
mainFunctionThe main()-like method to wrap.

This method creates a dummy command line module that does its processing by calling mainFunction. It then runs this module as with gmx::runCommandLineModule(). This allows the resulting executable to handle common options and do other common actions (e.g., startup headers) without duplicate code in the main methods.

mainFunction should call parse_common_args() to process its command-line arguments.


int my_main(int argc, char *argv[])
// <...>
int main(int argc, char *argv[])
return gmx_run_cmain(argc, argv, &my_main);

Does not throw. All exceptions are caught and handled internally.