archeus/src/math/config.c

371 lines
17 KiB
C
Raw Normal View History

#include "arc/math/config.h"
#include <stdio.h>
#include <stdlib.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){ sizeof(ARC_Point) , ARC_ConfigType_PointCopyFn , ARC_ConfigType_PointDestroyFn , NULL });
ARC_Config_RegisterTypeWithCStr(config, "ARC_FPoint", (ARC_ConfigType){ sizeof(ARC_FPoint), ARC_ConfigType_FPointCopyFn, ARC_ConfigType_FPointDestroyFn, NULL });
ARC_Config_RegisterTypeWithCStr(config, "ARC_Rect" , (ARC_ConfigType){ sizeof(ARC_Rect) , ARC_ConfigType_RectCopyFn , ARC_ConfigType_RectDestroyFn , NULL });
ARC_Config_RegisterTypeWithCStr(config, "ARC_FRect" , (ARC_ConfigType){ sizeof(ARC_FRect) , ARC_ConfigType_FRectCopyFn , ARC_ConfigType_FRectDestroyFn , 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(ARC_Config *config, void *type){
free((ARC_Point *)type);
}
void ARC_ConfigType_FPointCopyFn(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_FPointCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), nestedValue was not passed in for ARC_FPoint");
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_FPointCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), nested value { x } only had one value, fpoint needs two { x, y }");
return;
}
//get the first value
ARC_ParserTagToken *valueTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(valueArgsTagToken->tagTokens, 0);
float *pointTemp = NULL;
ARC_ConfigType_FloatCopyFn((void **)&pointTemp, valueTagToken, config, userdata);
if(pointTemp == NULL){
arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_LOG_ERROR("ARC_ConfigType_FPointCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), first parameter was not a float");
return;
}
//copy the xpoint value to stack and free the pointer
float 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_FPointCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), nested value { x, y, ... } had too many values, fpoint needs two { x, y }");
return;
}
//get the second value
valueTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(valueArgsTagToken->tagTokens, 0);
ARC_ConfigType_FloatCopyFn((void **)&pointTemp, valueTagToken, config, userdata);
if(pointTemp == NULL){
arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_LOG_ERROR("ARC_ConfigType_FPointCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), second parameter was not a float");
return;
}
//copy the last value and free the temp value
ARC_FPoint *point = (ARC_FPoint *)malloc(sizeof(ARC_FPoint));
*point = (ARC_FPoint){ pointX, *pointTemp };
free(pointTemp);
//set the type value
*type = (void *)point;
}
void ARC_ConfigType_FPointDestroyFn(ARC_Config *config, void *type){
free((ARC_FPoint *)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_Rect");
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_RectCopyFn(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(ARC_Config *config, void *type){
free((ARC_Rect *)type);
}
void ARC_ConfigType_FRectCopyFn(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_FRectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), nestedValue was not passed in for ARC_FRect");
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_FRectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), nested value { x } only had one value, frect needs four { x, y, w, h }");
return;
}
//get the first value
ARC_ParserTagToken *valueTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(valueArgsTagToken->tagTokens, 0);
float *pointTemp = NULL;
ARC_ConfigType_FloatCopyFn((void **)&pointTemp, valueTagToken, config, userdata);
if(pointTemp == NULL){
arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_LOG_ERROR("ARC_ConfigType_FRectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), first parameter was not a float");
return;
}
//copy the xpoint value to stack and free the pointer
float 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_FRectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), nested value { x, y } only had two values, frect needs four { x, y, w, h }");
return;
}
//get the second value
valueTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(valueArgsTagToken->tagTokens, 0);
ARC_ConfigType_FloatCopyFn((void **)&pointTemp, valueTagToken, config, userdata);
if(pointTemp == NULL){
arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_LOG_ERROR("ARC_ConfigType_FRectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), second parameter was not a float");
return;
}
float 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_FRectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), nested value { x, y, w } only had three values, frect needs four { x, y, w, h }");
return;
}
//get the third value
valueTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(valueArgsTagToken->tagTokens, 0);
ARC_ConfigType_FloatCopyFn((void **)&pointTemp, valueTagToken, config, userdata);
if(pointTemp == NULL){
arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_LOG_ERROR("ARC_ConfigType_FRectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), third parameter was not a float");
return;
}
float 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_FRectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), nested value { x, y, w, h, ... } had too many values, frect needs four { x, y, w, h }");
return;
}
//get the fourth value
valueTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(valueArgsTagToken->tagTokens, 0);
ARC_ConfigType_FloatCopyFn((void **)&pointTemp, valueTagToken, config, userdata);
if(pointTemp == NULL){
arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_LOG_ERROR("ARC_ConfigType_FRectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), fourth parameter was not a float");
return;
}
//copy the last value and free the temp value
ARC_FRect *point = (ARC_FRect *)malloc(sizeof(ARC_FPoint));
*point = (ARC_FRect){ pointX, pointY, pointW, *pointTemp };
free(pointTemp);
//set the type value
*type = (void *)point;
}
void ARC_ConfigType_FRectDestroyFn(ARC_Config *config, void *type){
free((ARC_FRect *)type);
}