Skip to content
Snippets Groups Projects
Commit 66c35c86 authored by Christian Engwer's avatar Christian Engwer
Browse files

make the paramtertree parser recognize true,yes,false,no as nool values

[[Imported from SVN: r6151]]
parent 0bbf8f2c
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@
#include <sstream>
#include <fstream>
#include <set>
#include <algorithm>
#include <dune/common/exceptions.hh>
#include <dune/common/parametertree.hh>
......@@ -14,6 +15,15 @@
using namespace Dune;
using namespace std;
namespace {
struct ToLower {
int operator()(int c)
{
return std::tolower(c);
}
};
}
ParameterTree::ParameterTree()
{}
......@@ -187,6 +197,13 @@ bool ParameterTree::get(const string& key, bool defaultValue) const
stream << 0;
string ret = get(key, stream.str());
std::transform(ret.begin(), ret.end(), ret.begin(), ToLower());
if (ret == "yes" || ret == "true")
return true;
if (ret == "no" || ret == "false")
return true;
return (atoi(ret.c_str()) !=0 );
}
......@@ -225,8 +242,19 @@ namespace Dune {
bool ParameterTree::get<bool>(const string& key) const
{
if (hasKey(key))
return (std::atoi((*this)[key].c_str()) !=0 );
{
string ret = (*this)[key];
std::transform(ret.begin(), ret.end(), ret.begin(), ToLower());
if (ret == "yes" || ret == "true")
return true;
if (ret == "no" || ret == "false")
return true;
return (std::atoi(ret.c_str()) !=0 );
}
DUNE_THROW(RangeError, "Key '" << key << "' not found in parameter file!");
}
......
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