renamed chemical to config, and renamed life to entity

This commit is contained in:
herbglitch 2025-03-11 00:41:17 -06:00
parent 30e8d94805
commit 04c89e46fe
10 changed files with 862 additions and 1725 deletions

View file

@ -5,122 +5,201 @@
extern "C" {
#endif
#include "arc/std/hashtable.h"
#include "arc/std/string.h"
#include <stdint.h>
#define ARC_KEY_BUCKET_SIZE 0x20
#define ARC_GROUP_BUCKET_SIZE 0x20
#define ARC_GROUP_DATA_BUCKET_SIZE 0x20
#include "arc/std/parser.h"
/**
* @brief a type that keeps permanice of data for when loading and unloading config files
*/
* @brief the config type for archeus, loads in a config file which syntax is specified in the documentation
* @TODO: add documentation link here
*/
typedef struct ARC_Config ARC_Config;
/**
* @brief a function to read a key from string to a ARC_ConfigTypeTemplate
*
* @param config ARC_Config to store data to
* @param string ARC_String of data that is being read in
* @param value value that is read in
*
* @note use ARC_Config_StoreValue(ARC_Config *config, ARC_String *name, void *value); to store a value to the config
* if there is an error, set arc_errno
*
* @return 0 if value not a reference, 1 if value is a reference
*/
typedef uint8_t (* ARC_ConfigKeyRead)(ARC_Config* config, ARC_String *string, void **value);
/**
* @brief a function to delete a value from a key in ARC_Config
*
* @param config ARC_Config that can be used to check for references in data
* @param value pointer of data to be deleted
*
* @note this function can be NULL if memory does not need to be cleaned for this type
* if there is an error, set arc_errno
*/
typedef void (* ARC_ConfigKeyDelete)(ARC_Config* config, ARC_String *string, void *value);
/**
* @brief adds a usable key to ARC_Config
*
* @param config ARC_Config to add keys to
* @param type string of key type
* @param keyRead function for reading/creating key from string
* @param keyDelete function for deleting stored key
*/
void ARC_Config_AddKey(ARC_Config *config, ARC_String *type, ARC_ConfigKeyRead keyRead, ARC_ConfigKeyDelete keyDelete);
/**
* @brief adds a key from a cstring
* @param config ARC_Config to add keys to
* @param type cstring of key type
* @param length length of cstring
* @param keyRead function for reading/creating key from string
* @param keyDelete function for deleting stored key
* @brief a function callback to create a type stored within a config
*/
//void ARC_Config_AddKeyCString(ARC_Config *config, const char *type, uint64_t length, ARC_ConfigKeyRead keyRead, ARC_ConfigKeyDelete keyDelete);
typedef void (* ARC_ConfigType_CopyFn)(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config);
/**
* @brief external callback to add keys to config
*/
typedef void (* ARC_ConfigKey_AddFunc)(ARC_Config *config);
* @brief a function callback to destroy a type
*/
typedef void (* ARC_ConfigType_DestroyFn)(void *type);
/**
* @brief creates ARC_Config type
*
* @param config ARC_Config to initialize
*/
* @brief the functions for used for loading and unloading a type, the name will be the key of a hashtable
*/
typedef struct ARC_ConfigType {
ARC_ConfigType_CopyFn copyFn;
ARC_ConfigType_DestroyFn destroyFn;
} ARC_ConfigType;
/**
* @brief creates the arc config type (a type that loads in config files and can have types added to it)
*/
void ARC_Config_Create(ARC_Config **config);
/**
* @brief destroys ARC_Config type
*/
* @brief destroys an ARC_Config type
*/
void ARC_Config_Destroy(ARC_Config *config);
/**
* @brief adds creation and destruction functions for a new user provided type will be used for config load and unload functions
*
* @note this function uses ARC_Config_RegisterTypeWithCStr so it shares error messages with that function
*
* @param[in] config the ARC_Config to set the new type into
* @param[in] typeName the name of the type like "uint32" or "ARC_Rect" that will be read in from a config file
* @param[in] type the copy and destroy functions for the type used on load and unload
*/
void ARC_Config_RegisterType(ARC_Config *config, ARC_String *typeName, ARC_ConfigType type);
/**
* @brief adds creation and destruction functions for a new user provided type
*
* @param[in] config the ARC_Config to set the new type into
* @param[in] typeName the name of the type like "uint32" or "ARC_Rect" that will be read in from a config file
* @param[in] type the copy and destroy functions for the type used on load and unload
*/
void ARC_Config_RegisterTypeWithCStr(ARC_Config *config, const char *typeNameCStr, ARC_ConfigType type);
/**
* @brief sets current group in config
*
* @note ARC_Config_Get will use this set group
* @note this function uses ARC_Config_SetGroupWithCStr so it shares error messages with that function
*
* @param[in] config ARC_Config we are setting current group in
* @param[in] groupname name of group that will be set
*/
void ARC_Config_SetGroup(ARC_Config *config, ARC_String *groupName);
/**
* @brief sets current group in config
*
* @note ARC_Config_Get will use this set group
*
* @param config ARC_Config we are setting current group in
* @param groupname name of group that will be set
* @param[in] config ARC_Config we are setting current group in
* @param[in] groupname name of group that will be set
*/
void ARC_Config_SetGroup(ARC_Config *config, ARC_String *groupname);
void ARC_Config_SetGroupWithCStr(ARC_Config *config, const char *groupName);
/**
* @brief get a value from a given name
*
* @note name should be prefaced with <group>:: to specify group
*
* @param[in] config ARC_Config to get value from
* @param[in] name name of a variable that has been read in
*
* @return the stored element on success, or NULL on failure
*/
void *ARC_Config_Get(ARC_Config *config, ARC_String *name);
/**
* @brief get a value from a given keyname
*
* @note name may be prefaced with <group>:: to specify group
* @note name should be prefaced with <group>:: to specify group
* @note this function uses ARC_Config_Get so it shares error messages with that function
*
* @param config ARC_Config to get value from
* @param keyname name of key to get from config
* @param value data retrieved from config
* @param[in] config ARC_Config to get value from
* @param[in] name name of a variable that has been read in
*
* @return the stored element on success, or NULL on failure
*/
//void ARC_Config_Get(ARC_Config *config, ARC_String *keyname, void **value);
void *ARC_Config_GetWithCStr(ARC_Config *config, const char *name);
/**
* @brief commands that can be used in ARC_Config_FileIO
*/
#define ARC_CONFIG_FILE_IO_LOAD 0x00
#define ARC_CONFIG_FILE_IO_UNLOAD 0x01
* @brief TODO: write this
*/
void ARC_Config_LoadFromString(ARC_Config *config, ARC_String **string);
/**
* @brief handles file io for ARC_Config Type
*
* @param config ARC_Config where io operations will take place
* @param path file path for io
*/
void ARC_Config_FileIO(ARC_Config *config, ARC_String *path, uint8_t command);
* @brief TODO: write this
*/
void ARC_Config_LoadFromFile(ARC_Config *config, ARC_String *path);
/**
* @brief TODO: write this
*/
void ARC_Config_UnloadFromString(ARC_Config *config, ARC_String **string);
/**
* @brief TODO: write this
*/
void ARC_Config_UnloadFromFile(ARC_Config *config, ARC_String *data);
#define ARC_CONFIG_DEFAULT_GROUP " "
#define ARC_CONFIG_GROUP_TAG_NAME "group"
#define ARC_CONFIG_GROUP_SEPARATOR "::"
//the grouping is based on the ascii table, but the ids are sequential to make finding tokens quicker (look at the lexer continious for more explanation)
#define ARC_CONFIG_TAB 0x01
#define ARC_CONFIG_NEWLINE 0x02
#define ARC_CONFIG_SPACE 0x03
#define ARC_CONFIG_BANG 0x04
#define ARC_CONFIG_QUOTE 0x05
#define ARC_CONFIG_HASH 0x06
#define ARC_CONFIG_DOLLAR 0x07
#define ARC_CONFIG_PERCENT 0x08
#define ARC_CONFIG_AMPERSAND 0x09
#define ARC_CONFIG_SINGLE_QUOTE 0x0A
#define ARC_CONFIG_OPEN_PAREN 0x0B
#define ARC_CONFIG_CLOSE_PAREN 0x0C
#define ARC_CONFIG_ASTERISK 0x0D
#define ARC_CONFIG_PLUS 0x0E
#define ARC_CONFIG_COMMA 0x0F
#define ARC_CONFIG_MINUS 0x10
#define ARC_CONFIG_PERIOD 0x11
#define ARC_CONFIG_SLASH 0x12
#define ARC_CONFIG_NUMBER 0x13
#define ARC_CONFIG_COLON 0x14
#define ARC_CONFIG_SEMICOLON 0x15
#define ARC_CONFIG_LESS_THAN 0x16
#define ARC_CONFIG_GREATER_THAN 0x17
#define ARC_CONFIG_EQUAL 0x18
#define ARC_CONFIG_QUESTION_MARK 0x19
#define ARC_CONFIG_AT 0x1A
#define ARC_CONFIG_ALPHA_UPPER_CHAR 0x1B
#define ARC_CONFIG_OPEN_BRACKET 0x1C
#define ARC_CONFIG_BACKSLASH 0x1D
#define ARC_CONFIG_CLOSE_BRACKET 0x1E
#define ARC_CONFIG_CARET 0x1F
#define ARC_CONFIG_UNDERSCORE 0x20
#define ARC_CONFIG_GRAVE 0x21
#define ARC_CONFIG_ALPHA_LOWER_CHAR 0x22
#define ARC_CONFIG_OPEN_CURLY_BRACE 0x23
#define ARC_CONFIG_VERTICAL_LINE 0x24
#define ARC_CONFIG_CLOSE_CURLY_BRACE 0x25
#define ARC_CONFIG_TILDE 0x26
#define ARC_CONFIG_LANGUAGE 0x27
#define ARC_CONFIG_GROUP 0x28
#define ARC_CONFIG_GROUP_NAME 0x29
#define ARC_CONFIG_GROUP_ARGS 0x2A
#define ARC_CONFIG_VARIABLE_LINES 0x2B
#define ARC_CONFIG_VARIABLE_LINE 0x2C
#define ARC_CONFIG_ALLOW_SPACE 0x2D
#define ARC_CONFIG_TYPE 0x2E
#define ARC_CONFIG_VALUE 0x2F
#define ARC_CONFIG_NESTED_VALUE 0x30
#define ARC_CONFIG_VALUE_ARGS 0x31
#define ARC_CONFIG_VARIABLE 0x32
#define ARC_CONFIG_VARIABLE_NAME 0x33
#define ARC_CONFIG_VARIABLE_CHAR 0x34
#define ARC_CONFIG_STRING 0x35
#define ARC_CONFIG_STRING_CHARS 0x36
#define ARC_CONFIG_STRING_CHAR 0x37
#define ARC_CONFIG_ESCAPE_CHAR 0x38
#define ARC_CONFIG_NUMBER_SIGN 0x39
#define ARC_CONFIG_NUMBER_TAG 0x3A
#define ARC_CONFIG_WHITESPACE 0x3B
#ifdef __cplusplus
}
#endif
#endif //ARC_STD_CONFIG_H_
#ifdef ARC_DEFAULT_CONFIG
#include "defaults/config.h"
#endif //ARC_DEFAULT_CONFIG