Skip to content
Snippets Groups Projects
Commit bad91eb3 authored by Oliver Sander's avatar Oliver Sander
Browse files

new method get() which does not take a default parameter and throws an...

new method get() which does not take a default parameter and throws an exception if the key is not found in the parameter set

[[Imported from SVN: r4980]]
parent 3cd939d2
No related branches found
No related tags found
No related merge requests found
......@@ -229,6 +229,48 @@ bool ConfigParser::get(const string& key, bool defaultValue)
return (atoi(ret.c_str()) !=0 );
}
// This namespace here is needed to make the code compile...
namespace Dune {
template<>
string ConfigParser::get<string>(const string& key)
{
if (hasKey(key))
return (*this)[key];
DUNE_THROW(RangeError, "Key '" << key << "' not found in parameter file!");
}
template<>
int ConfigParser::get<int>(const string& key)
{
if (hasKey(key))
return std::atoi((*this)[key].c_str());
DUNE_THROW(RangeError, "Key '" << key << "' not found in parameter file!");
}
template<>
double ConfigParser::get<double>(const string& key)
{
if (hasKey(key))
return std::atof((*this)[key].c_str());
DUNE_THROW(RangeError, "Key '" << key << "' not found in parameter file!");
}
template<>
bool ConfigParser::get<bool>(const string& key)
{
if (hasKey(key))
return (std::atoi((*this)[key].c_str()) !=0 );
DUNE_THROW(RangeError, "Key '" << key << "' not found in parameter file!");
}
} // end namespace Dune
string ConfigParser::trim(string s)
{
int i = 0;
......
......@@ -183,6 +183,16 @@ namespace Dune {
*/
bool get(const std::string& key, bool defaultValue);
/** \brief Get value
*
* \param T Type of the value
* \param key Key name
* \throws RangeError if key does not exist
* \throws NotImplemented Type is not supported
* \return value as T
*/
template <class T>
T get(const std::string& key);
/** \brief get value keys
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment