Gromacs
2019.3
|
#include <gromacs/options/abstractoption.h>
Abstract base class for specifying option properties.
Concrete classes should normally not derive directly from this class, but from OptionTemplate instead. Classes derived from this class are mainly designed to implement the "named parameter" idiom. For efficiency and clarity, these classes should only store values provided to them. All error checking and memory management should be postponed to the point when the actual option is created.
Subclasses should override createStorage() to create the correct type of storage object. If they use their own info type derived from OptionInfo, they should also have a public typedef InfoType
that specifies that info type. This is required for Options::addOption() to return the correct info type.
Protected Member Functions | |
AbstractOption (const char *name) | |
Initializes the name and default values for an option. | |
virtual AbstractOptionStorage * | createStorage (const OptionManagerContainer &managers) const =0 |
Creates a default storage object for the option. More... | |
void | setDescription (const char *descr) |
Sets the description for the option. | |
void | setStoreIsSet (bool *store) |
Sets the storage location for whether the option is set. | |
void | setFlag (OptionFlag flag) |
Sets a flag for the option. | |
void | clearFlag (OptionFlag flag) |
Clears a flag for the option. | |
void | setFlag (OptionFlag flag, bool bSet) |
Sets or clears a flag for the option. | |
bool | isVector () const |
Returns true if the option is vector-valued. | |
void | setVector () |
Sets the option to be vector-valued. More... | |
void | setValueCount (int count) |
Sets the required number of values for the option. | |
Protected Attributes | |
int | minValueCount_ |
Minimum number of values required for the option. | |
int | maxValueCount_ |
Maximum number of values allowed for the option. | |
Friends | |
class | AbstractOptionStorage |
Needed to initialize an AbstractOptionStorage object from this class without otherwise unnecessary accessors. | |
class | internal::OptionSectionImpl |
Needed to be able to call createStorage(). | |
|
protectedpure virtual |
Creates a default storage object for the option.
[in] | managers | Manager container (unused if the option does not use a manager). |
APIError | if invalid option settings have been provided. |
This method is called by Options::addOption() when initializing an option from the settings.
Derived classes should implement the method to create an actual storage object and populate it with correct values. They should also throw APIError if they detect problems.
Should only be called by Options::addOption().
The ownership of the return value is passed, but is not using a smart pointer to avoid introducing such a dependency in an installed header. The implementation will always consist of a single new
call and returning that value, and the caller always immediately wraps the pointer in a smart pointer, so there is not exception safety issue.
|
inlineprotected |
Sets the option to be vector-valued.
This method is provided for convenience to make management of value counts easier. In order to implement a vector-valued option, the class derived from AbstractOption should expose a method that calls this method, and the storage object derived from AbstractOptionStorage should check isVector(). If only a single value is provided, the storage object should fill the whole vector with that value.
The length of the vector (the value of maxValueCount_) must be fixed. The default length is 3 elements.