ConfigData: use std::vector for the block_param list
This commit is contained in:
parent
d25195447a
commit
3cdd01aa1b
@ -43,8 +43,6 @@ config_new_param(const char *value, int line)
|
|||||||
|
|
||||||
ret->line = line;
|
ret->line = line;
|
||||||
|
|
||||||
ret->num_block_params = 0;
|
|
||||||
ret->block_params = NULL;
|
|
||||||
ret->used = false;
|
ret->used = false;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -55,14 +53,11 @@ config_param_free(struct config_param *param)
|
|||||||
{
|
{
|
||||||
g_free(param->value);
|
g_free(param->value);
|
||||||
|
|
||||||
for (unsigned i = 0; i < param->num_block_params; i++) {
|
for (auto &i : param->block_params) {
|
||||||
g_free(param->block_params[i].name);
|
g_free(i.name);
|
||||||
g_free(param->block_params[i].value);
|
g_free(i.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (param->num_block_params)
|
|
||||||
g_free(param->block_params);
|
|
||||||
|
|
||||||
delete param;
|
delete param;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,18 +65,10 @@ void
|
|||||||
config_add_block_param(struct config_param * param, const char *name,
|
config_add_block_param(struct config_param * param, const char *name,
|
||||||
const char *value, int line)
|
const char *value, int line)
|
||||||
{
|
{
|
||||||
struct block_param *bp;
|
|
||||||
|
|
||||||
assert(config_get_block_param(param, name) == NULL);
|
assert(config_get_block_param(param, name) == NULL);
|
||||||
|
|
||||||
param->num_block_params++;
|
param->block_params.push_back(block_param());
|
||||||
|
struct block_param *bp = ¶m->block_params.back();
|
||||||
param->block_params = (struct block_param *)
|
|
||||||
g_realloc(param->block_params,
|
|
||||||
param->num_block_params *
|
|
||||||
sizeof(param->block_params[0]));
|
|
||||||
|
|
||||||
bp = ¶m->block_params[param->num_block_params - 1];
|
|
||||||
|
|
||||||
bp->name = g_strdup(name);
|
bp->name = g_strdup(name);
|
||||||
bp->value = g_strdup(value);
|
bp->value = g_strdup(value);
|
||||||
@ -95,11 +82,10 @@ config_get_block_param(const struct config_param * param, const char *name)
|
|||||||
if (param == NULL)
|
if (param == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
for (unsigned i = 0; i < param->num_block_params; i++) {
|
for (auto &i : param->block_params) {
|
||||||
if (0 == strcmp(name, param->block_params[i].name)) {
|
if (0 == strcmp(name, i.name)) {
|
||||||
struct block_param *bp = ¶m->block_params[i];
|
i.used = true;
|
||||||
bp->used = true;
|
return &i;
|
||||||
return bp;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <vector>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
@ -42,7 +43,7 @@ struct block_param {
|
|||||||
* This flag is false when nobody has queried the value of
|
* This flag is false when nobody has queried the value of
|
||||||
* this option yet.
|
* this option yet.
|
||||||
*/
|
*/
|
||||||
bool used;
|
mutable bool used;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -51,14 +52,15 @@ struct config_param {
|
|||||||
char *value;
|
char *value;
|
||||||
unsigned int line;
|
unsigned int line;
|
||||||
|
|
||||||
struct block_param *block_params;
|
#ifdef __cplusplus
|
||||||
unsigned num_block_params;
|
std::vector<block_param> block_params;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This flag is false when nobody has queried the value of
|
* This flag is false when nobody has queried the value of
|
||||||
* this option yet.
|
* this option yet.
|
||||||
*/
|
*/
|
||||||
bool used;
|
bool used;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -76,12 +76,10 @@ config_param_check(gpointer data, G_GNUC_UNUSED gpointer user_data)
|
|||||||
Silently ignore it here. */
|
Silently ignore it here. */
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (unsigned i = 0; i < param->num_block_params; i++) {
|
for (const auto &i : param->block_params) {
|
||||||
struct block_param *bp = ¶m->block_params[i];
|
if (!i.used)
|
||||||
|
|
||||||
if (!bp->used)
|
|
||||||
g_warning("option '%s' on line %i was not recognized",
|
g_warning("option '%s' on line %i was not recognized",
|
||||||
bp->name, bp->line);
|
i.name, i.line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user