Gromacs
2024.3
|
#include <gromacs/options/abstractoption.h>
Gives information and allows modifications to an option after creation.
When an option is added with Options::addOption(), an object of a subclass of OptionInfo is returned. This object can be later used to access information about the option. Non-const methods also allow later changing (some of) the option settings provided at initialization time. The properties accessible/modifiable through this interface are implemented based on need, and may not be implemented for all cases.
This class is also used by OptionsVisitor and OptionsModifyingVisitor as the interface that allows querying/modifying each visited option.
This class isolates the details of the internal option implementation from callers. Although this class is a simple reference to the underlying implementation, it is implemented as non-copyable to allow const/non-const status of a reference to this class to indicate whether modifications are allowed. Otherwise, separate classes would be needed for access and modification, complicating the implementation. In the implementation, there is always a single OptionInfo instance referring to one option. The underlying implementation object always owns this instance, and only references are passed to callers.
Public Member Functions | |
template<class InfoType > | |
bool | isType () const |
Test whether the option is of a particular type. More... | |
template<class InfoType > | |
InfoType * | toType () |
Convert the info object to a particular type if the type is correct. More... | |
template<class InfoType > | |
const InfoType * | toType () const |
Convert the info object to a particular type if the type is correct. More... | |
bool | isSet () const |
Returns true if the option has been set. | |
bool | isHidden () const |
Returns true if the option is a hidden option. | |
bool | isRequired () const |
Returns true if the option is required. | |
int | minValueCount () const |
Returns the minimum number of values that this option accepts. | |
int | maxValueCount () const |
Returns the maximum number of values that this option accepts. | |
const std::string & | name () const |
Returns the name of the option. | |
std::string | type () const |
Returns the type of the option as a string. | |
std::string | formatDescription () const |
Returns the description of the option. | |
std::vector< Any > | defaultValues () const |
Returns the default value(s) of the option. More... | |
std::vector< std::string > | defaultValuesAsStrings () const |
Returns the default value(s) of the option as strings. More... | |
std::vector< Any > | normalizeValues (const std::vector< Any > &values) const |
Converts given values to native representation for this option. More... | |
Protected Member Functions | |
OptionInfo (AbstractOptionStorage *option) | |
Wraps a given option object. More... | |
AbstractOptionStorage & | option () |
Returns the wrapped option storage object. | |
const AbstractOptionStorage & | option () const |
Returns the wrapped option storage object. | |
|
explicitprotected |
Wraps a given option object.
Does not throw.
std::vector< Any > gmx::OptionInfo::defaultValues | ( | ) | const |
Returns the default value(s) of the option.
The returned values should all be of the same type, but returning each as a separate any is currently simpler.
Currently, this can only be called before option values have been assigned.
std::vector< std::string > gmx::OptionInfo::defaultValuesAsStrings | ( | ) | const |
Returns the default value(s) of the option as strings.
If there is no default value, but defaultValueIfSet() is set, that is returned instead.
Currently, this can only be called before option values have been assigned.
|
inline |
Test whether the option is of a particular type.
InfoType | Option type to test for. Should be a class derived from OptionInfo. |
Converts given values to native representation for this option.
For example, strings are parsed to the type that is actually used to store the options.
The return value only depends on the option type, not on the current value of the option, and the current value in the option is not changed.
|
inline |
Convert the info object to a particular type if the type is correct.
InfoType | Option type to convert to. Should be a class derived from OptionInfo. |
this | converted to a pointer to InfoType , or NULL if the conversion is not possible. |
|
inline |
Convert the info object to a particular type if the type is correct.
InfoType | Option type to convert to. Should be a class derived from OptionInfo. |
this | converted to a pointer to InfoType , or NULL if the conversion is not possible. |