ConfigData: overload GetBlockPath() with default value

This commit is contained in:
Max Kellermann 2013-08-10 11:10:30 +02:00
parent 25e338a098
commit 1c823e9d1f
2 changed files with 22 additions and 6 deletions

View File

@ -96,24 +96,37 @@ config_param::DupBlockString(const char *name, const char *default_value) const
}
Path
config_param::GetBlockPath(const char *name, GError **error_r) const
config_param::GetBlockPath(const char *name, const char *default_value,
GError **error_r) const
{
assert(error_r != nullptr);
assert(*error_r == nullptr);
const block_param *bp = GetBlockParam(name);
if (bp == nullptr)
return Path::Null();
int line2 = line;
const char *s;
Path path = ParsePath(bp->value.c_str(), error_r);
const block_param *bp = GetBlockParam(name);
if (bp != nullptr) {
line2 = bp->line;
s = bp->value.c_str();
} else
s = default_value;
Path path = ParsePath(s, error_r);
if (gcc_unlikely(path.IsNull()))
g_prefix_error(error_r,
"Invalid path in \"%s\" at line %i: ",
name, bp->line);
name, line2);
return path;
}
Path
config_param::GetBlockPath(const char *name, GError **error_r) const
{
return GetBlockPath(name, nullptr, error_r);
}
unsigned
config_param::GetBlockValue(const char *name, unsigned default_value) const
{

View File

@ -112,6 +112,9 @@ struct config_param {
* Same as config_dup_path(), but looks up the setting in the
* specified block.
*/
Path GetBlockPath(const char *name, const char *default_value,
GError **error_r) const;
Path GetBlockPath(const char *name, GError **error_r) const;
gcc_pure