diff options
-rw-r--r-- | src/ConfigData.cxx | 41 | ||||
-rw-r--r-- | src/ConfigData.hxx | 20 | ||||
-rw-r--r-- | src/ConfigFile.cxx | 4 | ||||
-rw-r--r-- | src/Main.cxx | 3 | ||||
-rw-r--r-- | test/DumpDatabase.cxx | 3 | ||||
-rw-r--r-- | test/run_encoder.cxx | 2 | ||||
-rw-r--r-- | test/test_vorbis_encoder.cxx | 2 |
7 files changed, 37 insertions, 38 deletions
diff --git a/src/ConfigData.cxx b/src/ConfigData.cxx index 67f93a4ab..7e16c0126 100644 --- a/src/ConfigData.cxx +++ b/src/ConfigData.cxx @@ -39,22 +39,10 @@ config_param::~config_param() g_free(value); } -void -config_add_block_param(struct config_param * param, const char *name, - const char *value, int line) +const block_param * +config_param::GetBlockParam(const char *name) const { - assert(config_get_block_param(param, name) == NULL); - - param->block_params.emplace_back(name, value, line); -} - -const struct block_param * -config_get_block_param(const struct config_param * param, const char *name) -{ - if (param == NULL) - return NULL; - - for (auto &i : param->block_params) { + for (const auto &i : block_params) { if (i.name == name) { i.used = true; return &i; @@ -68,8 +56,10 @@ const char * config_get_block_string(const struct config_param *param, const char *name, const char *default_value) { - const struct block_param *bp = config_get_block_param(param, name); + if (param == nullptr) + return default_value; + const block_param *bp = param->GetBlockParam(name); if (bp == NULL) return default_value; @@ -90,7 +80,10 @@ config_dup_block_path(const struct config_param *param, const char *name, assert(error_r != NULL); assert(*error_r == NULL); - const struct block_param *bp = config_get_block_param(param, name); + if (param == nullptr) + return nullptr; + + const block_param *bp = param->GetBlockParam(name); if (bp == NULL) return NULL; @@ -107,14 +100,15 @@ unsigned config_get_block_unsigned(const struct config_param *param, const char *name, unsigned default_value) { - const struct block_param *bp = config_get_block_param(param, name); - long value; - char *endptr; + if (param == nullptr) + return default_value; + const block_param *bp = param->GetBlockParam(name); if (bp == NULL) return default_value; - value = strtol(bp->value.c_str(), &endptr, 0); + char *endptr; + long value = strtol(bp->value.c_str(), &endptr, 0); if (*endptr != 0) MPD_ERROR("Not a valid number in line %i", bp->line); @@ -128,7 +122,10 @@ bool config_get_block_bool(const struct config_param *param, const char *name, bool default_value) { - const struct block_param *bp = config_get_block_param(param, name); + if (param == nullptr) + return default_value; + + const block_param *bp = param->GetBlockParam(name); bool success, value; if (bp == NULL) diff --git a/src/ConfigData.hxx b/src/ConfigData.hxx index 36e3ea332..93d1092fb 100644 --- a/src/ConfigData.hxx +++ b/src/ConfigData.hxx @@ -68,8 +68,20 @@ struct config_param { config_param(int _line=-1) :value(nullptr), line(_line), used(false) {} + + gcc_nonnull_all config_param(const char *_value, int _line=-1); + ~config_param(); + + gcc_nonnull_all + void AddBlockParam(const char *_name, const char *_value, + int _line=-1) { + block_params.emplace_back(_name, _value, _line); + } + + gcc_nonnull_all gcc_pure + const block_param *GetBlockParam(const char *_name) const; #endif }; @@ -85,14 +97,6 @@ struct ConfigData { extern "C" { #endif -void -config_add_block_param(struct config_param * param, const char *name, - const char *value, int line); - -gcc_pure -const struct block_param * -config_get_block_param(const struct config_param *param, const char *name); - gcc_pure const char * config_get_block_string(const struct config_param *param, const char *name, diff --git a/src/ConfigFile.cxx b/src/ConfigFile.cxx index aea2e58ae..d5b539e7a 100644 --- a/src/ConfigFile.cxx +++ b/src/ConfigFile.cxx @@ -75,7 +75,7 @@ config_read_name_value(struct config_param *param, char *input, unsigned line, return false; } - const struct block_param *bp = config_get_block_param(param, name); + const struct block_param *bp = param->GetBlockParam(name); if (bp != NULL) { g_set_error(error_r, config_quark(), 0, "\"%s\" is duplicate, first defined on line %i", @@ -83,7 +83,7 @@ config_read_name_value(struct config_param *param, char *input, unsigned line, return false; } - config_add_block_param(param, name, value, line); + param->AddBlockParam(name, value, line); return true; } diff --git a/src/Main.cxx b/src/Main.cxx index 613a253b2..7c98c956b 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -190,8 +190,7 @@ glue_db_init_and_load(void) if (param == NULL && path != NULL) { allocated = new config_param("database", path->line); - config_add_block_param(allocated, "path", - path->value, path->line); + allocated->AddBlockParam("path", path->value, path->line); param = allocated; } diff --git a/test/DumpDatabase.cxx b/test/DumpDatabase.cxx index 172d00491..ba0e74e43 100644 --- a/test/DumpDatabase.cxx +++ b/test/DumpDatabase.cxx @@ -108,8 +108,7 @@ main(int argc, char **argv) const struct config_param *path = config_get_param(CONF_DB_FILE); config_param param("database", path->line); if (path != nullptr) - config_add_block_param(¶m, "path", path->value, - path->line); + param.AddBlockParam("path", path->value, path->line); Database *db = plugin->create(¶m, &error); diff --git a/test/run_encoder.cxx b/test/run_encoder.cxx index e2ecab583..9039f2db5 100644 --- a/test/run_encoder.cxx +++ b/test/run_encoder.cxx @@ -74,7 +74,7 @@ int main(int argc, char **argv) } config_param param; - config_add_block_param(¶m, "quality", "5.0", -1); + param.AddBlockParam("quality", "5.0", -1); encoder = encoder_init(plugin, ¶m, &error); if (encoder == NULL) { diff --git a/test/test_vorbis_encoder.cxx b/test/test_vorbis_encoder.cxx index aad48acde..0e502b154 100644 --- a/test/test_vorbis_encoder.cxx +++ b/test/test_vorbis_encoder.cxx @@ -54,7 +54,7 @@ main(G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv) assert(plugin != NULL); config_param param; - config_add_block_param(¶m, "quality", "5.0", -1); + param.AddBlockParam("quality", "5.0", -1); struct encoder *encoder = encoder_init(plugin, ¶m, NULL); assert(encoder != NULL); |