2022-10-27 15:16:54 -06:00
|
|
|
#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>
|
|
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
*
|
2023-01-17 01:59:08 -07:00
|
|
|
* @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
|
2022-10-27 15:16:54 -06:00
|
|
|
*/
|
2023-01-17 01:59:08 -07:00
|
|
|
typedef uint8_t (* ARC_ConfigKeyRead)(ARC_Config* config, ARC_String *string, void **value);
|
2022-10-27 15:16:54 -06:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @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
|
2023-01-17 01:59:08 -07:00
|
|
|
*
|
|
|
|
|
* @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
|
2022-10-27 15:16:54 -06:00
|
|
|
*/
|
2023-01-20 22:38:29 -07:00
|
|
|
typedef void (* ARC_ConfigKeyDelete)(ARC_Config* config, ARC_String *string, void *value);
|
2022-10-27 15:16:54 -06:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief adds a usable key to ARC_Config
|
|
|
|
|
*
|
2023-01-17 01:59:08 -07:00
|
|
|
* @param config ARC_Config to add keys to
|
2022-10-27 15:16:54 -06:00
|
|
|
* @param type string of key type
|
|
|
|
|
* @param keyRead function for reading/creating key from string
|
|
|
|
|
* @param keyDelete function for deleting stored key
|
|
|
|
|
*/
|
2023-01-17 01:59:08 -07:00
|
|
|
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);
|
2022-10-27 15:16:54 -06:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief external callback to add keys to config
|
|
|
|
|
*/
|
2023-01-17 01:59:08 -07:00
|
|
|
typedef void (* ARC_ConfigKey_AddFunc)(ARC_Config *config);
|
2022-10-27 15:16:54 -06:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief creates ARC_Config type
|
|
|
|
|
*
|
2023-01-17 01:59:08 -07:00
|
|
|
* @param config ARC_Config to initialize
|
2022-10-27 15:16:54 -06:00
|
|
|
*/
|
2023-01-17 01:59:08 -07:00
|
|
|
void ARC_Config_Create(ARC_Config **config);
|
2022-10-27 15:16:54 -06:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief destroys ARC_Config type
|
|
|
|
|
*/
|
2023-01-17 01:59:08 -07:00
|
|
|
void ARC_Config_Destroy(ARC_Config *config);
|
2022-10-27 15:16:54 -06:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @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
|
|
|
|
|
*/
|
2023-01-17 01:59:08 -07:00
|
|
|
void ARC_Config_SetGroup(ARC_Config *config, ARC_String *groupname);
|
2022-10-27 15:16:54 -06:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @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
|
|
|
|
|
*/
|
2023-01-17 01:59:08 -07:00
|
|
|
void ARC_Config_Get(ARC_Config *config, ARC_String *keyname, void **value);
|
2022-10-27 15:16:54 -06:00
|
|
|
|
|
|
|
|
/**
|
2023-01-17 01:59:08 -07:00
|
|
|
* @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
|
2022-10-27 15:16:54 -06:00
|
|
|
*
|
2023-01-17 01:59:08 -07:00
|
|
|
* @param config ARC_Config where io operations will take place
|
|
|
|
|
* @param path file path for io
|
2022-10-27 15:16:54 -06:00
|
|
|
*/
|
2023-01-17 01:59:08 -07:00
|
|
|
void ARC_Config_FileIO(ARC_Config *config, ARC_String *path, uint8_t command);
|
2022-10-27 15:16:54 -06:00
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#endif //ARC_STD_CONFIG_H_
|
|
|
|
|
|
|
|
|
|
#ifdef ARC_DEFAULT_CONFIG
|
|
|
|
|
#include "defaults/config.h"
|
2022-10-29 00:22:23 -06:00
|
|
|
#endif //ARC_DEFAULT_CONFIG
|