#ifndef ARC_STD_CONFIG_H_ #define ARC_STD_CONFIG_H_ #ifdef __cplusplus extern "C" { #endif #include "arc/std/parser.h" #include /** * @brief the config type for archeus, loads in a .chemical file which syntax is specified in the documentation */ typedef struct ARC_Config ARC_Config; /** * @brief a function callback to create a type stored within a config * * @param[out] type the place to store the type copy, should be set to NULL on error * @param[in] parsedData the parsed data used to copy from. will be as defined in the language * @param[in] config the config that is reading in the data, can be used within the copy function to add a new type (check ARC_ConfigType_SpriteCopyFn for an example) * @param[in] userdata userdata that was stored in the type during type register */ typedef void (* ARC_ConfigType_CopyFn)(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata); /** * @brief a function callback to destroy a type * * @param[in] config the config that is destroying the data, can be used within the destroy function to remove a previously added tag (check ARC_ConfigType_SpriteDestroyFn for an example) * @param[in] type the type to be destroyed */ typedef void (* ARC_ConfigType_DestroyFn)(ARC_Config *config, void *type); /** * @brief the functions for used for loading and unloading a type, the name will be the key of a hashtable */ typedef struct ARC_ConfigType { uint32_t size; ARC_ConfigType_CopyFn copyFn; ARC_ConfigType_DestroyFn destroyFn; void *userdata; } ARC_ConfigType; /** * @brief creates the arc config type (a type that loads in config files and can have types added to it) * * @param[out] ARC_Config to create */ void ARC_Config_Create(ARC_Config **config); /** * @brief destroys an ARC_Config type * * @param[in] config ARC_Config to destroy */ 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 add a value with a given keyname * * @note name should be prefaced with :: to specify group, or just the name if it is in the default group * @note not specifying the group will use the current group * @note this function uses ARC_Config_AddWithCStr so it shares error messages with that function * @note value will be freed on cleanup or remove * * @param[in] config ARC_Config to add value to * @param[in] type the type of a variable to add to specified group * @param[in] name name of a variable to add to specified group * @param[in] value the value of the variable to add, will be freed */ void ARC_Config_Add(ARC_Config *config, ARC_String *type, ARC_String *name, void *value); /** * @brief add a value with a given keyname * * @note name should be prefaced with :: to specify group, or just the name if it is in the default group * @note not specifying the group will use the current group * @note value will be freed on cleanup or remove * * @param[in] config ARC_Config to add value to * @param[in] type the type of a variable to add to specified group * @param[in] name name of a variable to add to specified group * @param[in] value the value of the variable to add, will be freed */ void ARC_Config_AddWithCStr(ARC_Config *config, const char *type, const char *name, void *value); /** * @brief remove a value with a given keyname * * @note name should be prefaced with :: to specify group, or just the name if it is in the default group * @note not specifying the group will use the current group * @note this function uses ARC_Config_RemoveWithCStr so it shares error messages with that function * * @param[in] config ARC_Config to remove value from * @param[in] name name of a variable to remove to specified group * @param[in] isArray a boolean to specify if the variable is an array */ void ARC_Config_Remove(ARC_Config *config, ARC_String *name, ARC_Bool isArray); /** * @brief remove a value with a given keyname * * @note name should be prefaced with :: to specify group, or just the name if it is in the default group * @note not specifying the group will use the current group * * @param[in] config ARC_Config to remove value from * @param[in] name name of a variable to remove to specified group * @param[in] isArray a boolean to specify if the variable is an array */ void ARC_Config_RemoveWithCStr(ARC_Config *config, const char *name, ARC_Bool isArray); /** * @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[in] config ARC_Config we are setting current group in * @param[in] groupname name of group that will be set */ void ARC_Config_SetGroupWithCStr(ARC_Config *config, const char *groupName); /** * @brief get a value from a given name * * @note name should be prefaced with :: to specify group, or just the name if it is in the default 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 should be prefaced with :: to specify group, or just the name if it is in the default group * @note this function uses ARC_Config_Get so it shares error messages with that function * * @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_GetWithCStr(ARC_Config *config, const char *name); /** * @brief takes a given string and loads it into the config * * @breif config the config to load the string to * @breif string the string to load into the config */ void ARC_Config_LoadFromString(ARC_Config *config, ARC_String **string); /** * @brief takes a given file path and loads it into the config * * @note this path will be based on wherever the executable is run from * * @breif config the config to load the file to * @breif path the location of the .chemical file to load */ void ARC_Config_LoadFromFile(ARC_Config *config, ARC_String *path); /** * @brief takes a given file path and loads it into the config * * @note this path will be based on wherever the executable is run from * * @breif config the config to load the file to * @breif path the location of the .chemical file to load */ void ARC_Config_LoadFromFileWithCStr(ARC_Config *config, const char *path); /** * @brief takes a given file path and unloads it into the config * * @note this path will be based on wherever the executable is run from * * @breif config the config to unload the file from * @breif path the location of the .chemical file to unload */ void ARC_Config_UnloadFromString(ARC_Config *config, ARC_String **string); /** * @brief takes a given file path and unloads it into the config * * @note this path will be based on wherever the executable is run from * * @breif config the config to unload the file from * @breif path the location of the .chemical file to unload */ void ARC_Config_UnloadFromFile(ARC_Config *config, ARC_String *path); /** * @brief takes a given file path and unloads it into the config * * @note this path will be based on wherever the executable is run from * * @breif config the config to unload the file from * @breif path the location of the .chemical file to unload */ void ARC_Config_UnloadFromFileWithCStr(ARC_Config *config, const char *path); /** * @{ * @brief defaults used by arc config can be defined before building to change them */ #ifndef ARC_CONFIG_DEFAULT_GROUP #define ARC_CONFIG_DEFAULT_GROUP " " #endif #ifndef ARC_CONFIG_GROUP_TAG_NAME #define ARC_CONFIG_GROUP_TAG_NAME "group" #endif #ifndef ARC_CONFIG_GROUP_SEPARATOR #define ARC_CONFIG_GROUP_SEPARATOR "::" #endif /** * @} */ /** * @{ * @brief tokens used in the config langauge, defined here for use in ARC_ConfigType_CopyFn and ARC_ConfigType_DestroyFn * * @note 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_ARRAY 0x32 #define ARC_CONFIG_VARIABLE 0x33 #define ARC_CONFIG_VARIABLE_NAME 0x34 #define ARC_CONFIG_VARIABLE_CHAR 0x35 #define ARC_CONFIG_STRING 0x36 #define ARC_CONFIG_STRING_CHARS 0x37 #define ARC_CONFIG_STRING_CHAR 0x38 #define ARC_CONFIG_ESCAPE_CHAR 0x39 #define ARC_CONFIG_FLOAT 0x3A #define ARC_CONFIG_NUMBER_SIGN 0x3B #define ARC_CONFIG_NUMBER_TAG 0x3C #define ARC_CONFIG_WHITESPACE 0x3D #define ARC_CONFIG_COMMENT 0x3E #define ARC_CONFIG_LINE_COMMENT 0x3F #define ARC_CONFIG_MULTI_LINE_COMMENT 0x40 #define ARC_CONFIG_LINE_CHARS 0x41 #define ARC_CONFIG_MULTI_LINE_CHARS 0x42 #define ARC_CONFIG_COMMENT_CHAR 0x43 /** * @} */ /** * @brief inits a config type with the standard config settings * * @param config the config to init */ void ARC_Config_InitStd(ARC_Config *config); /** * @brief a function callback to create an ARC_Bool stored within a config * * @note this function is an ARC_ConfigType_CopyFn callback * * @param[out] type the place to store the type copy, should be set to NULL on error * @param[in] parsedData the parsed data used to copy from. will be as defined in the language * @param[in] config the config that is reading in the data, can be used within the copy function to add a new type (check ARC_ConfigType_SpriteCopyFn for an example) * @param[in] userdata userdata that was stored in the type during type register */ void ARC_ConfigType_BoolCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata); /** * @brief a function callback to destroy an ARC_Bool type * * @note this function is an ARC_ConfigType_DestroyFn callback * * @param[in] config the config that is destroying the data, can be used within the destroy function to remove a previously added tag (check ARC_ConfigType_SpriteDestroyFn for an example) * @param[in] type the type to be destroyed */ void ARC_ConfigType_BoolDestroyFn(ARC_Config *config, void *type); /** * @brief a function callback to create an int8_t stored within a config * * @note this function is an ARC_ConfigType_CopyFn callback * * @param[out] type the place to store the type copy, should be set to NULL on error * @param[in] parsedData the parsed data used to copy from. will be as defined in the language * @param[in] config the config that is reading in the data, can be used within the copy function to add a new type (check ARC_ConfigType_SpriteCopyFn for an example) * @param[in] userdata userdata that was stored in the type during type register */ void ARC_ConfigType_Int8CopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata); /** * @brief a function callback to destroy an int8_t type * * @note this function is an ARC_ConfigType_DestroyFn callback * * @param[in] config the config that is destroying the data, can be used within the destroy function to remove a previously added tag (check ARC_ConfigType_SpriteDestroyFn for an example) * @param[in] type the type to be destroyed */ void ARC_ConfigType_Int8DestroyFn(ARC_Config *config, void *type); /** * @brief a function callback to create an uint8_t stored within a config * * @note this function is an ARC_ConfigType_CopyFn callback * * @param[out] type the place to store the type copy, should be set to NULL on error * @param[in] parsedData the parsed data used to copy from. will be as defined in the language * @param[in] config the config that is reading in the data, can be used within the copy function to add a new type (check ARC_ConfigType_SpriteCopyFn for an example) * @param[in] userdata userdata that was stored in the type during type register */ void ARC_ConfigType_Uint8CopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata); /** * @brief a function callback to destroy an uint8_t type * * @note this function is an ARC_ConfigType_DestroyFn callback * * @param[in] config the config that is destroying the data, can be used within the destroy function to remove a previously added tag (check ARC_ConfigType_SpriteDestroyFn for an example) * @param[in] type the type to be destroyed */ void ARC_ConfigType_Uint8DestroyFn(ARC_Config *config, void *type); /** * @brief a function callback to create an int16_t stored within a config * * @note this function is an ARC_ConfigType_CopyFn callback * * @param[out] type the place to store the type copy, should be set to NULL on error * @param[in] parsedData the parsed data used to copy from. will be as defined in the language * @param[in] config the config that is reading in the data, can be used within the copy function to add a new type (check ARC_ConfigType_SpriteCopyFn for an example) * @param[in] userdata userdata that was stored in the type during type register */ void ARC_ConfigType_Int16CopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata); /** * @brief a function callback to destroy an int16_t type * * @note this function is an ARC_ConfigType_DestroyFn callback * * @param[in] config the config that is destroying the data, can be used within the destroy function to remove a previously added tag (check ARC_ConfigType_SpriteDestroyFn for an example) * @param[in] type the type to be destroyed */ void ARC_ConfigType_Int16DestroyFn(ARC_Config *config, void *type); /** * @brief a function callback to create an uint16_t stored within a config * * @note this function is an ARC_ConfigType_CopyFn callback * * @param[out] type the place to store the type copy, should be set to NULL on error * @param[in] parsedData the parsed data used to copy from. will be as defined in the language * @param[in] config the config that is reading in the data, can be used within the copy function to add a new type (check ARC_ConfigType_SpriteCopyFn for an example) * @param[in] userdata userdata that was stored in the type during type register */ void ARC_ConfigType_Uint16CopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata); /** * @brief a function callback to destroy an uint16_t type * * @note this function is an ARC_ConfigType_DestroyFn callback * * @param[in] config the config that is destroying the data, can be used within the destroy function to remove a previously added tag (check ARC_ConfigType_SpriteDestroyFn for an example) * @param[in] type the type to be destroyed */ void ARC_ConfigType_Uint16DestroyFn(ARC_Config *config, void *type); /** * @brief a function callback to create an int32_t stored within a config * * @note this function is an ARC_ConfigType_CopyFn callback * * @param[out] type the place to store the type copy, should be set to NULL on error * @param[in] parsedData the parsed data used to copy from. will be as defined in the language * @param[in] config the config that is reading in the data, can be used within the copy function to add a new type (check ARC_ConfigType_SpriteCopyFn for an example) * @param[in] userdata userdata that was stored in the type during type register */ void ARC_ConfigType_Int32CopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata); /** * @brief a function callback to destroy an int32_t type * * @note this function is an ARC_ConfigType_DestroyFn callback * * @param[in] config the config that is destroying the data, can be used within the destroy function to remove a previously added tag (check ARC_ConfigType_SpriteDestroyFn for an example) * @param[in] type the type to be destroyed */ void ARC_ConfigType_Int32DestroyFn(ARC_Config *config, void *type); /** * @brief a function callback to create an uint32_t stored within a config * * @note this function is an ARC_ConfigType_CopyFn callback * * @param[out] type the place to store the type copy, should be set to NULL on error * @param[in] parsedData the parsed data used to copy from. will be as defined in the language * @param[in] config the config that is reading in the data, can be used within the copy function to add a new type (check ARC_ConfigType_SpriteCopyFn for an example) * @param[in] userdata userdata that was stored in the type during type register */ void ARC_ConfigType_Uint32CopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata); /** * @brief a function callback to destroy an uint32_t type * * @note this function is an ARC_ConfigType_DestroyFn callback * * @param[in] config the config that is destroying the data, can be used within the destroy function to remove a previously added tag (check ARC_ConfigType_SpriteDestroyFn for an example) * @param[in] type the type to be destroyed */ void ARC_ConfigType_Uint32DestroyFn(ARC_Config *config, void *type); /** * @brief a function callback to create an int64_t stored within a config * * @note this function is an ARC_ConfigType_CopyFn callback * * @param[out] type the place to store the type copy, should be set to NULL on error * @param[in] parsedData the parsed data used to copy from. will be as defined in the language * @param[in] config the config that is reading in the data, can be used within the copy function to add a new type (check ARC_ConfigType_SpriteCopyFn for an example) * @param[in] userdata userdata that was stored in the type during type register */ void ARC_ConfigType_Int64CopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata); /** * @brief a function callback to destroy an int64_t type * * @note this function is an ARC_ConfigType_DestroyFn callback * * @param[in] config the config that is destroying the data, can be used within the destroy function to remove a previously added tag (check ARC_ConfigType_SpriteDestroyFn for an example) * @param[in] type the type to be destroyed */ void ARC_ConfigType_Int64DestroyFn(ARC_Config *config, void *type); /** * @brief a function callback to create an uint64_t stored within a config * * @note this function is an ARC_ConfigType_CopyFn callback * * @param[out] type the place to store the type copy, should be set to NULL on error * @param[in] parsedData the parsed data used to copy from. will be as defined in the language * @param[in] config the config that is reading in the data, can be used within the copy function to add a new type (check ARC_ConfigType_SpriteCopyFn for an example) * @param[in] userdata userdata that was stored in the type during type register */ void ARC_ConfigType_Uint64CopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata); /** * @brief a function callback to destroy an uint64_t type * * @note this function is an ARC_ConfigType_DestroyFn callback * * @param[in] config the config that is destroying the data, can be used within the destroy function to remove a previously added tag (check ARC_ConfigType_SpriteDestroyFn for an example) * @param[in] type the type to be destroyed */ void ARC_ConfigType_Uint64DestroyFn(ARC_Config *config, void *type); /** * @brief a function callback to create a float stored within a config * * @note this function is an ARC_ConfigType_CopyFn callback * * @param[out] type the place to store the type copy, should be set to NULL on error * @param[in] parsedData the parsed data used to copy from. will be as defined in the language * @param[in] config the config that is reading in the data, can be used within the copy function to add a new type (check ARC_ConfigType_SpriteCopyFn for an example) * @param[in] userdata userdata that was stored in the type during type register */ void ARC_ConfigType_FloatCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata); /** * @brief a function callback to destroy a float type * * @note this function is an ARC_ConfigType_DestroyFn callback * * @param[in] config the config that is destroying the data, can be used within the destroy function to remove a previously added tag (check ARC_ConfigType_SpriteDestroyFn for an example) * @param[in] type the type to be destroyed */ void ARC_ConfigType_FloatDestroyFn(ARC_Config *config, void *type); /** * @brief a function callback to create a double stored within a config * * @note this function is an ARC_ConfigType_CopyFn callback * * @param[out] type the place to store the type copy, should be set to NULL on error * @param[in] parsedData the parsed data used to copy from. will be as defined in the language * @param[in] config the config that is reading in the data, can be used within the copy function to add a new type (check ARC_ConfigType_SpriteCopyFn for an example) * @param[in] userdata userdata that was stored in the type during type register */ void ARC_ConfigType_DoubleCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata); /** * @brief a function callback to destroy a double type * * @note this function is an ARC_ConfigType_DestroyFn callback * * @param[in] config the config that is destroying the data, can be used within the destroy function to remove a previously added tag (check ARC_ConfigType_SpriteDestroyFn for an example) * @param[in] type the type to be destroyed */ void ARC_ConfigType_DoubleDestroyFn(ARC_Config *config, void *type); /** * @brief a function callback to create an ARC_String stored within a config * * @note this function is an ARC_ConfigType_CopyFn callback * * @param[out] type the place to store the type copy, should be set to NULL on error * @param[in] parsedData the parsed data used to copy from. will be as defined in the language * @param[in] config the config that is reading in the data, can be used within the copy function to add a new type (check ARC_ConfigType_SpriteCopyFn for an example) * @param[in] userdata userdata that was stored in the type during type register */ void ARC_ConfigType_StringCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata); /** * @brief a function callback to destroy an ARC_String type * * @note this function is an ARC_ConfigType_DestroyFn callback * * @param[in] config the config that is destroying the data, can be used within the destroy function to remove a previously added tag (check ARC_ConfigType_SpriteDestroyFn for an example) * @param[in] type the type to be destroyed */ void ARC_ConfigType_StringDestroyFn(ARC_Config *config, void *type); #ifdef __cplusplus } #endif #endif // !ARC_STD_CONFIG_H_