config_setting_t *config_setting_set_string_elem(config_setting_t *vector, int idx, const char *value) { config_setting_t *element = NULL; if((vector->type != CONFIG_TYPE_ARRAY) && (vector->type != CONFIG_TYPE_LIST)) return(NULL); if(idx < 0) { if(! __config_vector_checktype(vector, CONFIG_TYPE_STRING)) return(NULL); element = config_setting_create(vector, NULL, CONFIG_TYPE_STRING); } else element = config_setting_get_elem(vector, idx); if(! element) return(NULL); if(! config_setting_set_string(element, value)) return(NULL); return(element); }
config_setting_t *config_setting_set_int64_elem(config_setting_t *vector, int idx, long long value) { config_setting_t *element = NULL; if((vector->type != CONFIG_TYPE_ARRAY) && (vector->type != CONFIG_TYPE_LIST)) return(NULL); if(idx < 0) { if(! __config_vector_checktype(vector, CONFIG_TYPE_INT64)) return(NULL); element = config_setting_create(vector, NULL, CONFIG_TYPE_INT64); } else { element = config_setting_get_elem(vector, idx); if(! element) return(NULL); } if(! config_setting_set_int64(element, value)) return(NULL); return(element); }
config_setting_t *config_setting_set_float_elem(config_setting_t *vector, int idx, double value) { config_setting_t *element = NULL; if((vector->type != CONFIG_TYPE_ARRAY) && (vector->type != CONFIG_TYPE_LIST)) return(NULL); if(idx < 0) { if(! __config_vector_checktype(vector, CONFIG_TYPE_FLOAT)) return(NULL); element = config_setting_create(vector, NULL, CONFIG_TYPE_FLOAT); } else element = config_setting_get_elem(vector, idx); if(! element) return(NULL); if(! config_setting_set_float(element, value)) return(NULL); return(element); }
config_setting_t *config_setting_add(config_setting_t *parent, const char *name, int type) { if((type < CONFIG_TYPE_NONE) || (type > CONFIG_TYPE_LIST)) return(NULL); if(! parent) return(NULL); if((parent->type == CONFIG_TYPE_ARRAY) || (parent->type == CONFIG_TYPE_LIST)) name = NULL; if(name) { if(! __config_validate_name(name)) return(NULL); } config_setting_t *setting = config_setting_get_member(parent, name); if (setting != NULL) { if ((setting->type != type && type != CONFIG_TYPE_NONE) || (setting->type != CONFIG_TYPE_GROUP && setting->type != CONFIG_TYPE_ARRAY && setting->type != CONFIG_TYPE_LIST)) return(NULL); /* already exists */ else return setting; /* merge with existing config */ } return(config_setting_create(parent, name, type)); }
config_setting_t *config_setting_add(config_setting_t *parent, const char *name, int type) { if((type < CONFIG_TYPE_NONE) || (type > CONFIG_TYPE_LIST)) return(NULL); if(! parent) return(NULL); if((parent->type == CONFIG_TYPE_ARRAY) || (parent->type == CONFIG_TYPE_LIST)) name = NULL; if(name) { if(! __config_validate_name(name)) return(NULL); } #if 0 /* https://github.com/HerculesWS/Hercules/pull/136#discussion_r6363319 * With this code, accidental duplicate keys would cause the file parsing to fail * (would cause several issues during runtime on file reloads), while libconfig's code * has no problems with duplicate members so it was ducked out -- TODO: looking now though * I'd think it could be useful to have it display a warning or error message when finding * duplicate keys instead of silently moving on. [Ind] */ if(config_setting_get_member(parent, name) != NULL) return(NULL); /* already exists */ #endif return(config_setting_create(parent, name, type)); }
LIBCONFIG_API config_setting_t *config_setting_set_bool_elem( config_setting_t *vector, int index, int value) { config_setting_t *element = NULL; if((vector->type != CONFIG_TYPE_ARRAY) && (vector->type != CONFIG_TYPE_LIST)) return(NULL); if(index < 0) { if(! __config_vector_checktype(vector, CONFIG_TYPE_BOOL)) return(NULL); element = config_setting_create(vector, NULL, CONFIG_TYPE_BOOL); } else element = config_setting_get_elem(vector, index); if(! element) return(NULL); if(! config_setting_set_bool(element, value)) return(NULL); return(element); }
LIBCONFIG_API config_setting_t *config_setting_add(config_setting_t *parent, const char *name, int type) { if((type < CONFIG_TYPE_NONE) || (type > CONFIG_TYPE_LIST)) return(NULL); if(! parent) return(NULL); if((parent->type == CONFIG_TYPE_ARRAY) || (parent->type == CONFIG_TYPE_LIST)) name = NULL; if(name) if(config_setting_get_member(parent, name) != NULL) return(NULL); // already exists return(config_setting_create(parent, name, type)); }
config_setting_t *config_setting_add(config_setting_t *parent, const char *name, int type) { if((type < CONFIG_TYPE_NONE) || (type > CONFIG_TYPE_LIST)) return(NULL); if(! parent) return(NULL); if((parent->type == CONFIG_TYPE_ARRAY) || (parent->type == CONFIG_TYPE_LIST)) name = NULL; if(name) { if(! __config_validate_name(name)) return(NULL); } if(((name && *name != '$') || (!name)) && config_setting_get_member(parent, name) != NULL) return(NULL); /* already exists */ return(config_setting_create(parent, name, type)); }