Add some support for default constructed vconfigs.

Before a default constructed vconfig would crash on operator[]. This has
been fixed, some other issues remain, see the @todo.
This commit is contained in:
Mark de Wever 2009-01-28 20:44:42 +00:00
parent abb77e0d4c
commit 20c52979b8
2 changed files with 12 additions and 0 deletions

View file

@ -317,6 +317,9 @@ vconfig vconfig::child(const std::string& key) const
bool vconfig::has_child(const std::string& key) const
{
if(!cfg_) {
return false;
}
if(cfg_->child(key) != NULL) {
return true;
}
@ -333,6 +336,9 @@ bool vconfig::has_child(const std::string& key) const
const t_string vconfig::expand(const std::string& key) const
{
if(!cfg_) {
return t_string();
}
const t_string& val = (*cfg_)[key];
if(repos != NULL && !val.str().empty()) {
std::string interp = utils::interpolate_variables_into_string(val.str(), *repos);

View file

@ -30,6 +30,12 @@ class unit_map;
/**
* A variable-expanding proxy for the config class. This class roughly behaves
* as a constant config object, but automatically expands variables.
*
* @todo A default constructed vconfig doesn't work properly in all cases
* since cfg_ will be deferred without testing in some cases. Fixing it by
* adding a dummy config seems to fail as well (some test cases failed). The
* entire class needs to be review to make it safe for using the default
* constructor.
*/
class vconfig
{