[zhoulongyu]: 调用 config_setting_add前, 先调用config_setting_get_member 判断对象是否已存在
This commit is contained in:
parent
c629d6b63f
commit
efa068fea2
|
@ -58,7 +58,11 @@ static const StatusCode ConfigSetIntImpl(VConfig *cfg, const char *name, const i
|
||||||
{
|
{
|
||||||
config_setting_t *root, *setting;
|
config_setting_t *root, *setting;
|
||||||
root = config_root_setting(&(((Config *)cfg)->cfg));
|
root = config_root_setting(&(((Config *)cfg)->cfg));
|
||||||
|
setting = config_setting_get_member(root, name);
|
||||||
|
if(!setting)
|
||||||
|
{
|
||||||
setting = config_setting_add(root, name, CONFIG_TYPE_INT);
|
setting = config_setting_add(root, name, CONFIG_TYPE_INT);
|
||||||
|
}
|
||||||
config_setting_set_int(setting, value);
|
config_setting_set_int(setting, value);
|
||||||
return CreateStatusCode(STATUS_CODE_OK);
|
return CreateStatusCode(STATUS_CODE_OK);
|
||||||
}
|
}
|
||||||
|
@ -77,7 +81,11 @@ static const StatusCode ConfigSetStringImpl(VConfig *cfg, const char *name, cons
|
||||||
{
|
{
|
||||||
config_setting_t *root, *setting;
|
config_setting_t *root, *setting;
|
||||||
root = config_root_setting(&(((Config *)cfg)->cfg));
|
root = config_root_setting(&(((Config *)cfg)->cfg));
|
||||||
|
setting = config_setting_get_member(root, name);
|
||||||
|
if(!setting)
|
||||||
|
{
|
||||||
setting = config_setting_add(root, name, CONFIG_TYPE_STRING);
|
setting = config_setting_add(root, name, CONFIG_TYPE_STRING);
|
||||||
|
}
|
||||||
config_setting_set_string(setting, value);
|
config_setting_set_string(setting, value);
|
||||||
return CreateStatusCode(STATUS_CODE_OK);
|
return CreateStatusCode(STATUS_CODE_OK);
|
||||||
}
|
}
|
||||||
|
@ -92,7 +100,6 @@ static void ConfigImplInit(Config *cfg)
|
||||||
cfg->close = ConfigClose;
|
cfg->close = ConfigClose;
|
||||||
cfg->base.get_int = ConfigGetIntImpl;
|
cfg->base.get_int = ConfigGetIntImpl;
|
||||||
cfg->base.set_int = ConfigSetIntImpl;
|
cfg->base.set_int = ConfigSetIntImpl;
|
||||||
|
|
||||||
cfg->base.get_string = ConfigGetStringImpl;
|
cfg->base.get_string = ConfigGetStringImpl;
|
||||||
cfg->base.set_string = ConfigSetStringImpl;
|
cfg->base.set_string = ConfigSetStringImpl;
|
||||||
cfg->base.save = ConfigSaveFileImpl;
|
cfg->base.save = ConfigSaveFileImpl;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user