archeus/include/arc/std/config.h
herbglitch db1adbb838 first
2022-10-27 15:16:54 -06:00

141 lines
No EOL
4.1 KiB
C

#ifndef ARC_STD_CONFIG_H_
#define ARC_STD_CONFIG_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "arc/std/hashtable.h"
#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
/**
* @brief a type that keeps permanice of data for when loading and unloading config files
*/
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
*/
typedef int32_t (* ARC_ConfigKeyRead)(ARC_Config* config, const char *data, ARC_StringSubstr *subdata, 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
*/
typedef int32_t (* ARC_ConfigKeyDelete)(ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value);
/**
* @brief adds a usable key to ARC_Config
*
* @param config ARC_Config we are adding 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);
/**
* @brief external callback to add keys to config
*/
typedef int32_t (* 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
*/
int32_t ARC_Config_Create(ARC_Config **config, ARC_ConfigKey_AddFunc keysAdd);
/**
* @brief destroys ARC_Config type
*
* @return 0 on sucess, ARC_ERRNO_ on fail
*/
int32_t ARC_Config_Destroy(ARC_Config *config);
/**
* @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 handles file io for ARC_Config Type
*
* @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);
#ifdef __cplusplus
}
#endif
#endif //ARC_STD_CONFIG_H_
#ifdef ARC_DEFAULT_CONFIG
#include "defaults/config.h"
#endif //ARC_DEFAULT_CONFIG