00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef TEUCHOS_STRING_TO_INT_MAP_HPP
00030 #define TEUCHOS_STRING_TO_INT_MAP_HPP
00031
00032 #include "Teuchos_TestForException.hpp"
00033
00034 namespace Teuchos {
00035
00082 class StringToIntMap {
00083 public:
00084
00086 class AlreadyExists : public std::logic_error
00087 {public: AlreadyExists(const std::string& what_arg) : std::logic_error(what_arg) {}};
00088
00090 class DoesNotExist : public std::logic_error
00091 {public: DoesNotExist(const std::string& what_arg) : std::logic_error(what_arg) {}};
00092
00094 StringToIntMap( const std::string& defaultGroupName, int n, const char* strings[] );
00095
00097 int get( const std::string& option, const std::string& groupName = "" ) const;
00098
00100 template<class EnumType>
00101 EnumType get( const std::string& option, const std::string& groupName = "" ) const;
00102
00104 const std::string& defaultGroupName() const;
00105
00106 private:
00107
00108 typedef std::map< std::string, int > map_t;
00109 std::string defaultGroupName_;
00110 map_t map_;
00111
00112 std::string validSelections() const;
00113
00114
00115 StringToIntMap();
00116
00117 };
00118
00122 template<class EnumType>
00123 inline
00124 EnumType get(
00125 StringToIntMap const& theMap
00126 ,std::string const& option
00127 ,std::string const& groupName = ""
00128 )
00129 {
00130 return static_cast<EnumType>(theMap.get(option,groupName));
00131 }
00132
00133
00134
00135
00136 template<class EnumType>
00137 inline
00138 EnumType StringToIntMap::get( const std::string& option, const std::string& groupName ) const
00139 {
00140 return static_cast<EnumType>(get(option,groupName));
00141 }
00142
00143 inline
00144 const std::string& StringToIntMap::defaultGroupName() const
00145 {
00146 return defaultGroupName_;
00147 }
00148
00149 }
00150
00151 #endif // TEUCHOS_STRING_TO_INT_MAP_HPP