Gromacs
2024.4
|
#include <gromacs/options/abstractoption.h>
Templated base class for constructing concrete option settings classes.
T | Assignable type that stores a single option value. |
U | Type of the derived class. |
This template is used as a base class like this:
All public functions in this class return *this
casted to a reference to U
. They do not throw.
For examples of how to use classes derived from this class, see the class documentation for Options.
Public Types | |
typedef T | ValueType |
Type that stores a single option value. | |
typedef U | MyClass |
Alias for the derived class type. | |
Public Member Functions | |
MyClass & | description (const char *descr) |
Sets a description for the option. More... | |
MyClass & | hidden (bool bHidden=true) |
Hides the option from normal help output. | |
MyClass & | required (bool bRequired=true) |
Requires the option to be specified explicitly. More... | |
MyClass & | allowMultiple (bool bMulti=true) |
Allows the option to be specified multiple times. | |
MyClass & | valueCount (int count) |
Requires exactly count values for the option. | |
MyClass & | multiValue (bool bMulti=true) |
Allows any number of values for the option. | |
MyClass & | defaultValue (const T &defaultValue) |
Sets a default value for the option. More... | |
MyClass & | defaultValueIfSet (const T &defaultValue) |
Sets a default value for the option when it is set. More... | |
MyClass & | store (T *store) |
Stores value(s) in memory pointed by store . More... | |
MyClass & | storeCount (int *countptr) |
Stores number of values in the value pointed by countptr . More... | |
MyClass & | storeVector (std::vector< T > *store) |
Stores option values in the provided vector. More... | |
MyClass & | storeIsSet (bool *store) |
Stores whether the option was explicitly set. More... | |
Protected Types | |
typedef OptionTemplate< T, U > | MyBase |
Alias for the template class for use in base classes. | |
Protected Member Functions | |
OptionTemplate (const char *name) | |
Initializes the name and default values for an option. | |
const T * | defaultValue () const |
Returns a pointer to user-specified default value, or NULL if there is none. | |
const T * | defaultValueIfSet () const |
Returns a pointer to user-specified default value, or NULL if there is none. | |
T * | store () const |
Returns a pointer to the storage location, or NULL if none specified. | |
std::vector< T > * | storeVector () const |
Returns a pointer to the storage vector, or NULL if none specified. | |
MyClass & | me () |
Returns *this casted into MyClass to reduce typing. | |
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 | setFlag (OptionFlag flag, bool bSet) |
Sets or clears a flag for the option. | |
void | clearFlag (OptionFlag flag) |
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 | OptionStorageTemplate< T > |
Needed to initialize storage from this class without otherwise unnecessary accessors. | |
|
protectedpure virtualinherited |
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.
|
inline |
Sets a default value for the option.
[in] | defaultValue | Default value. |
If the option is never set, the default value is copied to the assigned storage. Note that if the option is not set and there is no default value, the storage is not altered, which can also be used to provide a default value. The latter method has to be used if the option can take multiple values.
defaultValue
is copied when the option is created.
|
inline |
Sets a default value for the option when it is set.
[in] | defaultValue | Default value. |
This value is used if the option is set, but no value is provided. If the option is never set, the value set with defaultValue() is used. Can only be used for options that accept a single value.
defaultValue
is copied when the option is created.
|
inline |
Sets a description for the option.
[in] | descr | Description to set. |
String in descr
is copied when the option is created.
|
inline |
Requires the option to be specified explicitly.
Note that if you specify defaultValue() together with required(), the user is not required to explicitly provide the option. In this case, required() only affects possible help output.
|
inlineprotectedinherited |
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.
|
inline |
Stores value(s) in memory pointed by store
.
[in] | store | Storage for option value(s). |
The caller is responsible for allocating enough memory such that the any allowed number of values fits into the array pointed by store
. If there is no maximum allowed number or if the maximum is inconveniently large, storeVector() should be used.
For information on when values are available in the storage, see storeVector().
The pointer provided should remain valid as long as the associated Options object exists.
|
inline |
Stores number of values in the value pointed by countptr
.
[in] | countptr | Storage for the number of values. |
For information on when values are available in the storage, see storeVector().
The pointers provided should remain valid as long as the associated Options object exists.
|
inline |
Stores whether the option was explicitly set.
[in] | store | Variable to store the flag in. |
The value is set to false
on creation of the option, and to true
as soon as a value is assigned to the option. A default value does not set the flag to true
, but assignment that uses defaultValueIfSet() does.
The pointer provided should remain valid as long as the associated Options object exists.
|
inline |
Stores option values in the provided vector.
[in] | store | Vector to store option values in. |
Values are added to the vector after each successful set of values is parsed. Note that for some options, the value may be changed later, and is only guaranteed to be correct after Options::finish() has been called.
The pointer provided should remain valid as long as the associated Options object exists.