Gromacs  2016.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | Public Member Functions
gmx::FileNameOptionManager Class Reference

#include <gromacs/options/filenameoptionmanager.h>

+ Inheritance diagram for gmx::FileNameOptionManager:
+ Collaboration diagram for gmx::FileNameOptionManager:


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.

Most of the functionality in this class is specific to command line parsing, so it would be cleaner to replace this with an interface, and have the actual code in the 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.

See Also

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

Member Function Documentation

void gmx::FileNameOptionManager::addDefaultFileNameOption ( IOptionsContainer options,
const char *  name 

Adds an option for setting the default global file name.

optionsOptions to add the option to.
[in]nameName 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]prefixDefault prefix for the file name.
[in]optionOption for which the value should be completed.
Value for the file name option.
std::bad_allocif out of memory.
InvalidInputErrorif 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]valueValue provided by the user.
[in]optionOption for which the value should be completed.
Value for the file name option.
std::bad_allocif out of memory.
InvalidInputErrorif 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:

  • Providing non-existent files does not trigger errors.
  • Extensions for input files are not completed to an existing file.
  • Compressed input files do not work.
void gmx::FileNameOptionManager::setInputRedirector ( const IFileInputRedirector redirector)

Redirects file existence checks.

[in]redirectorFile 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.

The documentation for this class was generated from the following files: