ConfigData: Add support for signed integers

Now config_param::GetBlockValue() can be used to get signed integers
from the configuration.
This commit is contained in:
Sebastian Thorarensen
2013-10-19 15:38:50 +02:00
committed by Max Kellermann
parent fc9014f7ec
commit d6553fc6a7
2 changed files with 27 additions and 0 deletions

View File

@@ -29,6 +29,17 @@
#include <string.h>
#include <stdlib.h>
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
{