diff options
author | Max Kellermann <max@duempel.org> | 2013-01-30 22:00:32 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-01-30 22:20:14 +0100 |
commit | d9ea3082fb608935c72620e272f4b3e74b2c3a44 (patch) | |
tree | 5353513725721f49c0296520b0f55f760dacf8a5 /src | |
parent | 2d63c26936b2b9acfb8f2f81a109e4aff0b26fe7 (diff) | |
download | mpd-d9ea3082fb608935c72620e272f4b3e74b2c3a44.tar.gz mpd-d9ea3082fb608935c72620e272f4b3e74b2c3a44.tar.xz mpd-d9ea3082fb608935c72620e272f4b3e74b2c3a44.zip |
ConfigData: add constructors/destructors
Diffstat (limited to 'src')
-rw-r--r-- | src/ConfigData.cxx | 33 | ||||
-rw-r--r-- | src/ConfigData.hxx | 16 | ||||
-rw-r--r-- | src/ConfigFile.cxx | 10 | ||||
-rw-r--r-- | src/ConfigGlobal.cxx | 2 | ||||
-rw-r--r-- | src/Main.cxx | 5 |
5 files changed, 22 insertions, 44 deletions
diff --git a/src/ConfigData.cxx b/src/ConfigData.cxx index b542dccd3..67f93a4ab 100644 --- a/src/ConfigData.cxx +++ b/src/ConfigData.cxx @@ -31,29 +31,12 @@ extern "C" { #include <string.h> #include <stdlib.h> -struct config_param * -config_new_param(const char *value, int line) -{ - config_param *ret = new config_param(); - - if (!value) - ret->value = NULL; - else - ret->value = g_strdup(value); - - ret->line = line; +config_param::config_param(const char *_value, int _line) + :value(g_strdup(_value)), line(_line) {} - ret->used = false; - - return ret; -} - -void -config_param_free(struct config_param *param) +config_param::~config_param() { - g_free(param->value); - - delete param; + g_free(value); } void @@ -62,13 +45,7 @@ config_add_block_param(struct config_param * param, const char *name, { assert(config_get_block_param(param, name) == NULL); - param->block_params.push_back(block_param()); - struct block_param *bp = ¶m->block_params.back(); - - bp->name = name; - bp->value = value; - bp->line = line; - bp->used = false; + param->block_params.emplace_back(name, value, line); } const struct block_param * diff --git a/src/ConfigData.hxx b/src/ConfigData.hxx index b71c0a9e4..36e3ea332 100644 --- a/src/ConfigData.hxx +++ b/src/ConfigData.hxx @@ -45,6 +45,10 @@ struct block_param { * this option yet. */ mutable bool used; + + gcc_nonnull_all + block_param(const char *_name, const char *_value, int _line=-1) + :name(_name), value(_value), line(_line), used(false) {} }; #endif @@ -61,6 +65,11 @@ struct config_param { * this option yet. */ bool used; + + config_param(int _line=-1) + :value(nullptr), line(_line), used(false) {} + config_param(const char *_value, int _line=-1); + ~config_param(); #endif }; @@ -76,13 +85,6 @@ struct ConfigData { extern "C" { #endif -gcc_malloc -struct config_param * -config_new_param(const char *value, int line); - -void -config_param_free(struct config_param *param); - void config_add_block_param(struct config_param * param, const char *name, const char *value, int line); diff --git a/src/ConfigFile.cxx b/src/ConfigFile.cxx index aebc4dc0a..aea2e58ae 100644 --- a/src/ConfigFile.cxx +++ b/src/ConfigFile.cxx @@ -90,7 +90,7 @@ config_read_name_value(struct config_param *param, char *input, unsigned line, static struct config_param * config_read_block(FILE *fp, int *count, char *string, GError **error_r) { - struct config_param *ret = config_new_param(NULL, *count); + struct config_param *ret = new config_param(*count); GError *error = NULL; while (true) { @@ -98,7 +98,7 @@ config_read_block(FILE *fp, int *count, char *string, GError **error_r) line = fgets(string, MAX_STRING_SIZE, fp); if (line == NULL) { - config_param_free(ret); + delete ret; g_set_error(error_r, config_quark(), 0, "Expected '}' before end-of-file"); return NULL; @@ -115,7 +115,7 @@ config_read_block(FILE *fp, int *count, char *string, GError **error_r) line = strchug_fast(line + 1); if (*line != 0 && *line != CONF_COMMENT) { - config_param_free(ret); + delete ret; g_set_error(error_r, config_quark(), 0, "line %i: Unknown tokens after '}'", *count); @@ -129,7 +129,7 @@ config_read_block(FILE *fp, int *count, char *string, GError **error_r) if (!config_read_name_value(ret, line, *count, &error)) { assert(*line != 0); - config_param_free(ret); + delete ret; g_propagate_prefixed_error(error_r, error, "line %i: ", *count); return NULL; @@ -241,7 +241,7 @@ ReadConfigFile(ConfigData &config_data, FILE *fp, GError **error_r) return false; } - param = config_new_param(value, count); + param = new config_param(value, count); } params = g_slist_append(params, param); diff --git a/src/ConfigGlobal.cxx b/src/ConfigGlobal.cxx index 92e0b5410..0c9af0563 100644 --- a/src/ConfigGlobal.cxx +++ b/src/ConfigGlobal.cxx @@ -44,7 +44,7 @@ config_param_free_callback(gpointer data, G_GNUC_UNUSED gpointer user_data) { struct config_param *param = (struct config_param *)data; - config_param_free(param); + delete param; } void config_global_finish(void) diff --git a/src/Main.cxx b/src/Main.cxx index 63a78d0e4..613a253b2 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -189,7 +189,7 @@ glue_db_init_and_load(void) struct config_param *allocated = NULL; if (param == NULL && path != NULL) { - allocated = config_new_param("database", path->line); + allocated = new config_param("database", path->line); config_add_block_param(allocated, "path", path->value, path->line); param = allocated; @@ -198,8 +198,7 @@ glue_db_init_and_load(void) if (!DatabaseGlobalInit(param, &error)) MPD_ERROR("%s", error->message); - if (allocated != NULL) - config_param_free(allocated); + delete allocated; ret = DatabaseGlobalOpen(&error); if (!ret) |