Gromacs
2016.6
|
#include <gromacs/options/options.h>
Collection of options.
See Extensible Handling of Options (options) for an overview of how the options work. The IOptionsContainer interface documents how to add options.
In order to keep the public interface of this class simple, functionality to assign values to options is provided by a separate OptionsAssigner class. Similarly, functionality for looping over all options (e.g., for writing out help) is provided by OptionsIterator.
Public Member Functions | |
Options (const char *name, const char *title) | |
Initializes the name and title of an option collection. More... | |
const std::string & | name () const |
Returns the short name of the option collection. | |
void | addManager (IOptionManager *manager) |
Adds an option manager. More... | |
void | addSubSection (Options *section) |
Adds an option collection as a subsection of this collection. More... | |
virtual IOptionsContainer & | addGroup () |
Creates a subgroup of options within the current options. More... | |
virtual OptionInfo * | addOption (const AbstractOption &settings) |
Adds a recognized option. More... | |
void | finish () |
Notifies the collection that all option values are assigned. More... | |
Public Member Functions inherited from gmx::IOptionsContainer | |
template<class OptionType > | |
OptionType::InfoType * | addOption (const OptionType &settings) |
Adds a recognized option. More... | |
Friends | |
class | internal::OptionsImpl |
Needed for the implementation to access subsections. | |
class | OptionsAssigner |
Needed to be able to extend the interface of this object. | |
class | OptionsIterator |
Needed to be able to extend the interface of this object. | |
class | OptionsModifyingIterator |
Needed to be able to extend the interface of this object. | |
gmx::Options::Options | ( | const char * | name, |
const char * | title | ||
) |
Initializes the name and title of an option collection.
[in] | name | Single-word name. |
[in] | title | Descriptive title. |
Copies the input strings.
|
virtual |
Creates a subgroup of options within the current options.
To add options to the group, use the returned interface.
Currently, this is only used to influence the order of options: all options in a group appear before options in a group added after it, no matter in which order the options are added to the groups. In the future, the groups could also be used to influence the help output.
Implements gmx::IOptionsContainer.
void gmx::Options::addManager | ( | IOptionManager * | manager | ) |
Adds an option manager.
manager | Manager to add. |
std::bad_alloc | if out of memory. |
Option managers are used by some types of options that require interaction between different option instances (e.g., selection options), or need to support globally set properties (e.g., a global default file prefix). Option objects can retrieve the pointer to their manager when they are created, and the caller can alter the behavior of the options through the manager. See the individual managers for details.
Caller is responsible for memory management of manager
. The Options object (and its contained options) only stores a reference to the object.
This method cannot be called after adding options or subsections.
|
virtual |
Adds a recognized option.
[in] | settings | Option description. |
APIError | if invalid option settings are provided. |
This method provides the internal implementation, but in most cases the templated method is called from user code. See the templated method for more details.
Implements gmx::IOptionsContainer.
void gmx::Options::addSubSection | ( | Options * | section | ) |
Adds an option collection as a subsection of this collection.
[in] | section | Subsection to add. |
The name() field of section
is used as the name of the subsection. If an attempt is made to add two different subsections with the same name, this function asserts.
section
should not have any options added at the point this method is called.
Only a pointer to the provided object is stored. The caller is responsible that the object exists for the lifetime of the collection. It is not possible to add the same Options object as a subsection to several different Options. If an attempt is made, the function asserts.
void gmx::Options::finish | ( | ) |
Notifies the collection that all option values are assigned.
InvalidInputError | if invalid user input is detected. |
This function should be called after no more option values are to be assigned. Values in storage variables are guaranteed to be available only after this call, although in most cases, they are available already during assignment.
If invalid option values, e.g., missing required option, is detected at this point, this function throws. The thrown exception contains information on all errors detected during the call.