working on sprite config, kinda scared I'm f***ing everything up :)
This commit is contained in:
parent
da2be7780b
commit
8845cf78e0
7 changed files with 149 additions and 55 deletions
|
|
@ -21,7 +21,7 @@ void ARC_ConfigType_SpritesheetCopyFn(void **type, ARC_ParserTagToken *parsedDat
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
*/
|
*/
|
||||||
void ARC_ConfigType_SpritesheetDestroyFn(void *type);
|
void ARC_ConfigType_SpritesheetDestroyFn(ARC_Config *config, void *type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
|
|
@ -31,7 +31,7 @@ void ARC_ConfigType_SpriteCopyFn(void **type, ARC_ParserTagToken *parsedData, AR
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
*/
|
*/
|
||||||
void ARC_ConfigType_SpriteDestroyFn(void *type);
|
void ARC_ConfigType_SpriteDestroyFn(ARC_Config *config, void *type);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ void ARC_ConfigType_PointCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
*/
|
*/
|
||||||
void ARC_ConfigType_PointDestroyFn(void *type);
|
void ARC_ConfigType_PointDestroyFn(ARC_Config *config, void *type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
|
|
@ -34,7 +34,7 @@ void ARC_ConfigType_RectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
*/
|
*/
|
||||||
void ARC_ConfigType_RectDestroyFn(void *type);
|
void ARC_ConfigType_RectDestroyFn(ARC_Config *config, void *type);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ typedef void (* ARC_ConfigType_CopyFn)(void **type, ARC_ParserTagToken *parsedDa
|
||||||
/**
|
/**
|
||||||
* @brief a function callback to destroy a type
|
* @brief a function callback to destroy a type
|
||||||
*/
|
*/
|
||||||
typedef void (* ARC_ConfigType_DestroyFn)(void *type);
|
typedef void (* ARC_ConfigType_DestroyFn)(ARC_Config *config, void *type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief the functions for used for loading and unloading a type, the name will be the key of a hashtable
|
* @brief the functions for used for loading and unloading a type, the name will be the key of a hashtable
|
||||||
|
|
@ -105,8 +105,9 @@ void ARC_Config_AddWithCStr(ARC_Config *config, const char *type, const char *na
|
||||||
*
|
*
|
||||||
* @param[in] config ARC_Config to remove value from
|
* @param[in] config ARC_Config to remove value from
|
||||||
* @param[in] name name of a variable to remove to specified group
|
* @param[in] name name of a variable to remove to specified group
|
||||||
|
* @param[in] isArray a boolean to specify if the variable is an array
|
||||||
*/
|
*/
|
||||||
void ARC_Config_Remove(ARC_Config *config, ARC_String *name);
|
void ARC_Config_Remove(ARC_Config *config, ARC_String *name, ARC_Bool isArray);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief remove a value with a given keyname
|
* @brief remove a value with a given keyname
|
||||||
|
|
@ -116,8 +117,9 @@ void ARC_Config_Remove(ARC_Config *config, ARC_String *name);
|
||||||
*
|
*
|
||||||
* @param[in] config ARC_Config to remove value from
|
* @param[in] config ARC_Config to remove value from
|
||||||
* @param[in] name name of a variable to remove to specified group
|
* @param[in] name name of a variable to remove to specified group
|
||||||
|
* @param[in] isArray a boolean to specify if the variable is an array
|
||||||
*/
|
*/
|
||||||
void ARC_Config_RemoveWithCStr(ARC_Config *config, const char *name);
|
void ARC_Config_RemoveWithCStr(ARC_Config *config, const char *name, ARC_Bool isArray);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief sets current group in config
|
* @brief sets current group in config
|
||||||
|
|
@ -281,7 +283,7 @@ void ARC_ConfigType_BoolCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
*/
|
*/
|
||||||
void ARC_ConfigType_BoolDestroyFn(void *type);
|
void ARC_ConfigType_BoolDestroyFn(ARC_Config *config, void *type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
|
|
@ -291,7 +293,7 @@ void ARC_ConfigType_CharCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
*/
|
*/
|
||||||
void ARC_ConfigType_CharDestroyFn(void *type);
|
void ARC_ConfigType_CharDestroyFn(ARC_Config *config, void *type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
|
|
@ -301,7 +303,7 @@ void ARC_ConfigType_Int8CopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
*/
|
*/
|
||||||
void ARC_ConfigType_Int8DestroyFn(void *type);
|
void ARC_ConfigType_Int8DestroyFn(ARC_Config *config, void *type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
|
|
@ -311,7 +313,7 @@ void ARC_ConfigType_Uint8CopyFn(void **type, ARC_ParserTagToken *parsedData, ARC
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
*/
|
*/
|
||||||
void ARC_ConfigType_Uint8DestroyFn(void *type);
|
void ARC_ConfigType_Uint8DestroyFn(ARC_Config *config, void *type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
|
|
@ -321,7 +323,7 @@ void ARC_ConfigType_Int16CopyFn(void **type, ARC_ParserTagToken *parsedData, ARC
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
*/
|
*/
|
||||||
void ARC_ConfigType_Int16DestroyFn(void *type);
|
void ARC_ConfigType_Int16DestroyFn(ARC_Config *config, void *type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
|
|
@ -331,7 +333,7 @@ void ARC_ConfigType_Uint16CopyFn(void **type, ARC_ParserTagToken *parsedData, AR
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
*/
|
*/
|
||||||
void ARC_ConfigType_Uint16DestroyFn(void *type);
|
void ARC_ConfigType_Uint16DestroyFn(ARC_Config *config, void *type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
|
|
@ -341,7 +343,7 @@ void ARC_ConfigType_Int32CopyFn(void **type, ARC_ParserTagToken *parsedData, ARC
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
*/
|
*/
|
||||||
void ARC_ConfigType_Int32DestroyFn(void *type);
|
void ARC_ConfigType_Int32DestroyFn(ARC_Config *config, void *type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
|
|
@ -351,7 +353,7 @@ void ARC_ConfigType_Uint32CopyFn(void **type, ARC_ParserTagToken *parsedData, AR
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
*/
|
*/
|
||||||
void ARC_ConfigType_Uint32DestroyFn(void *type);
|
void ARC_ConfigType_Uint32DestroyFn(ARC_Config *config, void *type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
|
|
@ -361,7 +363,7 @@ void ARC_ConfigType_Int64CopyFn(void **type, ARC_ParserTagToken *parsedData, ARC
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
*/
|
*/
|
||||||
void ARC_ConfigType_Int64DestroyFn(void *type);
|
void ARC_ConfigType_Int64DestroyFn(ARC_Config *config, void *type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
|
|
@ -371,7 +373,7 @@ void ARC_ConfigType_Uint64CopyFn(void **type, ARC_ParserTagToken *parsedData, AR
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
*/
|
*/
|
||||||
void ARC_ConfigType_Uint64DestroyFn(void *type);
|
void ARC_ConfigType_Uint64DestroyFn(ARC_Config *config, void *type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
|
|
@ -381,7 +383,7 @@ void ARC_ConfigType_FloatCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
*/
|
*/
|
||||||
void ARC_ConfigType_FloatDestroyFn(void *type);
|
void ARC_ConfigType_FloatDestroyFn(ARC_Config *config, void *type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
|
|
@ -391,7 +393,7 @@ void ARC_ConfigType_DoubleCopyFn(void **type, ARC_ParserTagToken *parsedData, AR
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
*/
|
*/
|
||||||
void ARC_ConfigType_DoubleDestroyFn(void *type);
|
void ARC_ConfigType_DoubleDestroyFn(ARC_Config *config, void *type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
|
|
@ -401,7 +403,7 @@ void ARC_ConfigType_StringCopyFn(void **type, ARC_ParserTagToken *parsedData, AR
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
*/
|
*/
|
||||||
void ARC_ConfigType_StringDestroyFn(void *type);
|
void ARC_ConfigType_StringDestroyFn(ARC_Config *config, void *type);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -55,14 +55,92 @@ void ARC_ConfigType_SpritesheetCopyFn(void **type, ARC_ParserTagToken *parsedDat
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ARC_ConfigType_SpritesheetDestroyFn(void *type){
|
void ARC_ConfigType_SpritesheetDestroyFn(ARC_Config *config, void *type){
|
||||||
ARC_Spritesheet_Destroy((ARC_Spritesheet *)type);
|
ARC_Spritesheet_Destroy((ARC_Spritesheet *)type);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ARC_ConfigType_SpriteCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata){
|
void ARC_ConfigType_SpriteCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata){
|
||||||
|
//go into the <nestedValue> tag
|
||||||
|
ARC_ParserTagToken *childTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(parsedData->tagTokens, 0);
|
||||||
|
if(childTagToken->id != ARC_CONFIG_NESTED_VALUE){
|
||||||
|
arc_errno = ARC_ERRNO_DATA;
|
||||||
|
ARC_DEBUG_LOG_ERROR("ARC_ConfigType_SpriteCopyFn(type, parsedData, config, userdata), parsed data was not a <nestedValue>");
|
||||||
|
*type = NULL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//<nestedValue> -> OPEN_CURLY_BRACE <whitespace> <valueArgs> <whitespace> CLOSE_CURLY_BRACE
|
||||||
|
ARC_ParserTagToken *valueArgsTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(childTagToken->tagTokens, 2);
|
||||||
|
|
||||||
|
ARC_Sprite *sprite;
|
||||||
|
ARC_Sprite_Create(&sprite, NULL, (ARC_Array){ 0, NULL });
|
||||||
|
|
||||||
|
//really large number in case a system has 64 digit pointer addresses
|
||||||
|
char pointerCString[64];
|
||||||
|
sprintf(pointerCString, "%p", sprite);
|
||||||
|
|
||||||
|
//<valueArgs> -> <value> <whitespace> COMMA <whitespace> <valueArgs> | <value>
|
||||||
|
if(ARC_Vector_GetSize(valueArgsTagToken->tagTokens) == 1){
|
||||||
|
//TODO: error here
|
||||||
|
}
|
||||||
|
ARC_ParserTagToken *valueTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(valueArgsTagToken->tagTokens, 0);
|
||||||
|
|
||||||
|
//check if spritesheet exist
|
||||||
|
ARC_String *valueString;
|
||||||
|
ARC_String_Create(&valueString, NULL, 0);
|
||||||
|
ARC_ParserData_HelperRecurseStringAdd(&valueString, valueTagToken);
|
||||||
|
|
||||||
|
ARC_Spritesheet *spritesheet = (ARC_Spritesheet *)ARC_Config_Get(config, valueString);
|
||||||
|
if(spritesheet == NULL){
|
||||||
|
//create a name based on the type and the sprite pointer to have a unique name for cleanup on remove
|
||||||
|
ARC_String *spritesheetName;
|
||||||
|
ARC_String_CreateWithStrlen(&spritesheetName, pointerCString);
|
||||||
|
ARC_String_AppendCStringWithStrlen(&spritesheetName, "ARC_Spritesheet");
|
||||||
|
|
||||||
|
//copy the spritesheet
|
||||||
|
ARC_Spritesheet *sheet;
|
||||||
|
ARC_ConfigType_SpritesheetCopyFn((void *)&sheet, valueTagToken, config, userdata);
|
||||||
|
|
||||||
|
//add the new spritesheet type to the config
|
||||||
|
ARC_Config_AddWithCStr(config, "ARC_Spritesheet", spritesheetName->data, (void *)sheet);
|
||||||
|
|
||||||
|
//cleanup
|
||||||
|
ARC_String_Destroy(spritesheetName);
|
||||||
|
}
|
||||||
|
|
||||||
|
ARC_String_Destroy(valueString);
|
||||||
|
valueString = NULL;
|
||||||
|
|
||||||
|
//check if bounds exist
|
||||||
|
ARC_String_Create(&valueString, NULL, 0);
|
||||||
|
ARC_ParserData_HelperRecurseStringAdd(&valueString, valueTagToken);
|
||||||
|
|
||||||
|
void *bounds = ARC_Config_Get(config, valueString);
|
||||||
|
if(bounds == NULL){
|
||||||
|
//ARC_Config_AddWithCStr(config, "ARC_FRect[]", const char *name, void *value)
|
||||||
|
}
|
||||||
|
|
||||||
|
ARC_String_Destroy(valueString);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ARC_ConfigType_SpriteDestroyFn(void *type){
|
void ARC_ConfigType_SpriteDestroyFn(ARC_Config *config, void *type){
|
||||||
|
ARC_Sprite *sprite = (ARC_Sprite *)type;
|
||||||
|
|
||||||
|
//really large number in case a system has 64 digit pointer addresses
|
||||||
|
char pointerCString[64];
|
||||||
|
sprintf(pointerCString, "%p", sprite);
|
||||||
|
|
||||||
|
//create a name based on the type and the sprite pointer to have a unique name for cleanup on remove
|
||||||
|
ARC_String *spritesheetName;
|
||||||
|
ARC_String_CreateWithStrlen(&spritesheetName, pointerCString);
|
||||||
|
ARC_String_AppendCStringWithStrlen(&spritesheetName, "ARC_Spritesheet");
|
||||||
|
|
||||||
|
//remove the spritesheet from the config (it won't error if it doesn't exist)
|
||||||
|
//ARC_Config_RemoveWithCStr(config, spritesheetName->data, ARC_False);
|
||||||
|
|
||||||
|
//cleanup
|
||||||
|
ARC_String_Destroy(spritesheetName);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,9 @@ void ARC_Sprite_SetOrigin(ARC_Sprite *sprite, ARC_FPoint origin){
|
||||||
|
|
||||||
void ARC_Sprite_SetOpacity(ARC_Sprite *sprite, float opacity){
|
void ARC_Sprite_SetOpacity(ARC_Sprite *sprite, float opacity){
|
||||||
sprite->opacity = opacity;
|
sprite->opacity = opacity;
|
||||||
|
if(sprite->spritesheet != NULL){
|
||||||
SDL_SetTextureAlphaMod((SDL_Texture *)sprite->spritesheet->texture, sprite->opacity);
|
SDL_SetTextureAlphaMod((SDL_Texture *)sprite->spritesheet->texture, sprite->opacity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t ARC_Sprite_GetFrameIndex(ARC_Sprite *sprite){
|
uint32_t ARC_Sprite_GetFrameIndex(ARC_Sprite *sprite){
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ void ARC_ConfigType_PointCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC
|
||||||
*type = (void *)point;
|
*type = (void *)point;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ARC_ConfigType_PointDestroyFn(void *type){
|
void ARC_ConfigType_PointDestroyFn(ARC_Config *config, void *type){
|
||||||
free((ARC_Point *)type);
|
free((ARC_Point *)type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -187,6 +187,6 @@ void ARC_ConfigType_RectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_
|
||||||
*type = (void *)point;
|
*type = (void *)point;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ARC_ConfigType_RectDestroyFn(void *type){
|
void ARC_ConfigType_RectDestroyFn(ARC_Config *config, void *type){
|
||||||
free((ARC_Rect *)type);
|
free((ARC_Rect *)type);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ struct ARC_Config {
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct ARC_ConfigTypeData {
|
typedef struct ARC_ConfigTypeData {
|
||||||
|
ARC_Config *config;
|
||||||
void *data;
|
void *data;
|
||||||
ARC_ConfigType_DestroyFn destroyFn;
|
ARC_ConfigType_DestroyFn destroyFn;
|
||||||
} ARC_ConfigTypeData;
|
} ARC_ConfigTypeData;
|
||||||
|
|
@ -311,12 +312,12 @@ void ARC_Config_GroupDataHashtableDestroyKeyValueFn(void *key, void *value){
|
||||||
free((char *)key);
|
free((char *)key);
|
||||||
|
|
||||||
ARC_ConfigTypeData *typeData = (ARC_ConfigTypeData *)value;
|
ARC_ConfigTypeData *typeData = (ARC_ConfigTypeData *)value;
|
||||||
typeData->destroyFn(typeData->data);
|
typeData->destroyFn(typeData->config, typeData->data);
|
||||||
free(typeData);
|
free(typeData);
|
||||||
}
|
}
|
||||||
|
|
||||||
//private empty function to avoid removing references or data freed from an array
|
//private empty function to avoid removing references or data freed from an array
|
||||||
void ARC_ConfigType_EmptyDestroyFn(void *type){
|
void ARC_ConfigType_EmptyDestroyFn(ARC_Config *config, void *type){
|
||||||
}
|
}
|
||||||
|
|
||||||
//<variableLine> -> <whitespace> <type> <whitespace> <variable> <whitespace> <array> <whitespace> EQUAL <whitespace> <value> <whitespace> SEMICOLON
|
//<variableLine> -> <whitespace> <type> <whitespace> <variable> <whitespace> <array> <whitespace> EQUAL <whitespace> <value> <whitespace> SEMICOLON
|
||||||
|
|
@ -359,7 +360,7 @@ void ARC_ConfigData_RunVariableLineTag(ARC_ParserTagToken *tagToken, ARC_Config
|
||||||
ARC_Array *array = (ARC_Array *)removingType->data;
|
ARC_Array *array = (ARC_Array *)removingType->data;
|
||||||
|
|
||||||
for(uint32_t index = 0; index < array->size; index++){
|
for(uint32_t index = 0; index < array->size; index++){
|
||||||
removingType->destroyFn(array->data + index);
|
removingType->destroyFn(config, array->data + index);
|
||||||
}
|
}
|
||||||
|
|
||||||
removingType->destroyFn = ARC_ConfigType_EmptyDestroyFn;
|
removingType->destroyFn = ARC_ConfigType_EmptyDestroyFn;
|
||||||
|
|
@ -400,6 +401,7 @@ void ARC_ConfigData_RunVariableLineTag(ARC_ParserTagToken *tagToken, ARC_Config
|
||||||
|
|
||||||
//create where to store either the reference or type data
|
//create where to store either the reference or type data
|
||||||
typeData = (ARC_ConfigTypeData *)malloc(sizeof(ARC_ConfigTypeData));
|
typeData = (ARC_ConfigTypeData *)malloc(sizeof(ARC_ConfigTypeData));
|
||||||
|
typeData->config = config;
|
||||||
if(value != NULL){
|
if(value != NULL){
|
||||||
//point to the already stored data
|
//point to the already stored data
|
||||||
typeData->data = value;
|
typeData->data = value;
|
||||||
|
|
@ -771,7 +773,7 @@ void ARC_Config_RegisterTypeWithCStr(ARC_Config *config, const char *typeNameCSt
|
||||||
void ARC_Config_Add(ARC_Config *config, ARC_String *type, ARC_String *name, void *value){
|
void ARC_Config_Add(ARC_Config *config, ARC_String *type, ARC_String *name, void *value){
|
||||||
//check if type exists in the types hashtable
|
//check if type exists in the types hashtable
|
||||||
ARC_ConfigType *typeValue = (ARC_ConfigType *)ARC_Hashtable_Get(config->types, name->data);
|
ARC_ConfigType *typeValue = (ARC_ConfigType *)ARC_Hashtable_Get(config->types, name->data);
|
||||||
if(type == NULL){
|
if(typeValue == NULL){
|
||||||
//throw an error and return
|
//throw an error and return
|
||||||
arc_errno = ARC_ERRNO_DATA;
|
arc_errno = ARC_ERRNO_DATA;
|
||||||
ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("ARC_Config_Add(config, type, name, value), type \"%s\" was not registered to config", type->data);
|
ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("ARC_Config_Add(config, type, name, value), type \"%s\" was not registered to config", type->data);
|
||||||
|
|
@ -864,16 +866,29 @@ void ARC_Config_AddWithCStr(ARC_Config *config, const char *type, const char *na
|
||||||
ARC_String_Destroy(typeString);
|
ARC_String_Destroy(typeString);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ARC_Config_Remove(ARC_Config *config, ARC_String *name){
|
void ARC_Config_Remove(ARC_Config *config, ARC_String *name, ARC_Bool isArray){
|
||||||
//check if the group separator exists
|
//check if the group separator exists
|
||||||
uint64_t startSeparatorIndex = ARC_String_FindCStringWithStrlen(name, ARC_CONFIG_GROUP_SEPARATOR);
|
uint64_t startSeparatorIndex = ARC_String_FindCStringWithStrlen(name, ARC_CONFIG_GROUP_SEPARATOR);
|
||||||
if(startSeparatorIndex == ~(uint64_t)0){
|
if(startSeparatorIndex == ~(uint64_t)0){
|
||||||
//remove the value from the hashtable if it exists
|
//remove the value from the hashtable if it exists
|
||||||
ARC_ConfigTypeData *typeData = (ARC_ConfigTypeData *)ARC_Hashtable_Get(config->currentGroup, (void *)name->data);
|
ARC_ConfigTypeData *typeData = (ARC_ConfigTypeData *)ARC_Hashtable_Get(config->currentGroup, (void *)name->data);
|
||||||
if(typeData != NULL){
|
if(typeData == NULL){
|
||||||
ARC_Hashtable_Remove(config->currentGroup, (void *)name->data);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//clean up the values in the array
|
||||||
|
if(isArray == ARC_True){
|
||||||
|
ARC_Array *array = (ARC_Array *)typeData->data;
|
||||||
|
|
||||||
|
for(uint32_t index = 0; index < array->size; index++){
|
||||||
|
typeData->destroyFn(config, array->data + index);
|
||||||
|
}
|
||||||
|
|
||||||
|
typeData->destroyFn = ARC_ConfigType_EmptyDestroyFn;
|
||||||
|
}
|
||||||
|
|
||||||
|
//remove the value
|
||||||
|
ARC_Hashtable_Remove(config->currentGroup, (void *)name->data);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -906,13 +921,13 @@ void ARC_Config_Remove(ARC_Config *config, ARC_String *name){
|
||||||
ARC_String_Destroy(nameString);
|
ARC_String_Destroy(nameString);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ARC_Config_RemoveWithCStr(ARC_Config *config, const char *name){
|
void ARC_Config_RemoveWithCStr(ARC_Config *config, const char *name, ARC_Bool isArray){
|
||||||
//create and copy strings
|
//create and copy strings
|
||||||
ARC_String *nameString;
|
ARC_String *nameString;
|
||||||
ARC_String_CreateWithStrlen(&nameString, (char *)name);
|
ARC_String_CreateWithStrlen(&nameString, (char *)name);
|
||||||
|
|
||||||
//add as an ARC_String
|
//add as an ARC_String
|
||||||
ARC_Config_Remove(config, nameString);
|
ARC_Config_Remove(config, nameString, isArray);
|
||||||
|
|
||||||
//cleanup
|
//cleanup
|
||||||
ARC_String_Destroy(nameString);
|
ARC_String_Destroy(nameString);
|
||||||
|
|
@ -941,9 +956,6 @@ void *ARC_Config_Get(ARC_Config *config, ARC_String *name){
|
||||||
//check if the group separator exists
|
//check if the group separator exists
|
||||||
uint64_t startSeparatorIndex = ARC_String_FindCStringWithStrlen(name, ARC_CONFIG_GROUP_SEPARATOR);
|
uint64_t startSeparatorIndex = ARC_String_FindCStringWithStrlen(name, ARC_CONFIG_GROUP_SEPARATOR);
|
||||||
if(startSeparatorIndex == ~(uint64_t)0){
|
if(startSeparatorIndex == ~(uint64_t)0){
|
||||||
//use empty group
|
|
||||||
config->currentGroup = ARC_Hashtable_Get(config->groups, (void *)ARC_CONFIG_DEFAULT_GROUP);
|
|
||||||
|
|
||||||
//get the typeData and pass back the data without the cleanup function
|
//get the typeData and pass back the data without the cleanup function
|
||||||
ARC_ConfigTypeData *typeData = (ARC_ConfigTypeData *)ARC_Hashtable_Get(config->currentGroup, (void *)name->data);
|
ARC_ConfigTypeData *typeData = (ARC_ConfigTypeData *)ARC_Hashtable_Get(config->currentGroup, (void *)name->data);
|
||||||
if(typeData == NULL){
|
if(typeData == NULL){
|
||||||
|
|
@ -1049,7 +1061,7 @@ void ARC_ConfigType_BoolCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_
|
||||||
ARC_ParserTagToken *childTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(parsedData->tagTokens, 0);
|
ARC_ParserTagToken *childTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(parsedData->tagTokens, 0);
|
||||||
if(childTagToken->id != ARC_CONFIG_VARIABLE){
|
if(childTagToken->id != ARC_CONFIG_VARIABLE){
|
||||||
arc_errno = ARC_ERRNO_DATA;
|
arc_errno = ARC_ERRNO_DATA;
|
||||||
ARC_DEBUG_LOG_ERROR("ARC_ConfigType_BoolNumberHelperCopyFn(type, parsedData, config, userdata), parsed data was not a <numberSign>");
|
ARC_DEBUG_LOG_ERROR("ARC_ConfigType_BoolCopyFn(type, parsedData, config, userdata), parsed data was not a <numberSign>");
|
||||||
*type = NULL;
|
*type = NULL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -1079,12 +1091,12 @@ void ARC_ConfigType_BoolCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_
|
||||||
|
|
||||||
//error if true or false was not passed in
|
//error if true or false was not passed in
|
||||||
arc_errno = ARC_ERRNO_DATA;
|
arc_errno = ARC_ERRNO_DATA;
|
||||||
ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("ARC_ConfigType_BoolNumberHelperCopyFn(type, parsedData, config, userdata), bool can only be \"true\" or \"false\" but was given \"%s\"", value->data);
|
ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("ARC_ConfigType_BoolCopyFn(type, parsedData, config, userdata), bool can only be \"true\" or \"false\" but was given \"%s\"", value->data);
|
||||||
ARC_String_Destroy(value);
|
ARC_String_Destroy(value);
|
||||||
*type = NULL;
|
*type = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ARC_ConfigType_BoolDestroyFn(void *type){
|
void ARC_ConfigType_BoolDestroyFn(ARC_Config *config, void *type){
|
||||||
free((ARC_Bool *)type);
|
free((ARC_Bool *)type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1248,7 +1260,7 @@ void ARC_ConfigType_Int8CopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_
|
||||||
ARC_ConfigType_IntNumberHelperCopyFn(type, parsedData, ~(uint8_t)0);
|
ARC_ConfigType_IntNumberHelperCopyFn(type, parsedData, ~(uint8_t)0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ARC_ConfigType_Int8DestroyFn(void *type){
|
void ARC_ConfigType_Int8DestroyFn(ARC_Config *config, void *type){
|
||||||
free((int8_t *)type);
|
free((int8_t *)type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1256,7 +1268,7 @@ void ARC_ConfigType_Uint8CopyFn(void **type, ARC_ParserTagToken *parsedData, ARC
|
||||||
ARC_ConfigType_UintNumberHelperCopyFn(type, parsedData, ~(uint8_t)0);
|
ARC_ConfigType_UintNumberHelperCopyFn(type, parsedData, ~(uint8_t)0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ARC_ConfigType_Uint8DestroyFn(void *type){
|
void ARC_ConfigType_Uint8DestroyFn(ARC_Config *config, void *type){
|
||||||
free((uint8_t *)type);
|
free((uint8_t *)type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1264,7 +1276,7 @@ void ARC_ConfigType_Int16CopyFn(void **type, ARC_ParserTagToken *parsedData, ARC
|
||||||
ARC_ConfigType_IntNumberHelperCopyFn(type, parsedData, ~(uint16_t)0);
|
ARC_ConfigType_IntNumberHelperCopyFn(type, parsedData, ~(uint16_t)0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ARC_ConfigType_Int16DestroyFn(void *type){
|
void ARC_ConfigType_Int16DestroyFn(ARC_Config *config, void *type){
|
||||||
free((int16_t *)type);
|
free((int16_t *)type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1272,7 +1284,7 @@ void ARC_ConfigType_Uint16CopyFn(void **type, ARC_ParserTagToken *parsedData, AR
|
||||||
ARC_ConfigType_UintNumberHelperCopyFn(type, parsedData, ~(uint16_t)0);
|
ARC_ConfigType_UintNumberHelperCopyFn(type, parsedData, ~(uint16_t)0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ARC_ConfigType_Uint16DestroyFn(void *type){
|
void ARC_ConfigType_Uint16DestroyFn(ARC_Config *config, void *type){
|
||||||
free((uint16_t *)type);
|
free((uint16_t *)type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1280,7 +1292,7 @@ void ARC_ConfigType_Int32CopyFn(void **type, ARC_ParserTagToken *parsedData, ARC
|
||||||
ARC_ConfigType_IntNumberHelperCopyFn(type, parsedData, ~(uint32_t)0);
|
ARC_ConfigType_IntNumberHelperCopyFn(type, parsedData, ~(uint32_t)0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ARC_ConfigType_Int32DestroyFn(void *type){
|
void ARC_ConfigType_Int32DestroyFn(ARC_Config *config, void *type){
|
||||||
free((int32_t *)type);
|
free((int32_t *)type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1288,7 +1300,7 @@ void ARC_ConfigType_Uint32CopyFn(void **type, ARC_ParserTagToken *parsedData, AR
|
||||||
ARC_ConfigType_UintNumberHelperCopyFn(type, parsedData, ~(uint32_t)0);
|
ARC_ConfigType_UintNumberHelperCopyFn(type, parsedData, ~(uint32_t)0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ARC_ConfigType_Uint32DestroyFn(void *type){
|
void ARC_ConfigType_Uint32DestroyFn(ARC_Config *config, void *type){
|
||||||
free((uint32_t *)type);
|
free((uint32_t *)type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1296,7 +1308,7 @@ void ARC_ConfigType_Int64CopyFn(void **type, ARC_ParserTagToken *parsedData, ARC
|
||||||
ARC_ConfigType_IntNumberHelperCopyFn(type, parsedData, ~(uint64_t)0);
|
ARC_ConfigType_IntNumberHelperCopyFn(type, parsedData, ~(uint64_t)0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ARC_ConfigType_Int64DestroyFn(void *type){
|
void ARC_ConfigType_Int64DestroyFn(ARC_Config *config, void *type){
|
||||||
free((int64_t *)type);
|
free((int64_t *)type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1304,7 +1316,7 @@ void ARC_ConfigType_Uint64CopyFn(void **type, ARC_ParserTagToken *parsedData, AR
|
||||||
ARC_ConfigType_UintNumberHelperCopyFn(type, parsedData, ~(uint64_t)0);
|
ARC_ConfigType_UintNumberHelperCopyFn(type, parsedData, ~(uint64_t)0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ARC_ConfigType_Uint64DestroyFn(void *type){
|
void ARC_ConfigType_Uint64DestroyFn(ARC_Config *config, void *type){
|
||||||
free((uint64_t *)type);
|
free((uint64_t *)type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1349,7 +1361,7 @@ void ARC_ConfigType_FloatCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC
|
||||||
*type = valuePointer;
|
*type = valuePointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ARC_ConfigType_FloatDestroyFn(void *type){
|
void ARC_ConfigType_FloatDestroyFn(ARC_Config *config, void *type){
|
||||||
free((float *)type);
|
free((float *)type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1395,7 +1407,7 @@ void ARC_ConfigType_DoubleCopyFn(void **type, ARC_ParserTagToken *parsedData, AR
|
||||||
*type = valuePointer;
|
*type = valuePointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ARC_ConfigType_DoubleDestroyFn(void *type){
|
void ARC_ConfigType_DoubleDestroyFn(ARC_Config *config, void *type){
|
||||||
free((double *)type);
|
free((double *)type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1412,6 +1424,6 @@ void ARC_ConfigType_StringCopyFn(void **type, ARC_ParserTagToken *parsedData, AR
|
||||||
ARC_ParserData_HelperRecurseStringAdd((ARC_String **)type, stringCharsTagToken);
|
ARC_ParserData_HelperRecurseStringAdd((ARC_String **)type, stringCharsTagToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ARC_ConfigType_StringDestroyFn(void *type){
|
void ARC_ConfigType_StringDestroyFn(ARC_Config *config, void *type){
|
||||||
ARC_String_Destroy(type);
|
ARC_String_Destroy(type);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue