Gromacs
2024.3
|
#include <gromacs/commandline/cmdlineoptionsmodule.h>
Module that can be run from a command line and uses gmx::Options for argument processing.
This class provides a higher-level interface on top of gmx::ICommandLineModule for cases where gmx::Options will be used for declaring the command-line arguments. The module only needs to declare the options it uses, and the framework takes care of command-line parsing and help output. The module typically consists of the following parts:
registerModule(), runAsMain(), or createModule() can be used to use modules of this type in all contexts where a gmx::ICommandLineModule is expected. These methods create a gmx::ICommandLineModule implementation that contains the common code needed to parse command-line options and write help, based on the information provided from the methods in this class.
Public Types | |
typedef std::function < ICommandLineOptionsModulePointer()> | FactoryMethod |
Function pointer to a factory method that returns an interface of this type. More... | |
Public Member Functions | |
virtual void | init (CommandLineModuleSettings *settings)=0 |
Initializes the module and provides settings for the runner. More... | |
virtual void | initOptions (IOptionsContainer *options, ICommandLineOptionsModuleSettings *settings)=0 |
Initializes command-line arguments understood by the module. More... | |
virtual void | optionsFinished ()=0 |
Called after all option values have been set. More... | |
virtual int | run ()=0 |
Runs the module. More... | |
Static Public Member Functions | |
static std::unique_ptr < ICommandLineModule > | createModule (const char *name, const char *description, ICommandLineOptionsModulePointer module) |
Creates a ICommandLineModule to run the specified module. More... | |
static int | runAsMain (int argc, char *argv[], const char *name, const char *description, FactoryMethod factory) |
Implements a main() method that runs a single module. More... | |
static void | registerModuleFactory (CommandLineModuleManager *manager, const char *name, const char *description, FactoryMethod factory) |
Registers a module of a certain type to this manager. More... | |
static void | registerModuleDirect (CommandLineModuleManager *manager, const char *name, const char *description, ICommandLineOptionsModulePointer module) |
Registers a module to this manager. More... | |
typedef std::function<ICommandLineOptionsModulePointer()> gmx::ICommandLineOptionsModule::FactoryMethod |
Function pointer to a factory method that returns an interface of this type.
std::bad_alloc | if out of memory. |
|
static |
Creates a ICommandLineModule to run the specified module.
[in] | name | Name for the module. |
[in] | description | Short description for the module. |
[in] | module | Module to run. |
module
module. std::bad_alloc | if out of memory. |
|
pure virtual |
Initializes the module and provides settings for the runner.
This will be called before run(), and can be used to adjust initialization that the runner does.
This method is currently not called when writing the help.
|
pure virtual |
Initializes command-line arguments understood by the module.
[in,out] | options | Options object to add the options to. |
[in,out] | settings | Settings to communicate information to/from generic code running the module. |
When running the module, this method is called after init(). When printing help, there is no call to init(), and this is the only method called. In both cases, the implementation should add options understood by the module to options
. Output values from options should be stored in member variables.
|
pure virtual |
Called after all option values have been set.
When running the module, this method is called after all command-line arguments have been parsed.
|
static |
Registers a module to this manager.
manager | Manager to register to. | |
[in] | name | Name for the module. |
[in] | description | Short description for the module. |
[in] | module | Module to register. |
std::bad_alloc | if out of memory. |
This method internally creates a ICommandLineModule module with the given name
and description
, and adds that to manager
.
This method is mainly used by tests that need to have a reference to the ICommandLineOptionsModule instance (e.g., for mocking).
|
static |
Registers a module of a certain type to this manager.
manager | Manager to register to. | |
[in] | name | Name for the module. |
[in] | description | Short description for the module. |
[in] | factory | Factory that returns the module to register. |
std::bad_alloc | if out of memory. |
This method internally creates a ICommandLineModule module with the given name
and description
, and adds that to manager
. When run or asked to write the help, the module calls factory
to get the actual module, and forwards the necessary calls.
|
pure virtual |
Runs the module.
unspecified | May throw exceptions to indicate errors. |
0 | on successful termination. |
This method is called after optionsFinished() when running the module, and should do all the processing for the module.
|
static |
Implements a main() method that runs a single module.
argc | argc passed to main(). | |
argv | argv passed to main(). | |
[in] | name | Name for the module. |
[in] | description | Short description for the module. |
[in] | factory | Factory that returns the module to run. |
This method allows for uniform behavior for binaries that only contain a single module without duplicating any of the implementation from CommandLineModuleManager (startup headers, common options etc.).