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
|
|
@ -24,6 +24,7 @@ struct ARC_Config {
|
|||
};
|
||||
|
||||
typedef struct ARC_ConfigTypeData {
|
||||
ARC_Config *config;
|
||||
void *data;
|
||||
ARC_ConfigType_DestroyFn destroyFn;
|
||||
} ARC_ConfigTypeData;
|
||||
|
|
@ -311,12 +312,12 @@ void ARC_Config_GroupDataHashtableDestroyKeyValueFn(void *key, void *value){
|
|||
free((char *)key);
|
||||
|
||||
ARC_ConfigTypeData *typeData = (ARC_ConfigTypeData *)value;
|
||||
typeData->destroyFn(typeData->data);
|
||||
typeData->destroyFn(typeData->config, typeData->data);
|
||||
free(typeData);
|
||||
}
|
||||
|
||||
//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
|
||||
|
|
@ -359,7 +360,7 @@ void ARC_ConfigData_RunVariableLineTag(ARC_ParserTagToken *tagToken, ARC_Config
|
|||
ARC_Array *array = (ARC_Array *)removingType->data;
|
||||
|
||||
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;
|
||||
|
|
@ -400,6 +401,7 @@ void ARC_ConfigData_RunVariableLineTag(ARC_ParserTagToken *tagToken, ARC_Config
|
|||
|
||||
//create where to store either the reference or type data
|
||||
typeData = (ARC_ConfigTypeData *)malloc(sizeof(ARC_ConfigTypeData));
|
||||
typeData->config = config;
|
||||
if(value != NULL){
|
||||
//point to the already stored data
|
||||
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){
|
||||
//check if type exists in the types hashtable
|
||||
ARC_ConfigType *typeValue = (ARC_ConfigType *)ARC_Hashtable_Get(config->types, name->data);
|
||||
if(type == NULL){
|
||||
if(typeValue == NULL){
|
||||
//throw an error and return
|
||||
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);
|
||||
|
|
@ -864,16 +866,29 @@ void ARC_Config_AddWithCStr(ARC_Config *config, const char *type, const char *na
|
|||
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
|
||||
uint64_t startSeparatorIndex = ARC_String_FindCStringWithStrlen(name, ARC_CONFIG_GROUP_SEPARATOR);
|
||||
if(startSeparatorIndex == ~(uint64_t)0){
|
||||
//remove the value from the hashtable if it exists
|
||||
ARC_ConfigTypeData *typeData = (ARC_ConfigTypeData *)ARC_Hashtable_Get(config->currentGroup, (void *)name->data);
|
||||
if(typeData != NULL){
|
||||
ARC_Hashtable_Remove(config->currentGroup, (void *)name->data);
|
||||
if(typeData == NULL){
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -906,13 +921,13 @@ void ARC_Config_Remove(ARC_Config *config, ARC_String *name){
|
|||
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
|
||||
ARC_String *nameString;
|
||||
ARC_String_CreateWithStrlen(&nameString, (char *)name);
|
||||
|
||||
//add as an ARC_String
|
||||
ARC_Config_Remove(config, nameString);
|
||||
ARC_Config_Remove(config, nameString, isArray);
|
||||
|
||||
//cleanup
|
||||
ARC_String_Destroy(nameString);
|
||||
|
|
@ -941,9 +956,6 @@ void *ARC_Config_Get(ARC_Config *config, ARC_String *name){
|
|||
//check if the group separator exists
|
||||
uint64_t startSeparatorIndex = ARC_String_FindCStringWithStrlen(name, ARC_CONFIG_GROUP_SEPARATOR);
|
||||
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
|
||||
ARC_ConfigTypeData *typeData = (ARC_ConfigTypeData *)ARC_Hashtable_Get(config->currentGroup, (void *)name->data);
|
||||
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);
|
||||
if(childTagToken->id != ARC_CONFIG_VARIABLE){
|
||||
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;
|
||||
return;
|
||||
}
|
||||
|
|
@ -1079,12 +1091,12 @@ void ARC_ConfigType_BoolCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_
|
|||
|
||||
//error if true or false was not passed in
|
||||
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);
|
||||
*type = NULL;
|
||||
}
|
||||
|
||||
void ARC_ConfigType_BoolDestroyFn(void *type){
|
||||
void ARC_ConfigType_BoolDestroyFn(ARC_Config *config, void *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);
|
||||
}
|
||||
|
||||
void ARC_ConfigType_Int8DestroyFn(void *type){
|
||||
void ARC_ConfigType_Int8DestroyFn(ARC_Config *config, void *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);
|
||||
}
|
||||
|
||||
void ARC_ConfigType_Uint8DestroyFn(void *type){
|
||||
void ARC_ConfigType_Uint8DestroyFn(ARC_Config *config, void *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);
|
||||
}
|
||||
|
||||
void ARC_ConfigType_Int16DestroyFn(void *type){
|
||||
void ARC_ConfigType_Int16DestroyFn(ARC_Config *config, void *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);
|
||||
}
|
||||
|
||||
void ARC_ConfigType_Uint16DestroyFn(void *type){
|
||||
void ARC_ConfigType_Uint16DestroyFn(ARC_Config *config, void *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);
|
||||
}
|
||||
|
||||
void ARC_ConfigType_Int32DestroyFn(void *type){
|
||||
void ARC_ConfigType_Int32DestroyFn(ARC_Config *config, void *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);
|
||||
}
|
||||
|
||||
void ARC_ConfigType_Uint32DestroyFn(void *type){
|
||||
void ARC_ConfigType_Uint32DestroyFn(ARC_Config *config, void *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);
|
||||
}
|
||||
|
||||
void ARC_ConfigType_Int64DestroyFn(void *type){
|
||||
void ARC_ConfigType_Int64DestroyFn(ARC_Config *config, void *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);
|
||||
}
|
||||
|
||||
void ARC_ConfigType_Uint64DestroyFn(void *type){
|
||||
void ARC_ConfigType_Uint64DestroyFn(ARC_Config *config, void *type){
|
||||
free((uint64_t *)type);
|
||||
}
|
||||
|
||||
|
|
@ -1349,7 +1361,7 @@ void ARC_ConfigType_FloatCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC
|
|||
*type = valuePointer;
|
||||
}
|
||||
|
||||
void ARC_ConfigType_FloatDestroyFn(void *type){
|
||||
void ARC_ConfigType_FloatDestroyFn(ARC_Config *config, void *type){
|
||||
free((float *)type);
|
||||
}
|
||||
|
||||
|
|
@ -1395,7 +1407,7 @@ void ARC_ConfigType_DoubleCopyFn(void **type, ARC_ParserTagToken *parsedData, AR
|
|||
*type = valuePointer;
|
||||
}
|
||||
|
||||
void ARC_ConfigType_DoubleDestroyFn(void *type){
|
||||
void ARC_ConfigType_DoubleDestroyFn(ARC_Config *config, void *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);
|
||||
}
|
||||
|
||||
void ARC_ConfigType_StringDestroyFn(void *type){
|
||||
void ARC_ConfigType_StringDestroyFn(ARC_Config *config, void *type){
|
||||
ARC_String_Destroy(type);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue