Commit 3cdd01aa authored by Max Kellermann's avatar Max Kellermann

ConfigData: use std::vector for the block_param list

parent d2519544
......@@ -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;
}
}
......
......@@ -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
......
......@@ -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);
}
}
......
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