Commit d6553fc6 authored by Sebastian Thorarensen's avatar Sebastian Thorarensen Committed by Max Kellermann

ConfigData: Add support for signed integers

Now config_param::GetBlockValue() can be used to get signed integers from the configuration.
parent fc9014f7
...@@ -29,6 +29,17 @@ ...@@ -29,6 +29,17 @@
#include <string.h> #include <string.h>
#include <stdlib.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 unsigned
block_param::GetUnsignedValue() const block_param::GetUnsignedValue() const
{ {
...@@ -120,6 +131,16 @@ config_param::GetBlockPath(const char *name, Error &error) const ...@@ -120,6 +131,16 @@ config_param::GetBlockPath(const char *name, Error &error) const
return GetBlockPath(name, nullptr, error); 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 unsigned
config_param::GetBlockValue(const char *name, unsigned default_value) const config_param::GetBlockValue(const char *name, unsigned default_value) const
{ {
......
...@@ -46,6 +46,9 @@ struct block_param { ...@@ -46,6 +46,9 @@ struct block_param {
:name(_name), value(_value), line(_line), used(false) {} :name(_name), value(_value), line(_line), used(false) {}
gcc_pure gcc_pure
int GetIntValue() const;
gcc_pure
unsigned GetUnsignedValue() const; unsigned GetUnsignedValue() const;
gcc_pure gcc_pure
...@@ -115,6 +118,9 @@ struct config_param { ...@@ -115,6 +118,9 @@ struct config_param {
AllocatedPath GetBlockPath(const char *name, Error &error) const; AllocatedPath GetBlockPath(const char *name, Error &error) const;
gcc_pure gcc_pure
int GetBlockValue(const char *name, int default_value) const;
gcc_pure
unsigned GetBlockValue(const char *name, unsigned default_value) const; unsigned GetBlockValue(const char *name, unsigned default_value) const;
gcc_pure gcc_pure
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment