aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-01-30 22:01:20 +0100
committerMax Kellermann <max@duempel.org>2013-01-30 22:20:13 +0100
commit3cdd01aa1b889698768f2c53d736873f9f558e3b (patch)
tree971b051fa20120a43e962bbe1c28a41175afc55c
parentd25195447a3a690fa1d508871d4b15ade928b2b0 (diff)
downloadmpd-3cdd01aa1b889698768f2c53d736873f9f558e3b.tar.gz
mpd-3cdd01aa1b889698768f2c53d736873f9f558e3b.tar.xz
mpd-3cdd01aa1b889698768f2c53d736873f9f558e3b.zip
ConfigData: use std::vector for the block_param list
Diffstat (limited to '')
-rw-r--r--src/ConfigData.cxx32
-rw-r--r--src/ConfigData.hxx8
-rw-r--r--src/ConfigGlobal.cxx8
3 files changed, 17 insertions, 31 deletions
diff --git a/src/ConfigData.cxx b/src/ConfigData.cxx
index 7bd04e7c2..1635dfc51 100644
--- a/src/ConfigData.cxx
+++ b/src/ConfigData.cxx
@@ -43,8 +43,6 @@ config_new_param(const char *value, int line)
ret->line = line;
- ret->num_block_params = 0;
- ret->block_params = NULL;
ret->used = false;
return ret;
@@ -55,14 +53,11 @@ config_param_free(struct config_param *param)
{
g_free(param->value);
- for (unsigned i = 0; i < param->num_block_params; i++) {
- g_free(param->block_params[i].name);
- g_free(param->block_params[i].value);
+ for (auto &i : param->block_params) {
+ g_free(i.name);
+ g_free(i.value);
}
- if (param->num_block_params)
- g_free(param->block_params);
-
delete param;
}
@@ -70,18 +65,10 @@ void
config_add_block_param(struct config_param * param, const char *name,
const char *value, int line)
{
- struct block_param *bp;
-
assert(config_get_block_param(param, name) == NULL);
- param->num_block_params++;
-
- param->block_params = (struct block_param *)
- g_realloc(param->block_params,
- param->num_block_params *
- sizeof(param->block_params[0]));
-
- bp = &param->block_params[param->num_block_params - 1];
+ param->block_params.push_back(block_param());
+ struct block_param *bp = &param->block_params.back();
bp->name = g_strdup(name);
bp->value = g_strdup(value);
@@ -95,11 +82,10 @@ config_get_block_param(const struct config_param * param, const char *name)
if (param == NULL)
return NULL;
- for (unsigned i = 0; i < param->num_block_params; i++) {
- if (0 == strcmp(name, param->block_params[i].name)) {
- struct block_param *bp = &param->block_params[i];
- bp->used = true;
- return bp;
+ for (auto &i : param->block_params) {
+ if (0 == strcmp(name, i.name)) {
+ i.used = true;
+ return &i;
}
}
diff --git a/src/ConfigData.hxx b/src/ConfigData.hxx
index 98b74635f..6da0e73b9 100644
--- a/src/ConfigData.hxx
+++ b/src/ConfigData.hxx
@@ -27,6 +27,7 @@
#ifdef __cplusplus
#include <glib.h>
#include <array>
+#include <vector>
#endif
#include <stdbool.h>
@@ -42,7 +43,7 @@ struct block_param {
* This flag is false when nobody has queried the value of
* this option yet.
*/
- bool used;
+ mutable bool used;
};
#endif
@@ -51,14 +52,15 @@ struct config_param {
char *value;
unsigned int line;
- struct block_param *block_params;
- unsigned num_block_params;
+#ifdef __cplusplus
+ std::vector<block_param> block_params;
/**
* This flag is false when nobody has queried the value of
* this option yet.
*/
bool used;
+#endif
};
#ifdef __cplusplus
diff --git a/src/ConfigGlobal.cxx b/src/ConfigGlobal.cxx
index 01b8d09c5..d70a7f5bb 100644
--- a/src/ConfigGlobal.cxx
+++ b/src/ConfigGlobal.cxx
@@ -76,12 +76,10 @@ config_param_check(gpointer data, G_GNUC_UNUSED gpointer user_data)
Silently ignore it here. */
return;
- for (unsigned i = 0; i < param->num_block_params; i++) {
- struct block_param *bp = &param->block_params[i];
-
- if (!bp->used)
+ for (const auto &i : param->block_params) {
+ if (!i.used)
g_warning("option '%s' on line %i was not recognized",
- bp->name, bp->line);
+ i.name, i.line);
}
}