Gromacs  2024.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends
gmx::LegacyEnumOption< EnumType > Class Template Reference

#include <gromacs/options/basicoptions.h>

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

Description

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

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

Template Parameters
EnumTypeType of the variable that receives the values (can also be int).

Examples:

enum MyEnum { eAtom, eRes, eMol };
const char * const allowed[] = { "atom", "residue", "molecule" };
MyEnum value = eAtom; // default value
options.addOption(LegacyEnumOption<MyEnum>("type").enumValue(allowed).store(&value));
*

Works exactly as EnumOption.

This is legacy support for pargsToOptions and can be removed when it is removed. No new uses of it should be made.

Public methods in this class do not throw.

Public Types

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

Public Member Functions

 LegacyEnumOption (const char *name)
 Initializes an option with the given name.
 
template<size_t count>
LegacyEnumOptionenumValue (const char *const (&values)[count])
 Sets the option to only accept one of a fixed set of strings. More...
 
LegacyEnumOptionenumValueFromNullTerminatedArray (const char *const *values)
 Sets the option to only accept one of a fixed set of strings. More...
 
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...
 

Protected Member Functions

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.
 
MyClassme ()
 Returns *this casted into MyClass to reduce typing.
 
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 EnumOptionStorage
 Needed to initialize EnumOptionStorage from this class without otherwise unnecessary accessors.
 

Member Function Documentation

MyClass& gmx::OptionTemplate< EnumType , LegacyEnumOption< EnumType > >::defaultValue ( const EnumType &  defaultValue)
inlineinherited

Sets a default value for the option.

Parameters
[in]defaultValueDefault 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.

MyClass& gmx::OptionTemplate< EnumType , LegacyEnumOption< EnumType > >::defaultValueIfSet ( const EnumType &  defaultValue)
inlineinherited

Sets a default value for the option when it is set.

Parameters
[in]defaultValueDefault 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.

MyClass& gmx::OptionTemplate< EnumType , LegacyEnumOption< EnumType > >::description ( const char *  descr)
inlineinherited

Sets a description for the option.

Parameters
[in]descrDescription to set.

String in descr is copied when the option is created.

template<typename EnumType >
template<size_t count>
LegacyEnumOption& gmx::LegacyEnumOption< EnumType >::enumValue ( const char *const (&)  values[count])
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.

template<typename EnumType >
LegacyEnumOption& gmx::LegacyEnumOption< EnumType >::enumValueFromNullTerminatedArray ( const char *const *  values)
inline

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

Parameters
[in]valuesArray of strings to accept, with a NULL pointer following the last string.

Works otherwise as the array version, but accepts a pointer to an array of undetermined length. The end of the array is indicated by a NULL pointer in the array.

See Also
enumValue()
MyClass& gmx::OptionTemplate< EnumType , LegacyEnumOption< EnumType > >::required ( bool  bRequired = true)
inlineinherited

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.

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

MyClass& gmx::OptionTemplate< EnumType , LegacyEnumOption< EnumType > >::store ( EnumType *  store)
inlineinherited

Stores value(s) in memory pointed by store.

Parameters
[in]storeStorage 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.

MyClass& gmx::OptionTemplate< EnumType , LegacyEnumOption< EnumType > >::storeCount ( int *  countptr)
inlineinherited

Stores number of values in the value pointed by countptr.

Parameters
[in]countptrStorage 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.

MyClass& gmx::OptionTemplate< EnumType , LegacyEnumOption< EnumType > >::storeIsSet ( bool *  store)
inlineinherited

Stores whether the option was explicitly set.

Parameters
[in]storeVariable 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.

MyClass& gmx::OptionTemplate< EnumType , LegacyEnumOption< EnumType > >::storeVector ( std::vector< EnumType > *  store)
inlineinherited

Stores option values in the provided vector.

Parameters
[in]storeVector 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.


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