config and string reworked, hashtable updated to use arc_errno

This commit is contained in:
herbglitch 2023-01-17 01:59:08 -07:00
parent 0bbce28469
commit f8d987da8e
12 changed files with 1121 additions and 657 deletions

View file

@ -9,10 +9,6 @@ extern "C" {
#include "arc/std/string.h"
#include <stdint.h>
#ifndef ARC_HOME_PATH
#define ARC_HOME_PATH "./res/"
#endif //ARC_HOME_PATH
#define ARC_KEY_BUCKET_SIZE 0x20
#define ARC_GROUP_BUCKET_SIZE 0x20
#define ARC_GROUP_DATA_BUCKET_SIZE 0x20
@ -25,56 +21,85 @@ 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 data string of what is to be read in
* @param subdata location of stubstring in data for what is to be read in
* @param value value of read in variable
* @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 int32_t (* ARC_ConfigKeyRead)(ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value);
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 data string of what is going to be deleted (used to check if value is a reference)
* @param subdata location of substring in data for what is going to be deleted (used to check if value is a reference)
* @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 int32_t (* ARC_ConfigKeyDelete)(ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value);
typedef void (* ARC_ConfigKeyDelete)(ARC_Config* config, void *value);
/**
* @brief adds a usable key to ARC_Config
*
* @param config ARC_Config we are adding keys to
* @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
*
* @return 0 on sucess, ARC_ERRNO_ on fail
*/
int32_t ARC_ConfigKey_Add(ARC_Config *config, char *type, ARC_ConfigKeyRead keyRead, ARC_ConfigKeyDelete keyDelete);
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
*/
void ARC_Config_AddKeyCString(ARC_Config *config, const char *type, uint64_t length, ARC_ConfigKeyRead keyRead, ARC_ConfigKeyDelete keyDelete);
/**
* @brief external callback to add keys to config
*/
typedef int32_t (* ARC_ConfigKey_AddFunc)(ARC_Config *config);
typedef void (* ARC_ConfigKey_AddFunc)(ARC_Config *config);
/**
* @brief creates ARC_Config type
*
* @param config ARC_Config we are initializing
* @param keysAdd callback to add ConfigKeys to config->keys, can be NULL
*
* @return 0 on sucess, ARC_ERRNO_ on fail
* @param config ARC_Config to initialize
*/
int32_t ARC_Config_Create(ARC_Config **config, ARC_ConfigKey_AddFunc keysAdd);
void ARC_Config_Create(ARC_Config **config);
/**
* @brief destroys ARC_Config type
*
* @return 0 on sucess, ARC_ERRNO_ on fail
*/
int32_t ARC_Config_Destroy(ARC_Config *config);
void ARC_Config_Destroy(ARC_Config *config);
/**
* @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
*/
void ARC_Config_SetGroup(ARC_Config *config, ARC_String *groupname);
/**
* @brief get a value from a given keyname
*
* @note name may be prefaced with <group>:: to specify group
*
* @param config ARC_Config to get value from
* @param keyname name of key to get from config
* @param value data retrieved from config
*/
void ARC_Config_Get(ARC_Config *config, ARC_String *keyname, void **value);
/**
* @brief commands that can be used in ARC_Config_FileIO
@ -87,48 +112,8 @@ int32_t ARC_Config_Destroy(ARC_Config *config);
*
* @param config ARC_Config where io operations will take place
* @param path file path for io
*
* @return 0 on sucess, ARC_ERRNO_ on fail
*/
int32_t ARC_Config_FileIO(ARC_Config *config, const char *path, uint8_t command);
/**
* @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
*
* @return 0 on sucess, ARC_ERRNO_ on fail
*/
int32_t ARC_Config_SetGroup(ARC_Config *config, char *groupname);
/**
* @brief get a value from a given keyname
*
* @note name may be prefaced with <group>:: to specify group
*
* @param config ARC_Config to get value from
* @param keyname name of key to get from config
* @param value data retrieved from config
*
* @return 0 on sucess, ARC_ERRNO_ on fail
*/
int32_t ARC_Config_Get(ARC_Config *config, char *keyname, void **value);
/**
* @brief get a reference value from a given substring
*
* @note this function is meant to help with creation and deletion functions for types
*
* @param config ARC_Config to get value from
* @param data string that holds the substring that will be used
* @param subdata location of stubstring in data for what is to be read in
*
* @return a valid pointer on sucess, NULL on fail
*/
void *ARC_Config_GetReference(ARC_Config *config, char *data, ARC_StringSubstr *subdata);
void ARC_Config_FileIO(ARC_Config *config, ARC_String *path, uint8_t command);
#ifdef __cplusplus
}