template<typename T>
class gmx::OptionStorageTemplate< T >
Templated base class for constructing option value storage classes.
- Template Parameters
-
T | Assignable type that stores a single option value. |
Provides an implementation of the clearSet(), valueCount(), and processSet() methods of AbstractOptionStorage, as well as a basic no-action implementation of processAll(). Two new virtual methods are added: processSetValues() and refreshValues(). The default implementation of processSetValues() does nothing, and refreshValues() is used to update secondary storage after values have been added/changed. This leaves typeString(), formatValue(), and convertValue() to be implemented in derived classes. processSetValues() and processAll() can also be implemented if necessary.
Implements transaction support for adding values within a set: all calls to addValue() add the value to a temporary storage, processSetValues() operates on this temporary storage, and commitValues() then copies these values to the real storage. commitValues() provides a strong exception safety guarantee for the process (and it only throws if it runs out of memory).
|
virtual std::string | typeString () const =0 |
| Returns a short string describing the type of the option.
|
|
virtual int | valueCount () const |
| Returns the number of option values added so far. More...
|
|
virtual std::string | formatValue (int i) const |
| Returns the i'th value formatted as a string. More...
|
|
bool | isSet () const |
| Returns true if the option has been set.
|
|
bool | isBoolean () const |
| Returns true if the option is a boolean option. More...
|
|
bool | isHidden () const |
| Returns true if the option is a hidden option.
|
|
bool | isRequired () const |
| Returns true if the option is required.
|
|
bool | isVector () const |
| Returns true if the option is vector-valued.
|
|
const std::string & | name () const |
| Returns the name of the option.
|
|
const std::string & | description () const |
| Returns the description of the option set by the calling code.
|
|
bool | defaultValueIfSetExists () const |
| Returns true if defaultValueIfSet() value is specified.
|
|
int | minValueCount () const |
| Returns the minimum number of values required in one set.
|
|
int | maxValueCount () const |
| Returns the maximum allowed number of values in one set (-1 = no limit).
|
|
virtual OptionInfo & | optionInfo ()=0 |
| Returns an option info object corresponding to this option.
|
|
virtual std::string | formatExtraDescription () const |
| Formats additional description for the option. More...
|
|
std::string | formatDefaultValueIfSet () const |
| Returns the default value if set for the option as a string. More...
|
|
void | startSource () |
| Starts adding values from a new source for the option. More...
|
|
void | startSet () |
| Starts adding a new set of values for the option. More...
|
|
void | appendValue (const std::string &value) |
| Adds a new value for the option, converting it from a string. More...
|
|
void | finishSet () |
| Performs validation and/or actions once a set of values has been added. More...
|
|
void | finish () |
| Performs validation and/or actions once all values have been added. More...
|
|
Adds a value to a temporary storage.
- Parameters
-
[in] | value | Value to add. A copy is made. |
- Exceptions
-
std::bad_alloc | if out of memory. |
InvalidInputError | if the maximum value count has been reached. |
Derived classes should call this function from the convertValue() implementation to add converted values to the storage. If the maximum value count has been reached, the value is discarded and an exception is thrown.
If adding values outside convertValue() (e.g., to set a custom default value), derived classes should call clearSet() before adding values (unless in the constructor) and commitValues() once all values are added.
Commits values added with addValue().
- Exceptions
-
std::bad_alloc | if out of memory. |
If this function succeeds, values added with addValue() since the previous clearSet() are added to the storage for the option. Only throws in out-of-memory conditions, and provides the strong exception safety guarantee as long as the copy constructor of T
does not throw.
See addValue() for cases where this method should be used in derived classes.
Calls refreshValues() and clearSet() if it is successful.
Adds a new value, converting it from a string.
- Parameters
-
[in] | value | String value to convert. |
- Exceptions
-
InvalidInputError | if value is not valid for this option or if there have been too many values in the set. |
This method may be called multiple times if the underlying option is defined to accept multiple values.
- See Also
- OptionStorageTemplate::convertValue()
Derived classes should call addValue() after they have converted value
to the storage type. It is allowed to call addValue() more than once, or not at all. OptionsAssigner::appendValue() provides the same exception safety guarantee as this method, so it should be considered whether the implementation can be made strongly exception safe.
Implements gmx::AbstractOptionStorage.
Performs validation and/or actions once all values have been added.
- Exceptions
-
This method is always called once.
If the method throws, implementation should take care to leave the option in a consistent, meaningful state. However, currently none of the implementations actually throw in any situation where the option may be left in an inconsistent state.
The implementation in OptionStorageTemplate does nothing.
Implements gmx::AbstractOptionStorage.
Performs validation and/or actions once a set of values has been added.
- Exceptions
-
This method may be called multiple times if the underlying option can be specified multiple times. This method is not currently called if one of the convertValue() calls throwed.
- Todo:
- Improve the call semantics.
- See Also
- OptionStorageTemplate::processSetValues()
OptionStorageTemplate implements transaction support for a set of values in this method (see the class description), and provides a more detailed processSetValues() method that can be overridden in subclasses to process the actual values. Derived classes should override that method instead of this one if set value processing is necessary.
Implements gmx::AbstractOptionStorage.
Updates alternative store locations.
Derived classes should override this method if they implement alternative store locations, and copy/translate values from the values() vector to these alternative storages. They should also call the base class implementation as part of their implementation.
Should be called in derived classes if values are modified directly through the values() method, e.g., in processAll(). Does not need to be called if commitValues() is used.
Does not throw, and derived classes should not change that.