#include <Teuchos_StringToIntMap.hpp>
Public Member Functions | |
| StringToIntMap (const std::string &defaultGroupName, int n, const char *strings[]) | |
| | |
| int | get (const std::string &option, const std::string &groupName="") const |
| | |
| template<class EnumType> | |
| EnumType | get (const std::string &option, const std::string &groupName="") const |
| | |
| const std::string & | defaultGroupName () const |
| | |
The purpose of this class is to simplify mapping a standard string to an integer which can be interpreted as an enumeration.
Here is an example of its use.
const int n_opt = 3;
enum MyOptEnum {
OPT_ONE
,OPT_TWO
,OPT_THREE
}; // NOTE: Must be 0, 1,..., n_opt - 1
const char* MyOptStrings[n_opt] = {
"OPT_ONE
,"OPT_TWO"
,"OPT_THREE"
}; // NOTE: parallels enums in MyOptEnum
StringToIntMap my_enum_map( "opt_map", n_opt, NyOptStrings );
...
switch( my_enum_map.get<MyOptEnum>("OPT_ONE") ) {
case OPT_ONE:
// do stuff
case OPT_TWO:
// do stuff
case OPT_THREE:
// do stuff
default:
// ???
}
The number of strings passed to the constructor must equal the number of options in the enumeration. If there are duplicate strings (capitalization concidered) then the exception AlreadyExists is throw. If a string that was not passed in the constructor if given to operator()( const std::string& str ) then the exception DoesNotExist is thrown.
In the constructor, defaultGroupName is used in error messages in the exceptions thrown to help make since out of the message.
The default constructor is not defined and not to be called.
Definition at line 83 of file Teuchos_StringToIntMap.hpp.
|
||||||||||||||||
|
Definition at line 33 of file Teuchos_StringToIntMap.cpp. |
|
||||||||||||
|
Definition at line 47 of file Teuchos_StringToIntMap.cpp. |
|
||||||||||||||||
|
|
|
|
Definition at line 131 of file Teuchos_StringToIntMap.hpp. |
1.3.9.1