From d6553fc6a73ce458aa1fabe78dbb45b5b6a1ac12 Mon Sep 17 00:00:00 2001 From: Sebastian Thorarensen Date: Sat, 19 Oct 2013 15:38:50 +0200 Subject: ConfigData: Add support for signed integers Now config_param::GetBlockValue() can be used to get signed integers from the configuration. --- src/ConfigData.cxx | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/ConfigData.cxx') diff --git a/src/ConfigData.cxx b/src/ConfigData.cxx index 395d768f6..9712eef3e 100644 --- a/src/ConfigData.cxx +++ b/src/ConfigData.cxx @@ -29,6 +29,17 @@ #include #include +int +block_param::GetIntValue() const +{ + char *endptr; + long value2 = strtol(value.c_str(), &endptr, 0); + if (*endptr != 0) + FormatFatalError("Not a valid number in line %i", line); + + return value2; +} + unsigned block_param::GetUnsignedValue() const { @@ -120,6 +131,16 @@ config_param::GetBlockPath(const char *name, Error &error) const return GetBlockPath(name, nullptr, error); } +int +config_param::GetBlockValue(const char *name, int default_value) const +{ + const block_param *bp = GetBlockParam(name); + if (bp == nullptr) + return default_value; + + return bp->GetIntValue(); +} + unsigned config_param::GetBlockValue(const char *name, unsigned default_value) const { -- cgit v1.2.3