Gromacs
2024.4
|
#include <gromacs/options/filenameoptionmanager.h>
Handles interaction of file name options with global options.
This class contains all logic that completes file names based on user input and file system contents. Additionally, this class implements support for a global default file name that overrides any option-specific default, as well as additional control over how the completion is done.
commandline
module.Adding a FileNameOptionManager for an Options object is optional, even if the Options contains FileNameOption options. Features from the manager are not available if the manager is not created, but otherwise the options work: the values provided to FileNameOption are used as they are, and exceptions are thrown if they are no valid instead of attempting to complete them.
Public Member Functions | |
void | setInputRedirector (const IFileInputRedirector *redirector) |
Redirects file existence checks. More... | |
void | disableInputOptionChecking (bool bDisable) |
Disables special input file option handling. More... | |
void | addDefaultFileNameOption (IOptionsContainer *options, const char *name) |
Adds an option for setting the default global file name. More... | |
std::string | completeFileName (const std::string &value, const FileNameOptionInfo &option) |
Completes file name option values. More... | |
std::string | completeDefaultFileName (const std::string &prefix, const FileNameOptionInfo &option) |
Completes default values for file name options. More... | |
void gmx::FileNameOptionManager::addDefaultFileNameOption | ( | IOptionsContainer * | options, |
const char * | name | ||
) |
Adds an option for setting the default global file name.
options | Options to add the option to. | |
[in] | name | Name of the option to add. |
If the user sets the option, it affects all file name options that would normally return a default value: the basename for the returned value is taken from the value of the default file name option, instead from an option-specific default (FileNameOption::defaultBaseName()).
std::string gmx::FileNameOptionManager::completeDefaultFileName | ( | const std::string & | prefix, |
const FileNameOptionInfo & | option | ||
) |
Completes default values for file name options.
[in] | prefix | Default prefix for the file name. |
[in] | option | Option for which the value should be completed. |
std::bad_alloc | if out of memory. |
InvalidInputError | if the value is not valid for this option. |
This method is called for each FileNameOption that has a default value (either a standard default value, or if the user provided the option without an explicit value). prefix
is the default value without the default extension for the option. If the return value is non-empty, it is used as the default value for the option instead of prefix
+ default extension.
std::string gmx::FileNameOptionManager::completeFileName | ( | const std::string & | value, |
const FileNameOptionInfo & | option | ||
) |
Completes file name option values.
[in] | value | Value provided by the user. |
[in] | option | Option for which the value should be completed. |
std::bad_alloc | if out of memory. |
InvalidInputError | if the value is not valid for this option. |
This method is called for each value that the user provides to a FileNameOption. The return value (if non-empty) is used as the value of the option instead of the user-provided one.
void gmx::FileNameOptionManager::disableInputOptionChecking | ( | bool | bDisable | ) |
Disables special input file option handling.
If disabled, this removes all file system calls from the file name option parsing. The values returned by FileNameOption for input and input/output files are handled with the same simple rule as for output files: the default extension is added if the file does not end in a recognized extension, and no other checking is done.
This changes the following behavior:
void gmx::FileNameOptionManager::setInputRedirector | ( | const IFileInputRedirector * | redirector | ) |
Redirects file existence checks.
[in] | redirector | File redirector to use for existence checks. |
The manager checks for existence of various files on the file system to complete file extensions. This method can be used to redirect those checks to an alternative implementation.
This is used for unit tests to more easily control the result of the checks and to keep the tests as fast as possible by avoiding real file system access. To keep implementation options open, behavior with redirector == NULL
is undefined and should not be relied on. For tests, there should only be need to call this a single time, right after creating the manager.