Archeus 0.0.0
A C library and game engine that focuses on documentation
Loading...
Searching...
No Matches
config.h
Go to the documentation of this file.
1#ifndef ARC_STD_CONFIG_H_
2#define ARC_STD_CONFIG_H_
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8#include "arc/std/hashtable.h"
9#include "arc/std/string.h"
10#include <stdint.h>
11
12#define ARC_KEY_BUCKET_SIZE 0x20
13#define ARC_GROUP_BUCKET_SIZE 0x20
14#define ARC_GROUP_DATA_BUCKET_SIZE 0x20
15
16/**
17 * @brief a type that keeps permanice of data for when loading and unloading config files
18 */
19typedef struct ARC_Config ARC_Config;
20
21/**
22 * @brief a function to read a key from string to a ARC_ConfigTypeTemplate
23 *
24 * @param config ARC_Config to store data to
25 * @param string ARC_String of data that is being read in
26 * @param value value that is read in
27 *
28 * @note use ARC_Config_StoreValue(ARC_Config *config, ARC_String *name, void *value); to store a value to the config
29 * if there is an error, set arc_errno
30 *
31 * @return 0 if value not a reference, 1 if value is a reference
32 */
33typedef uint8_t (* ARC_ConfigKeyRead)(ARC_Config* config, ARC_String *string, void **value);
34
35/**
36 * @brief a function to delete a value from a key in ARC_Config
37 *
38 * @param config ARC_Config that can be used to check for references in data
39 * @param value pointer of data to be deleted
40 *
41 * @note this function can be NULL if memory does not need to be cleaned for this type
42 * if there is an error, set arc_errno
43 */
44typedef void (* ARC_ConfigKeyDelete)(ARC_Config* config, ARC_String *string, void *value);
45
46/**
47 * @brief adds a usable key to ARC_Config
48 *
49 * @param config ARC_Config to add keys to
50 * @param type string of key type
51 * @param keyRead function for reading/creating key from string
52 * @param keyDelete function for deleting stored key
53 */
55
56/**
57 * @brief adds a key from a cstring
58 * @param config ARC_Config to add keys to
59 * @param type cstring of key type
60 * @param length length of cstring
61 * @param keyRead function for reading/creating key from string
62 * @param keyDelete function for deleting stored key
63*/
64void ARC_Config_AddKeyCString(ARC_Config *config, const char *type, uint64_t length, ARC_ConfigKeyRead keyRead, ARC_ConfigKeyDelete keyDelete);
65
66/**
67 * @brief external callback to add keys to config
68 */
69typedef void (* ARC_ConfigKey_AddFunc)(ARC_Config *config);
70
71/**
72 * @brief creates ARC_Config type
73 *
74 * @param config ARC_Config to initialize
75 */
77
78/**
79 * @brief destroys ARC_Config type
80 */
82
83/**
84 * @brief sets current group in config
85 *
86 * @note ARC_Config_Get will use this set group
87 *
88 * @param config ARC_Config we are setting current group in
89 * @param groupname name of group that will be set
90 */
91void ARC_Config_SetGroup(ARC_Config *config, ARC_String *groupname);
92
93/**
94 * @brief get a value from a given keyname
95 *
96 * @note name may be prefaced with <group>:: to specify group
97 *
98 * @param config ARC_Config to get value from
99 * @param keyname name of key to get from config
100 * @param value data retrieved from config
101 */
102void ARC_Config_Get(ARC_Config *config, ARC_String *keyname, void **value);
103
104/**
105 * @brief commands that can be used in ARC_Config_FileIO
106 */
107#define ARC_CONFIG_FILE_IO_LOAD 0x00
108#define ARC_CONFIG_FILE_IO_UNLOAD 0x01
109
110/**
111 * @brief handles file io for ARC_Config Type
112 *
113 * @param config ARC_Config where io operations will take place
114 * @param path file path for io
115 */
116void ARC_Config_FileIO(ARC_Config *config, ARC_String *path, uint8_t command);
117
118#ifdef __cplusplus
119}
120#endif
121
122#endif //ARC_STD_CONFIG_H_
123
124#ifdef ARC_DEFAULT_CONFIG
125#include "defaults/config.h"
126#endif //ARC_DEFAULT_CONFIG
struct ARC_Config ARC_Config
a type that keeps permanice of data for when loading and unloading config files
Definition config.h:11
void ARC_Config_AddKeyCString(ARC_Config *config, const char *type, uint64_t length, ARC_ConfigKeyRead keyRead, ARC_ConfigKeyDelete keyDelete)
adds a key from a cstring
uint8_t(* ARC_ConfigKeyRead)(ARC_Config *config, ARC_String *string, void **value)
a function to read a key from string to a ARC_ConfigTypeTemplate
Definition config.h:33
void ARC_Config_Create(ARC_Config **config)
creates ARC_Config type
void ARC_Config_Get(ARC_Config *config, ARC_String *keyname, void **value)
get a value from a given keyname
void(* ARC_ConfigKey_AddFunc)(ARC_Config *config)
external callback to add keys to config
Definition config.h:69
void ARC_Config_SetGroup(ARC_Config *config, ARC_String *groupname)
sets current group in config
void ARC_Config_FileIO(ARC_Config *config, ARC_String *path, uint8_t command)
handles file io for ARC_Config Type
void ARC_Config_Destroy(ARC_Config *config)
destroys ARC_Config type
void(* ARC_ConfigKeyDelete)(ARC_Config *config, ARC_String *string, void *value)
a function to delete a value from a key in ARC_Config
Definition config.h:44
void ARC_Config_AddKey(ARC_Config *config, ARC_String *type, ARC_ConfigKeyRead keyRead, ARC_ConfigKeyDelete keyDelete)
adds a usable key to ARC_Config
substring position within a string
Definition string.h:14