Now config_param::GetBlockValue() can be used to get signed integers from the configuration. --- src/ConfigData.cxx | 21 +++++++++++++++++++-- src/ConfigData.hxx | 6 ++++++ 2 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/src/ConfigData.cxx b/src/ConfigData.cxx index 395d768..0d9ff5f 100644 --- a/src/ConfigData.cxx +++ b/src/ConfigData.cxx @@ -29,14 +29,21 @@ #include <string.h> #include <stdlib.h> -unsigned -block_param::GetUnsignedValue() const +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 +{ + long value2 = GetIntValue(); if (value2 < 0) FormatFatalError("Not a positive number in line %i", line); @@ -120,6 +127,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 { diff --git a/src/ConfigData.hxx b/src/ConfigData.hxx index d85228c..b41b274 100644 --- a/src/ConfigData.hxx +++ b/src/ConfigData.hxx @@ -46,6 +46,9 @@ struct block_param { :name(_name), value(_value), line(_line), used(false) {} gcc_pure + int GetIntValue() const; + + gcc_pure unsigned GetUnsignedValue() const; gcc_pure @@ -115,6 +118,9 @@ struct config_param { AllocatedPath GetBlockPath(const char *name, Error &error) const; gcc_pure + int GetBlockValue(const char *name, int default_value) const; + + gcc_pure unsigned GetBlockValue(const char *name, unsigned default_value) const; gcc_pure -- 1.8.1.5 ------------------------------------------------------------------------------ October Webinars: Code for Performance Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from the latest Intel processors and coprocessors. See abstracts and register > http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk _______________________________________________ Musicpd-dev-team mailing list Musicpd-dev-team@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/musicpd-dev-team