Gromacs  2021-beta2-UNCHECKED
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | Public Types | Public Member Functions | Friends
gmx::EnumOption< EnumType > Class Template Reference

#include <gromacs/options/basicoptions.h>

+ Inheritance diagram for gmx::EnumOption< EnumType >:
+ Collaboration diagram for gmx::EnumOption< EnumType >:

Description

template<typename EnumType>
class gmx::EnumOption< EnumType >

Specifies an option that accepts an EnumerationArray of string values and writes the selected index into an enum variable.

Template Parameters
EnumTypeDataType of the variable that receives the values

Examples:

enum class MyEnum { Atom, Res, Mol, Count } : int;
EnumerationArray<MyEnum, const char *> myEnumNames = { "atom", "residue", "molecule" };
MyEnum value = MyEnum::Atom; // default value
options.addOption(EnumOption<MyEnum>("type").enumValue(myEnumNames).store(&value));
*

storeCount() is not currently implemented for this option type, and providing multiple default values through an array passed to store() does not work consistently in all cases. In the current implementation, the values of the enum type should correspond to indices in the array passed to enumValue(), i.e., be consecutive starting from zero. Only values corresponding to valid indices are accepted as parameters to, e.g., defaultValue(). However, other values can be used as the initial value of the variable (value in the above example), and those will be preserved if the option is not set.

Public methods in this class do not throw.

Public Types

typedef EnumOptionInfo InfoType
 OptionInfo subclass corresponding to this option type.
 
typedef OptionTemplate
< EnumType, EnumOption
< EnumType > > 
MyBase
 Short-hand for the base class.
 
- Public Types inherited from gmx::OptionTemplate< EnumType, EnumOption< EnumType > >
typedef EnumType ValueType
 Type that stores a single option value.
 
typedef EnumOption< EnumType > MyClass
 Alias for the derived class type.
 

Public Member Functions

 EnumOption (const char *name)
 Initializes an option with the given name.
 
EnumOptionenumValue (const EnumerationArray< EnumType, const char * > &values)
 Sets the option to only accept one of a fixed set of strings. More...
 
- Public Member Functions inherited from gmx::OptionTemplate< EnumType, EnumOption< EnumType > >
MyClassdescription (const char *descr)
 Sets a description for the option. More...
 
MyClasshidden (bool bHidden=true)
 Hides the option from normal help output.
 
MyClassrequired (bool bRequired=true)
 Requires the option to be specified explicitly. More...
 
MyClassallowMultiple (bool bMulti=true)
 Allows the option to be specified multiple times.
 
MyClassvalueCount (int count)
 Requires exactly count values for the option.
 
MyClassmultiValue (bool bMulti=true)
 Allows any number of values for the option.
 
MyClassdefaultValue (const EnumType &defaultValue)
 Sets a default value for the option. More...
 
MyClassdefaultValueIfSet (const EnumType &defaultValue)
 Sets a default value for the option when it is set. More...
 
MyClassstore (EnumType *store)
 Stores value(s) in memory pointed by store. More...
 
MyClassstoreCount (int *countptr)
 Stores number of values in the value pointed by countptr. More...
 
MyClassstoreVector (std::vector< EnumType > *store)
 Stores option values in the provided vector. More...
 
MyClassstoreIsSet (bool *store)
 Stores whether the option was explicitly set. More...
 

Friends

class EnumOptionStorage
 Needed to initialize EnumOptionStorage from this class without otherwise unnecessary accessors.
 

Additional Inherited Members

- Protected Types inherited from gmx::OptionTemplate< EnumType, EnumOption< EnumType > >
typedef OptionTemplate
< EnumType, EnumOption
< EnumType > > 
MyBase
 Alias for the template class for use in base classes.
 
- Protected Member Functions inherited from gmx::OptionTemplate< EnumType, EnumOption< EnumType > >
const EnumType * defaultValue () const
 Returns a pointer to user-specified default value, or NULL if there is none.
 
const EnumType * defaultValueIfSet () const
 Returns a pointer to user-specified default value, or NULL if there is none.
 
EnumType * store () const
 Returns a pointer to the storage location, or NULL if none specified.
 
std::vector< EnumType > * storeVector () const
 Returns a pointer to the storage vector, or NULL if none specified.
 
 OptionTemplate (const char *name)
 Initializes the name and default values for an option.
 
MyClassme ()
 Returns *this casted into MyClass to reduce typing.
 
- Protected Member Functions inherited from gmx::AbstractOption
 AbstractOption (const char *name)
 Initializes the name and default values for an option.
 
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 inherited from gmx::AbstractOption
int minValueCount_
 Minimum number of values required for the option.
 
int maxValueCount_
 Maximum number of values allowed for the option.
 

Member Function Documentation

template<typename EnumType >
EnumOption& gmx::EnumOption< EnumType >::enumValue ( const EnumerationArray< EnumType, const char * > &  values)
inline

Sets the option to only accept one of a fixed set of strings.

Parameters
[in]valuesArray of strings to accept.

Also accepts prefixes of the strings; if a prefix matches more than one of the possible strings, the shortest one is used (in a tie, the first one is).

The strings are copied once the option is created.


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