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

[parametertree] keep track of the current prefix

in order to improve error messages further we introduce a new member
variable prefix_. Sometimes it is important to pass subtrees around.
In this case it is difficult to interpret error messages, as the user
doesn't know in which subtree the problem occured. Now a Parametertree
knows its prefix and can tell it to the user. This way the report
method is simplified and the throws are now more readable.
parent 5335b6c8
No related branches found
No related tags found
No related merge requests found
......@@ -36,8 +36,8 @@ void ParameterTree::report(std::ostream& stream, const std::string& prefix) cons
SubIt send = subs_.end();
for(; sit!=send; ++sit)
{
stream << "[ " << prefix + sit->first << " ]" << std::endl;
(sit->second).report(stream, prefix + sit->first + ".");
stream << "[ " << prefix + prefix_ + sit->first << " ]" << std::endl;
(sit->second).report(stream, prefix);
}
}
......@@ -88,6 +88,7 @@ ParameterTree& ParameterTree::sub(const std::string& key)
{
if (subs_.count(key) == 0)
subKeys_.push_back(key.substr(0,dot));
subs_[key].prefix_ = prefix_ + key + ".";
return subs_[key];
}
}
......@@ -104,7 +105,7 @@ const ParameterTree& ParameterTree::sub(const std::string& key) const
else
{
if (subs_.count(key) == 0)
DUNE_THROW(Dune::RangeError, "SubTree '" << key << "' not found in ParameterTree");
DUNE_THROW(Dune::RangeError, "SubTree '" << key << "' not found in ParameterTree (prefix " + prefix_ + ")");
return subs_.find(key)->second;
}
}
......@@ -143,7 +144,7 @@ const std::string& ParameterTree::operator[] (const std::string& key) const
else
{
if (not (hasKey(key)))
DUNE_THROW(Dune::RangeError, "Key '" << key << "' not found in ParameterTree");
DUNE_THROW(Dune::RangeError, "Key '" << key << "' not found in ParameterTree (prefix " + prefix_ + ")");
return values_.find(key)->second;
}
}
......
......@@ -202,6 +202,8 @@ namespace Dune {
const KeyVector& getSubKeys() const;
protected:
std::string prefix_;
KeyVector valueKeys_;
KeyVector subKeys_;
......
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