#include "arc/math/config.h" #include #include #include "arc/std/array.h" #include "arc/std/string.h" #include "arc/std/errno.h" #include "arc/std/config.h" #include "arc/math/point.h" #include "arc/math/rectangle.h" void ARC_Config_InitMath(ARC_Config *config){ ARC_Config_RegisterTypeWithCStr(config, "ARC_Point", (ARC_ConfigType){ ARC_ConfigType_PointCopyFn, ARC_ConfigType_PointDestroyFn, NULL }); ARC_Config_RegisterTypeWithCStr(config, "ARC_Rect" , (ARC_ConfigType){ ARC_ConfigType_RectCopyFn , ARC_ConfigType_RectDestroyFn , NULL }); } void ARC_ConfigType_PointCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata){ 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_PointCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), nestedValue was not passed in for ARC_Point"); type = NULL; return; } //get the valueArgs ARC_ParserTagToken *valueArgsTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(childTagToken->tagTokens, 2); //if there is only a value with no comma break if(ARC_Vector_GetSize(valueArgsTagToken->tagTokens) == 1){ arc_errno = ARC_ERRNO_DATA; ARC_DEBUG_LOG_ERROR("ARC_ConfigType_PointCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), nested value { x } only had one value, point needs two { x, y }"); return; } //get the first value ARC_ParserTagToken *valueTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(valueArgsTagToken->tagTokens, 0); int32_t *pointTemp = NULL; ARC_ConfigType_Int32CopyFn((void **)&pointTemp, valueTagToken, config, userdata); if(pointTemp == NULL){ arc_errno = ARC_ERRNO_DATA; ARC_DEBUG_LOG_ERROR("ARC_ConfigType_PointCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), first parameter was not a int32"); return; } //copy the xpoint value to stack and free the pointer int32_t pointX = *pointTemp; free(pointTemp); pointTemp = NULL; //get the second value valueArgsTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(valueArgsTagToken->tagTokens, 4); //if there is an empty comma break if(ARC_Vector_GetSize(valueArgsTagToken->tagTokens) > 1){ arc_errno = ARC_ERRNO_DATA; ARC_DEBUG_LOG_ERROR("ARC_ConfigType_PointCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), nested value { x, y, ... } had too many values, point needs two { x, y }"); return; } //get the second value valueTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(valueArgsTagToken->tagTokens, 0); ARC_ConfigType_Int32CopyFn((void **)&pointTemp, valueTagToken, config, userdata); if(pointTemp == NULL){ arc_errno = ARC_ERRNO_DATA; ARC_DEBUG_LOG_ERROR("ARC_ConfigType_PointCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), second parameter was not a int32"); return; } //copy the last value and free the temp value ARC_Point *point = (ARC_Point *)malloc(sizeof(ARC_Point)); *point = (ARC_Point){ pointX, *pointTemp }; free(pointTemp); //set the type value *type = (void *)point; } void ARC_ConfigType_PointDestroyFn(void *type){ free((ARC_Point *)type); } void ARC_ConfigType_RectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata){ 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_RectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), nestedValue was not passed in for ARC_Point"); type = NULL; return; } //get the valueArgs ARC_ParserTagToken *valueArgsTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(childTagToken->tagTokens, 2); //if there is only a value with no comma break if(ARC_Vector_GetSize(valueArgsTagToken->tagTokens) == 1){ arc_errno = ARC_ERRNO_DATA; ARC_DEBUG_LOG_ERROR("ARC_ConfigType_RectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), nested value { x } only had one value, rect needs four { x, y, w, h }"); return; } //get the first value ARC_ParserTagToken *valueTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(valueArgsTagToken->tagTokens, 0); int32_t *pointTemp = NULL; ARC_ConfigType_Int32CopyFn((void **)&pointTemp, valueTagToken, config, userdata); if(pointTemp == NULL){ arc_errno = ARC_ERRNO_DATA; ARC_DEBUG_LOG_ERROR("ARC_ConfigType_PointCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), first parameter was not a int32"); return; } //copy the xpoint value to stack and free the pointer int32_t pointX = *pointTemp; free(pointTemp); pointTemp = NULL; //get the second value valueArgsTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(valueArgsTagToken->tagTokens, 4); //if there is only a value with no comma break if(ARC_Vector_GetSize(valueArgsTagToken->tagTokens) == 1){ arc_errno = ARC_ERRNO_DATA; ARC_DEBUG_LOG_ERROR("ARC_ConfigType_RectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), nested value { x, y } only had two values, rect needs four { x, y, w, h }"); return; } //get the second value valueTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(valueArgsTagToken->tagTokens, 0); ARC_ConfigType_Int32CopyFn((void **)&pointTemp, valueTagToken, config, userdata); if(pointTemp == NULL){ arc_errno = ARC_ERRNO_DATA; ARC_DEBUG_LOG_ERROR("ARC_ConfigType_RectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), second parameter was not a int32"); return; } int32_t pointY = *pointTemp; free(pointTemp); pointTemp = NULL; //get the third value valueArgsTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(valueArgsTagToken->tagTokens, 4); //if there is an empty comma break if(ARC_Vector_GetSize(valueArgsTagToken->tagTokens) == 1){ arc_errno = ARC_ERRNO_DATA; ARC_DEBUG_LOG_ERROR("ARC_ConfigType_RectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), nested value { x, y, w } only had three values, rect needs four { x, y, w, h }"); return; } //get the third value valueTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(valueArgsTagToken->tagTokens, 0); ARC_ConfigType_Int32CopyFn((void **)&pointTemp, valueTagToken, config, userdata); if(pointTemp == NULL){ arc_errno = ARC_ERRNO_DATA; ARC_DEBUG_LOG_ERROR("ARC_ConfigType_RectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), third parameter was not a int32"); return; } int32_t pointW = *pointTemp; free(pointTemp); pointTemp = NULL; //get the fourth value valueArgsTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(valueArgsTagToken->tagTokens, 4); //if there is an empty comma break if(ARC_Vector_GetSize(valueArgsTagToken->tagTokens) > 1){ arc_errno = ARC_ERRNO_DATA; ARC_DEBUG_LOG_ERROR("ARC_ConfigType_RectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), nested value { x, y, w, h, ... } had too many values, rect needs four { x, y, w, h }"); return; } //get the fourth value valueTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(valueArgsTagToken->tagTokens, 0); ARC_ConfigType_Int32CopyFn((void **)&pointTemp, valueTagToken, config, userdata); if(pointTemp == NULL){ arc_errno = ARC_ERRNO_DATA; ARC_DEBUG_LOG_ERROR("ARC_ConfigType_RectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), fourth parameter was not a int32"); return; } //copy the last value and free the temp value ARC_Rect *point = (ARC_Rect *)malloc(sizeof(ARC_Point)); *point = (ARC_Rect){ pointX, pointY, pointW, *pointTemp }; free(pointTemp); //set the type value *type = (void *)point; } void ARC_ConfigType_RectDestroyFn(void *type){ free((ARC_Rect *)type); }