ConfigData: use std::string in block_param
This commit is contained in:
parent
3cdd01aa1b
commit
2d63c26936
@ -53,11 +53,6 @@ config_param_free(struct config_param *param)
|
|||||||
{
|
{
|
||||||
g_free(param->value);
|
g_free(param->value);
|
||||||
|
|
||||||
for (auto &i : param->block_params) {
|
|
||||||
g_free(i.name);
|
|
||||||
g_free(i.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
delete param;
|
delete param;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,8 +65,8 @@ config_add_block_param(struct config_param * param, const char *name,
|
|||||||
param->block_params.push_back(block_param());
|
param->block_params.push_back(block_param());
|
||||||
struct block_param *bp = ¶m->block_params.back();
|
struct block_param *bp = ¶m->block_params.back();
|
||||||
|
|
||||||
bp->name = g_strdup(name);
|
bp->name = name;
|
||||||
bp->value = g_strdup(value);
|
bp->value = value;
|
||||||
bp->line = line;
|
bp->line = line;
|
||||||
bp->used = false;
|
bp->used = false;
|
||||||
}
|
}
|
||||||
@ -83,7 +78,7 @@ config_get_block_param(const struct config_param * param, const char *name)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
for (auto &i : param->block_params) {
|
for (auto &i : param->block_params) {
|
||||||
if (0 == strcmp(name, i.name)) {
|
if (i.name == name) {
|
||||||
i.used = true;
|
i.used = true;
|
||||||
return &i;
|
return &i;
|
||||||
}
|
}
|
||||||
@ -101,7 +96,7 @@ config_get_block_string(const struct config_param *param, const char *name,
|
|||||||
if (bp == NULL)
|
if (bp == NULL)
|
||||||
return default_value;
|
return default_value;
|
||||||
|
|
||||||
return bp->value;
|
return bp->value.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
@ -122,7 +117,7 @@ config_dup_block_path(const struct config_param *param, const char *name,
|
|||||||
if (bp == NULL)
|
if (bp == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
char *path = parsePath(bp->value, error_r);
|
char *path = parsePath(bp->value.c_str(), error_r);
|
||||||
if (G_UNLIKELY(path == NULL))
|
if (G_UNLIKELY(path == NULL))
|
||||||
g_prefix_error(error_r,
|
g_prefix_error(error_r,
|
||||||
"Invalid path in \"%s\" at line %i: ",
|
"Invalid path in \"%s\" at line %i: ",
|
||||||
@ -142,7 +137,7 @@ config_get_block_unsigned(const struct config_param *param, const char *name,
|
|||||||
if (bp == NULL)
|
if (bp == NULL)
|
||||||
return default_value;
|
return default_value;
|
||||||
|
|
||||||
value = strtol(bp->value, &endptr, 0);
|
value = strtol(bp->value.c_str(), &endptr, 0);
|
||||||
if (*endptr != 0)
|
if (*endptr != 0)
|
||||||
MPD_ERROR("Not a valid number in line %i", bp->line);
|
MPD_ERROR("Not a valid number in line %i", bp->line);
|
||||||
|
|
||||||
@ -162,7 +157,7 @@ config_get_block_bool(const struct config_param *param, const char *name,
|
|||||||
if (bp == NULL)
|
if (bp == NULL)
|
||||||
return default_value;
|
return default_value;
|
||||||
|
|
||||||
success = get_bool(bp->value, &value);
|
success = get_bool(bp->value.c_str(), &value);
|
||||||
if (!success)
|
if (!success)
|
||||||
MPD_ERROR("%s is not a boolean value (yes, true, 1) or "
|
MPD_ERROR("%s is not a boolean value (yes, true, 1) or "
|
||||||
"(no, false, 0) on line %i\n",
|
"(no, false, 0) on line %i\n",
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
#include <string>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#endif
|
#endif
|
||||||
@ -35,8 +36,8 @@
|
|||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
||||||
struct block_param {
|
struct block_param {
|
||||||
char *name;
|
std::string name;
|
||||||
char *value;
|
std::string value;
|
||||||
int line;
|
int line;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -79,7 +79,7 @@ config_param_check(gpointer data, G_GNUC_UNUSED gpointer user_data)
|
|||||||
for (const auto &i : param->block_params) {
|
for (const auto &i : param->block_params) {
|
||||||
if (!i.used)
|
if (!i.used)
|
||||||
g_warning("option '%s' on line %i was not recognized",
|
g_warning("option '%s' on line %i was not recognized",
|
||||||
i.name, i.line);
|
i.name.c_str(), i.line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user