Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
Teuchos_StringToIntMap.hpp
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
17namespace Teuchos {
18
66public:
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
89private:
90
91 typedef std::map< std::string, int > map_t; // all share implementation.
92 std::string defaultGroupName_;
93 map_t map_;
94
95 std::string validSelections() const;
96
97 // not defined and not to be called.
99
100}; // end class StringToIntMap
101
105template<class EnumType>
106inline
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
119template<class EnumType>
120inline
121EnumType StringToIntMap::get( const std::string& option, const std::string& groupName ) const
122{
123 return static_cast<EnumType>(get(option,groupName));
124}
125
126inline
127const std::string& StringToIntMap::defaultGroupName() const
128{
129 return defaultGroupName_;
130}
131
132} // end namespace Teuchos
133
134#endif // TEUCHOS_STRING_TO_INT_MAP_HPP
Smart reference counting pointer class for automatic garbage collection.
T * get() const
Get the raw C++ pointer to the underlying object.
Map a std::string to an enumeration.
EnumType get(StringToIntMap const &theMap, std::string const &option, std::string const &groupName="")
Nonmember get function.
int get(const std::string &option, const std::string &groupName="") const
const std::string & defaultGroupName() const
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...