Gromacs  2019-beta2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Functions | Variables
cmdlineinit.cpp File Reference
#include "gmxpre.h"
#include "cmdlineinit.h"
#include <cstring>
#include <memory>
#include <utility>
#include "gromacs/commandline/cmdlinemodulemanager.h"
#include "gromacs/commandline/cmdlineoptionsmodule.h"
#include "gromacs/commandline/cmdlineprogramcontext.h"
#include "gromacs/compat/make_unique.h"
#include "gromacs/utility/basenetwork.h"
#include "gromacs/utility/datafilefinder.h"
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/futil.h"
#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/init.h"
#include "gromacs/utility/programcontext.h"
#include "gromacs/utility/smalloc.h"
+ Include dependency graph for cmdlineinit.cpp:

Description

Implements functions from cmdlineinit.h.

Author
Teemu Murtola teemu.nosp@m..mur.nosp@m.tola@.nosp@m.gmai.nosp@m.l.com

Functions

void gmx::anonymous_namespace{cmdlineinit.cpp}::broadcastArguments (int *argc, char ***argv)
 Broadcasts command-line arguments to all ranks. More...
 
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...
 

Variables

std::unique_ptr
< CommandLineProgramContext > 
gmx::anonymous_namespace{cmdlineinit.cpp}::g_commandLineContext
 Global context instance initialized in initForCommandLine().
 
std::unique_ptr< DataFileFinder > gmx::anonymous_namespace{cmdlineinit.cpp}::g_libFileFinder
 Global library data file finder that respects GMXLIB.
 

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.

Parameters
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.

Usage:

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.