Gromacs  2016.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | Protected Member Functions | Protected Attributes | Friends
gmx::AbstractOption Class Referenceabstract

#include <gromacs/options/abstractoption.h>

+ Inheritance diagram for gmx::AbstractOption:

Description

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 AbstractOptionStoragecreateStorage (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::OptionsImpl
 Needed to be able to call createStorage().
 

Member Function Documentation

virtual AbstractOptionStorage* gmx::AbstractOption::createStorage ( const OptionManagerContainer managers) const
protectedpure virtual

Creates a default storage object for the option.

Parameters
[in]managersManager container (unused if the option does not use a manager).
Returns
The created storage object.
Exceptions
APIErrorif 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.

void gmx::AbstractOption::setVector ( )
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.


The documentation for this class was generated from the following file: