Teuchos_StringToIntMap.hpp

00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //                    Teuchos: Common Tools Package
00005 //                 Copyright (2004) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
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;  // all share implementation.
00109   std::string defaultGroupName_;
00110   map_t map_;
00111 
00112   std::string validSelections() const;
00113 
00114   // not defined and not to be called.
00115   StringToIntMap();
00116 
00117 };  // end class StringToIntMap
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 // Inline declarations
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 }  // end namespace Teuchos
00150 
00151 #endif  // TEUCHOS_STRING_TO_INT_MAP_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Wed Apr 13 09:57:44 2011 for Teuchos - Trilinos Tools Package by  doxygen 1.6.3