Gromacs  2022.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | Public Member Functions
gmx::StringToEnumValueConverter< EnumType,, stringCompareType, stripStrings > Class Template Reference

#include <gromacs/utility/stringtoenumvalueconverter.h>


template<typename EnumType, const char *, StringCompareType stringCompareType = StringCompareType::Exact, StripStrings stripStrings = StripStrings::No>
class gmx::StringToEnumValueConverter< EnumType,, stringCompareType, stripStrings >

A class to convert a string to an enum value of type EnumType.

It can be configured:

Usage example:

enum class Foo : int { Fizz, Buzz, Count, Default = Fizz }; StringToEnumValueConverter<Foo, enumValueToString> converter; Foo type = converter.valueFrom(theString);

Template Parameters
EnumTypeA class enum for which enumValueToString is defined and maps all values (except EnumType::Count) to a string.
enumValueToStringFunctionFunction to convert EnumValue to string, which is typically enumValueToString, per convention
stringCompareTypeIndicates how the string should be compared with respect to case, hyphens, underscores, etc.
stripStringsIndicates whether strings should have leading and trailing whitespace removed before comparison

Public Member Functions

std::optional< EnumType > valueFrom (const std::string &s) const
 Return an optional enum value identified from the s (which is never EnumType::Count)

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