Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_StringToIntMap.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Teuchos: Common Tools Package
4 //
5 // Copyright 2004 NTESS and the Teuchos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef TEUCHOS_STRING_TO_INT_MAP_HPP
11 #define TEUCHOS_STRING_TO_INT_MAP_HPP
12 
13 #include "Teuchos_Assert.hpp"
14 #include <map>
15 #include <string>
16 
17 namespace Teuchos {
18 
66 public:
67 
69  class AlreadyExists : public std::logic_error
70  {public: AlreadyExists(const std::string& what_arg) : std::logic_error(what_arg) {}};
71 
73  class DoesNotExist : public std::logic_error
74  {public: DoesNotExist(const std::string& what_arg) : std::logic_error(what_arg) {}};
75 
77  StringToIntMap( const std::string& defaultGroupName, int n, const char* strings[] );
78 
80  int get( const std::string& option, const std::string& groupName = "" ) const;
81 
83  template<class EnumType>
84  EnumType get( const std::string& option, const std::string& groupName = "" ) const;
85 
87  const std::string& defaultGroupName() const;
88 
89 private:
90 
91  typedef std::map< std::string, int > map_t; // all share implementation.
92  std::string defaultGroupName_;
94 
95  std::string validSelections() const;
96 
97  // not defined and not to be called.
99 
100 }; // end class StringToIntMap
101 
105 template<class EnumType>
106 inline
107 EnumType get(
108  StringToIntMap const& theMap
109  ,std::string const& option
110  ,std::string const& groupName = ""
111  )
112 {
113  return static_cast<EnumType>(theMap.get(option,groupName));
114 }
115 
116 // ////////////////////////////////////////////
117 // Inline declarations
118 
119 template<class EnumType>
120 inline
121 EnumType StringToIntMap::get( const std::string& option, const std::string& groupName ) const
122 {
123  return static_cast<EnumType>(get(option,groupName));
124 }
125 
126 inline
127 const std::string& StringToIntMap::defaultGroupName() const
128 {
129  return defaultGroupName_;
130 }
131 
132 } // end namespace Teuchos
133 
134 #endif // TEUCHOS_STRING_TO_INT_MAP_HPP
std::string validSelections() const
int get(const std::string &option, const std::string &groupName="") const
Map a std::string to an enumeration.
const std::string & defaultGroupName() const
std::map< std::string, int > map_t