|
typedef struct M_conf_t | M_conf_t |
|
typedef void(* | M_conf_logger_t) (const char *path, const char *msg) |
|
typedef M_bool(* | M_conf_converter_buf_t) (char *buf, size_t buf_len, const char *value, const char *default_val) |
|
typedef M_bool(* | M_conf_converter_strdup_t) (char **mem, const char *value, const char *default_val) |
|
typedef M_bool(* | M_conf_converter_int8_t) (M_int8 *mem, const char *value, M_int8 default_val) |
|
typedef M_bool(* | M_conf_converter_int16_t) (M_int16 *mem, const char *value, M_int16 default_val) |
|
typedef M_bool(* | M_conf_converter_int32_t) (M_int32 *mem, const char *value, M_int32 default_val) |
|
typedef M_bool(* | M_conf_converter_int64_t) (M_int64 *mem, const char *value, M_int64 default_val) |
|
typedef M_bool(* | M_conf_converter_uint8_t) (M_uint8 *mem, const char *value, M_uint8 default_val) |
|
typedef M_bool(* | M_conf_converter_uint16_t) (M_uint16 *mem, const char *value, M_uint16 default_val) |
|
typedef M_bool(* | M_conf_converter_uint32_t) (M_uint32 *mem, const char *value, M_uint32 default_val) |
|
typedef M_bool(* | M_conf_converter_uint64_t) (M_uint64 *mem, const char *value, M_uint64 default_val) |
|
typedef M_bool(* | M_conf_converter_sizet_t) (size_t *mem, const char *value, size_t default_val) |
|
typedef M_bool(* | M_conf_converter_bool_t) (M_bool *mem, const char *value, M_bool default_val) |
|
typedef M_bool(* | M_conf_converter_custom_t) (void *mem, const char *value) |
|
typedef M_bool(* | M_conf_validator_t) (void *data) |
|
|
M_conf_t * | M_conf_create (const char *path, M_bool allow_multiple, char *errbuf, size_t errbuf_len) |
|
void | M_conf_destroy (M_conf_t *conf) |
|
M_bool | M_conf_add_debug_logger (M_conf_t *conf, M_conf_logger_t debug_logger) |
|
M_bool | M_conf_add_error_logger (M_conf_t *conf, M_conf_logger_t error_logger) |
|
M_bool | M_conf_parse (M_conf_t *conf) |
|
M_list_str_t * | M_conf_unused_keys (M_conf_t *conf) |
|
M_list_str_t * | M_conf_get_sections (M_conf_t *conf) |
|
const char * | M_conf_get_value (M_conf_t *conf, const char *key) |
|
M_list_str_t * | M_conf_get_values (M_conf_t *conf, const char *key) |
|
M_bool | M_conf_register_buf (M_conf_t *conf, const char *key, char *buf, size_t buf_len, const char *default_val, const char *regex, M_conf_converter_buf_t converter) |
|
M_bool | M_conf_register_strdup (M_conf_t *conf, const char *key, char **address, const char *default_val, const char *regex, M_conf_converter_strdup_t converter) |
|
M_bool | M_conf_register_int8 (M_conf_t *conf, const char *key, M_int8 *mem, M_int8 default_val, M_int8 min_val, M_int8 max_val, M_conf_converter_int8_t converter) |
|
M_bool | M_conf_register_int16 (M_conf_t *conf, const char *key, M_int16 *mem, M_int16 default_val, M_int16 min_val, M_int16 max_val, M_conf_converter_int16_t converter) |
|
M_bool | M_conf_register_int32 (M_conf_t *conf, const char *key, M_int32 *mem, M_int32 default_val, M_int32 min_val, M_int32 max_val, M_conf_converter_int32_t converter) |
|
M_bool | M_conf_register_int64 (M_conf_t *conf, const char *key, M_int64 *mem, M_int64 default_val, M_int64 min_val, M_int64 max_val, M_conf_converter_int64_t converter) |
|
M_bool | M_conf_register_uint8 (M_conf_t *conf, const char *key, M_uint8 *mem, M_uint8 default_val, M_uint8 min_val, M_uint8 max_val, M_conf_converter_uint8_t converter) |
|
M_bool | M_conf_register_uint16 (M_conf_t *conf, const char *key, M_uint16 *mem, M_uint16 default_val, M_uint16 min_val, M_uint16 max_val, M_conf_converter_uint16_t converter) |
|
M_bool | M_conf_register_uint32 (M_conf_t *conf, const char *key, M_uint32 *mem, M_uint32 default_val, M_uint32 min_val, M_uint32 max_val, M_conf_converter_uint32_t converter) |
|
M_bool | M_conf_register_uint64 (M_conf_t *conf, const char *key, M_uint64 *mem, M_uint64 default_val, M_uint64 min_val, M_uint64 max_val, M_conf_converter_uint64_t converter) |
|
M_bool | M_conf_register_sizet (M_conf_t *conf, const char *key, size_t *mem, size_t default_val, size_t min_val, size_t max_val, M_conf_converter_sizet_t converter) |
|
M_bool | M_conf_register_bool (M_conf_t *conf, const char *key, M_bool *mem, M_bool default_val, M_conf_converter_bool_t converter) |
|
M_bool | M_conf_register_custom (M_conf_t *conf, const char *key, void *mem, M_conf_converter_custom_t converter) |
|
M_bool | M_conf_register_validator (M_conf_t *conf, M_conf_validator_t validator, void *data) |
|
Wrapper around mstdlib's INI module for parsing configuration files and saving values. The file must be formatted as described in the INI module. This does not cover other file formats, such as JSON or XML.
This module is used for reading values from a configuration file directly into the provided memory. If you want to hold the values in temporary memory for manipulation and retrieval, you should use the Settings module.
You begin by building out all the key registrations, which specify the key to parse and where to store the value. There are multiple methods to handle the various data types that can be set. If you need to set a non-standardized data type like an enum or struct, you should use the custom registration method.
When building a key registration, you can also specify validators (depending on the data type) and a default value to use if a value isn't specified in the config file.
Every registration type has a corresponding conversion callback specific to it. If a callback is set with the registration, then that callback must do all the work of validating, converting, and storing the value.
Once all the registrations are set, you send the call to run through them all at once. We made the design decision to set everything up first and then parse the values over parsing on the fly as keys are registered so that all errors would be contained in one area. Instead of needing to do error checking for every registration, you only have to check the outcome of M_conf_parse().
Alternatively, you can access a key's value directly without setting up a registration.
To received debug and/or error messages, you can register a callback that will be provided the message as well as the filename of the file currently being processed. This is optional.
Example:
M_int8 num1;
M_uint32 num2;
static void log_conf_debug(const char *path, const char *msg)
{
M_printf(
"[DEBUG] %s: %s\n", path, msg);
}
static void log_conf_error(const char *path, const char *msg)
{
M_printf(
"[ERROR] %s: %s\n", path, msg);
}
static M_bool handle_num2(M_uint32 *mem, const char *value, M_uint32 default_val)
{
M_int64 num;
*mem = default_val;
return M_TRUE;
}
if (num < 0) {
*mem = 0;
} else if (num > 64) {
*mem = 64;
} else {
*mem = num;
}
return M_TRUE;
}
static M_bool handle_flags(void *mem, const char *value)
{
M_uint64 *flags = mem;
char **parts;
size_t num_parts;
size_t i;
*flags = 0;
if (parts == NULL)
return M_FALSE;
for (i=0; i<num_parts; i++) {
*flags |= parse_flag(parts[i]);
}
return M_TRUE;
}
static M_bool validate_data(void *data)
{
char *name_buf = data;
return M_FALSE;
}
if (num2 < num1) {
return M_FALSE;
}
return M_TRUE;
}
M_bool parse_conf(const char *path)
{
char err_buf[256];
char name_buf[256];
char *desc;
M_bool active;
M_uint64 flags;
M_bool ret;
if (conf == NULL) {
M_printf(
"Error reading conf: %s", err_buf);
return M_FALSE;
}
if (ret) {
} else {
}
return ret;
}
M_bool M_conf_parse(M_conf_t *conf)
M_bool M_conf_register_custom(M_conf_t *conf, const char *key, void *mem, M_conf_converter_custom_t converter)
M_bool M_conf_register_validator(M_conf_t *conf, M_conf_validator_t validator, void *data)
void M_conf_destroy(M_conf_t *conf)
M_bool M_conf_register_buf(M_conf_t *conf, const char *key, char *buf, size_t buf_len, const char *default_val, const char *regex, M_conf_converter_buf_t converter)
M_bool M_conf_add_error_logger(M_conf_t *conf, M_conf_logger_t error_logger)
M_conf_t * M_conf_create(const char *path, M_bool allow_multiple, char *errbuf, size_t errbuf_len)
M_bool M_conf_register_uint32(M_conf_t *conf, const char *key, M_uint32 *mem, M_uint32 default_val, M_uint32 min_val, M_uint32 max_val, M_conf_converter_uint32_t converter)
M_bool M_conf_register_strdup(M_conf_t *conf, const char *key, char **address, const char *default_val, const char *regex, M_conf_converter_strdup_t converter)
struct M_conf_t M_conf_t
Definition: m_conf.h:192
M_bool M_conf_add_debug_logger(M_conf_t *conf, M_conf_logger_t debug_logger)
M_bool M_conf_register_bool(M_conf_t *conf, const char *key, M_bool *mem, M_bool default_val, M_conf_converter_bool_t converter)
M_bool M_conf_register_int8(M_conf_t *conf, const char *key, M_int8 *mem, M_int8 default_val, M_int8 min_val, M_int8 max_val, M_conf_converter_int8_t converter)
ssize_t M_printf(const char *fmt,...)
M_bool M_str_isempty(const char *s) M_WARN_UNUSED_RESULT
size_t M_str_len(const char *s) M_WARN_UNUSED_RESULT
M_int64 M_str_to_int64(const char *s) M_WARN_UNUSED_RESULT
void M_str_explode_free(char **strs, size_t num) M_FREE(1)
char ** M_str_explode_str(unsigned char delim, const char *s, size_t *num) M_WARN_UNUSED_RESULT M_MALLOC
◆ M_conf_t
◆ M_conf_logger_t
typedef void(* M_conf_logger_t) (const char *path, const char *msg) |
Callback prototype for logging messages while parsing values.
- Parameters
-
[in] | path | Path of configuration file being read. |
[in] | msg | Message to log. |
◆ M_conf_converter_buf_t
typedef M_bool(* M_conf_converter_buf_t) (char *buf, size_t buf_len, const char *value, const char *default_val) |
Callback prototype for manual string-to-string conversions.
- Parameters
-
[in] | buf | Buffer to store the value. |
[in] | buf_len | Length of buffer. |
[in] | value | The value in the configuration file for the registered key. May be NULL. |
[in] | default_val | The default value as registered for the key. |
- Returns
- M_TRUE if the conversion was successful. Otherwise, M_FALSE.
◆ M_conf_converter_strdup_t
typedef M_bool(* M_conf_converter_strdup_t) (char **mem, const char *value, const char *default_val) |
Callback prototype for manual string-to-string conversions.
- Parameters
-
[in] | mem | Memory address where the value should be stored. The caller is responsible for free'ing this. |
[in] | value | The value in the configuration file for the registered key. May be NULL. |
[in] | default_val | The default value as registered for the key. |
- Returns
- M_TRUE if the conversion was successful. Otherwise, M_FALSE.
◆ M_conf_converter_int8_t
typedef M_bool(* M_conf_converter_int8_t) (M_int8 *mem, const char *value, M_int8 default_val) |
Callback prototype for manual string-to-integer conversions for signed 8-bit integers.
- Parameters
-
[in] | mem | Memory address where the value should be stored. |
[in] | value | The value in the configuration file for the registered key. May be NULL. |
[in] | default_val | The default value as registered for the key. |
- Returns
- M_TRUE if the conversion was successful. Otherwise, M_FALSE.
◆ M_conf_converter_int16_t
typedef M_bool(* M_conf_converter_int16_t) (M_int16 *mem, const char *value, M_int16 default_val) |
Callback prototype for manual string-to-integer conversions for signed 16-bit integers.
- Parameters
-
[in] | mem | Memory address where the value should be stored. |
[in] | value | The value in the configuration file for the registered key. May be NULL. |
[in] | default_val | The default value as registered for the key. |
- Returns
- M_TRUE if the conversion was successful. Otherwise, M_FALSE.
◆ M_conf_converter_int32_t
typedef M_bool(* M_conf_converter_int32_t) (M_int32 *mem, const char *value, M_int32 default_val) |
Callback prototype for manual string-to-integer conversions for signed 32-bit integers.
- Parameters
-
[in] | mem | Memory address where the value should be stored. |
[in] | value | The value in the configuration file for the registered key. May be NULL. |
[in] | default_val | The default value as registered for the key. |
- Returns
- M_TRUE if the conversion was successful. Otherwise, M_FALSE.
◆ M_conf_converter_int64_t
typedef M_bool(* M_conf_converter_int64_t) (M_int64 *mem, const char *value, M_int64 default_val) |
Callback prototype for manual string-to-integer conversions for signed 64-bit integers.
- Parameters
-
[in] | mem | Memory address where the value should be stored. |
[in] | value | The value in the configuration file for the registered key. May be NULL. |
[in] | default_val | The default value as registered for the key. |
- Returns
- M_TRUE if the conversion was successful. Otherwise, M_FALSE.
◆ M_conf_converter_uint8_t
typedef M_bool(* M_conf_converter_uint8_t) (M_uint8 *mem, const char *value, M_uint8 default_val) |
Callback prototype for manual string-to-integer conversions for unsigned 8-bit integers.
- Parameters
-
[in] | mem | Memory address where the value should be stored. |
[in] | value | The value in the configuration file for the registered key. May be NULL. |
[in] | default_val | The default value as registered for the key. |
- Returns
- M_TRUE if the conversion was successful. Otherwise, M_FALSE.
◆ M_conf_converter_uint16_t
typedef M_bool(* M_conf_converter_uint16_t) (M_uint16 *mem, const char *value, M_uint16 default_val) |
Callback prototype for manual string-to-integer conversions for unsigned 16-bit integers.
- Parameters
-
[in] | mem | Memory address where the value should be stored. |
[in] | value | The value in the configuration file for the registered key. May be NULL. |
[in] | default_val | The default value as registered for the key. |
- Returns
- M_TRUE if the conversion was successful. Otherwise, M_FALSE.
◆ M_conf_converter_uint32_t
typedef M_bool(* M_conf_converter_uint32_t) (M_uint32 *mem, const char *value, M_uint32 default_val) |
Callback prototype for manual string-to-integer conversions for unsigned 32-bit integers.
- Parameters
-
[in] | mem | Memory address where the value should be stored. |
[in] | value | The value in the configuration file for the registered key. May be NULL. |
[in] | default_val | The default value as registered for the key. |
- Returns
- M_TRUE if the conversion was successful. Otherwise, M_FALSE.
◆ M_conf_converter_uint64_t
typedef M_bool(* M_conf_converter_uint64_t) (M_uint64 *mem, const char *value, M_uint64 default_val) |
Callback prototype for manual string-to-integer conversions for unsigned 64-bit integers.
- Parameters
-
[in] | mem | Memory address where the value should be stored. |
[in] | value | The value in the configuration file for the registered key. May be NULL. |
[in] | default_val | The default value as registered for the key. |
- Returns
- M_TRUE if the conversion was successful. Otherwise, M_FALSE.
◆ M_conf_converter_sizet_t
typedef M_bool(* M_conf_converter_sizet_t) (size_t *mem, const char *value, size_t default_val) |
Callback prototype for manual string-to-integer conversions for size_t integers.
- Parameters
-
[in] | mem | Memory address where the value should be stored. |
[in] | value | The value in the configuration file for the registered key. May be NULL. |
[in] | default_val | The default value as registered for the key. |
- Returns
- M_TRUE if the conversion was successful. Otherwise, M_FALSE.
◆ M_conf_converter_bool_t
typedef M_bool(* M_conf_converter_bool_t) (M_bool *mem, const char *value, M_bool default_val) |
Callback prototype for manual string-to-boolean conversions.
- Parameters
-
[in] | mem | Memory address where the value should be stored. |
[in] | value | The value in the configuration file for the registered key. May be NULL. |
[in] | default_val | The default value as registered for the key. |
- Returns
- M_TRUE if the conversion was successful. Otherwise, M_FALSE.
◆ M_conf_converter_custom_t
typedef M_bool(* M_conf_converter_custom_t) (void *mem, const char *value) |
Callback prototype for custom conversions. This is used for manually validating and setting a value with M_conf_register_custom();
- Parameters
-
[in] | mem | Memory address where the value should be stored. May be NULL if address was not registered. |
[in] | value | The value in the configuration file for the registered key. May be NULL. |
- Returns
- M_TRUE if the conversion was successful. Otherwise, M_FALSE.
◆ M_conf_validator_t
typedef M_bool(* M_conf_validator_t) (void *data) |
Callback prototype for validating arbitrary data.
- Parameters
-
[in] | data | Arbitrary data, as registered with the callback. May be NULL. |
- Returns
- M_TRUE if the validation was successful. Otherwise, M_FALSE.
◆ M_conf_create()
M_conf_t * M_conf_create |
( |
const char * |
path, |
|
|
M_bool |
allow_multiple, |
|
|
char * |
errbuf, |
|
|
size_t |
errbuf_len |
|
) |
| |
Create a new M_conf_t object with the specified ini.
- Parameters
-
[in] | path | Path to the ini file. |
[in] | allow_multiple | M_TRUE to allow a single key to have multiple values. Otherwise, M_FALSE. |
[in] | errbuf | Buffer to hold error message. Only populated if return is NULL. |
[in] | errbuf_len | Size of buffer for holding error message. |
- Returns
- A newly allocated M_conf_t object, or NULL on error.
◆ M_conf_destroy()
Destroy an M_conf_t object and free the memory.
Before destruction, all unused keys will be logged with the debug loggers (if any).
- Parameters
-
[in] | conf | The M_conf_t object to destroy. |
◆ M_conf_add_debug_logger()
Add a debug logger to this conf object that will be passed various debug messages while parsing the values.
- Parameters
-
[in] | conf | The M_conf_t object to attach this logger to. |
[in] | debug_logger | The logging callback that will receive the error message. |
◆ M_conf_add_error_logger()
Add an error logger to this conf object that will be passed any errors that happen while parsing the values.
- Parameters
-
[in] | conf | The M_conf_t object to attach this logger to. |
[in] | error_logger | The logging callback that will receive the error message. |
◆ M_conf_parse()
Go through the key registrations and set the values at the specified locations.
- Parameters
-
[in] | conf | The M_conf_t object to use. |
- Returns
- M_TRUE if the registrations were processed successfully. Otherwise, M_FALSE. This fails if any of the registrations fail, like if a value does not pass the regex check or is outside of the min/max bounds.
◆ M_conf_unused_keys()
Get a list of keys from the ini file that were not used.
- Parameters
-
[in] | conf | The M_conf_t object to use. |
- Returns
- A list of keys.
◆ M_conf_get_sections()
Get a list of the section in the ini file.
- Parameters
-
[in] | conf | The M_conf_t object to use. |
- Returns
- A list of sections.
◆ M_conf_get_value()
const char * M_conf_get_value |
( |
M_conf_t * |
conf, |
|
|
const char * |
key |
|
) |
| |
Get the value for the provided key in the ini file. If a single key is allowed to have multiple values, then this returns the first value.
- Parameters
-
[in] | conf | The M_conf_t object to use. |
[in] | key | The key to look up. |
- Returns
- The value for the key.
◆ M_conf_get_values()
Get all the values for the provided key in the ini file.
- Parameters
-
[in] | conf | The M_conf_t object to use. |
[in] | key | The key to look up. |
- Returns
- A list of values for the key.
◆ M_conf_register_buf()
M_bool M_conf_register_buf |
( |
M_conf_t * |
conf, |
|
|
const char * |
key, |
|
|
char * |
buf, |
|
|
size_t |
buf_len, |
|
|
const char * |
default_val, |
|
|
const char * |
regex, |
|
|
M_conf_converter_buf_t |
converter |
|
) |
| |
Register a key that will have its value stored in the provided char buf.
- Parameters
-
[in] | conf | M_conf_t object to use. |
[in] | key | Key to register. |
[out] | buf | Buffer where the value will be stored. |
[in] | buf_len | Length of buffer. |
[in] | default_val | Default value to store, if a value is not set in the ini file. Pass NULL for no default. |
[in] | regex | Regular expression to check the value against. Matching is done in a case-insensitive fashion. If the check fails, then M_conf_parse() will also fail and the default value will be stored. Pass NULL to skip check. |
[in] | converter | Callback for manual conversion. The value will be pulled out of the ini and passed directly to the callback, which must do all validation/conversion. The value passed to the callback can be NULL. Pass NULL if not needed. |
- Returns
- M_TRUE if the registration was successful. Otherwise, M_FALSE. Currently, this returns M_FALSE only if any of the arguments are invalid.
◆ M_conf_register_strdup()
M_bool M_conf_register_strdup |
( |
M_conf_t * |
conf, |
|
|
const char * |
key, |
|
|
char ** |
address, |
|
|
const char * |
default_val, |
|
|
const char * |
regex, |
|
|
M_conf_converter_strdup_t |
converter |
|
) |
| |
Register a key that will have its value stored at the provided address as an allocated string.
- Parameters
-
[in] | conf | M_conf_t object to use. |
[in] | key | Key to register. |
[out] | address | Address where the value will be stored. The caller is responsible for free'ing this memory. |
[in] | default_val | Default value to store, if a value is not set in the ini file. Pass NULL for no default. |
[in] | regex | Regular expression to check the value against. Matching is done in a case-insensitive fashion. If the check fails, then M_conf_parse() will also fail and the default value will be stored. Pass NULL to skip check. |
[in] | converter | Callback for manual conversion. The value will be pulled out of the ini and passed directly to the callback, which must do all validation/conversion. The value passed to the callback can be NULL. Pass NULL if not needed. |
- Returns
- M_TRUE if the registration was successful. Otherwise, M_FALSE. Currently, this returns M_FALSE only if any of the arguments are invalid.
◆ M_conf_register_int8()
M_bool M_conf_register_int8 |
( |
M_conf_t * |
conf, |
|
|
const char * |
key, |
|
|
M_int8 * |
mem, |
|
|
M_int8 |
default_val, |
|
|
M_int8 |
min_val, |
|
|
M_int8 |
max_val, |
|
|
M_conf_converter_int8_t |
converter |
|
) |
| |
Register a key that will have its value stored at the provided address as a signed 8-bit integer.
- Parameters
-
[in] | conf | M_conf_t object to use. |
[in] | key | Key to register. |
[out] | mem | Memory where the value will be stored. |
[in] | default_val | Default value to store, if a value is not set in the ini file. |
[in] | min_val | Minimum allowed value. A value in the ini file less than this will cause M_conf_parse() to fail and the default value to be stored. |
[in] | max_val | Maximum allowed value. A value in the ini file greater than this will cause M_conf_parse() to fail and the default value to be stored. |
[in] | converter | Callback for manual conversion. The value will be pulled out of the ini and passed directly to the callback, which must do all validation/conversion. The value passed to the callback can be NULL. Pass NULL if not needed. |
- Returns
- M_TRUE if the registration was successful. Otherwise, M_FALSE. Currently, this returns M_FALSE only if any of the arguments are invalid.
◆ M_conf_register_int16()
M_bool M_conf_register_int16 |
( |
M_conf_t * |
conf, |
|
|
const char * |
key, |
|
|
M_int16 * |
mem, |
|
|
M_int16 |
default_val, |
|
|
M_int16 |
min_val, |
|
|
M_int16 |
max_val, |
|
|
M_conf_converter_int16_t |
converter |
|
) |
| |
Register a key that will have its value stored at the provided address as a signed 16-bit integer.
- Parameters
-
[in] | conf | M_conf_t object to use. |
[in] | key | Key to register. |
[out] | mem | Memory where the value will be stored. |
[in] | default_val | Default value to store, if a value is not set in the ini file. |
[in] | min_val | Minimum allowed value. A value in the ini file less than this will cause M_conf_parse() to fail and the default value to be stored. |
[in] | max_val | Maximum allowed value. A value in the ini file greater than this will cause M_conf_parse() to fail and the default value to be stored. |
[in] | converter | Callback for manual conversion. The value will be pulled out of the ini and passed directly to the callback, which must do all validation/conversion. The value passed to the callback can be NULL. Pass NULL if not needed. |
- Returns
- M_TRUE if the registration was successful. Otherwise, M_FALSE. Currently, this returns M_FALSE only if any of the arguments are invalid.
◆ M_conf_register_int32()
M_bool M_conf_register_int32 |
( |
M_conf_t * |
conf, |
|
|
const char * |
key, |
|
|
M_int32 * |
mem, |
|
|
M_int32 |
default_val, |
|
|
M_int32 |
min_val, |
|
|
M_int32 |
max_val, |
|
|
M_conf_converter_int32_t |
converter |
|
) |
| |
Register a key that will have its value stored at the provided address as a signed 32-bit integer.
- Parameters
-
[in] | conf | M_conf_t object to use. |
[in] | key | Key to register. |
[out] | mem | Memory where the value will be stored. |
[in] | default_val | Default value to store, if a value is not set in the ini file. |
[in] | min_val | Minimum allowed value. A value in the ini file less than this will cause M_conf_parse() to fail and the default value to be stored. |
[in] | max_val | Maximum allowed value. A value in the ini file greater than this will cause M_conf_parse() to fail and the default value to be stored. |
[in] | converter | Callback for manual conversion. The value will be pulled out of the ini and passed directly to the callback, which must do all validation/conversion. The value passed to the callback can be NULL. Pass NULL if not needed. |
- Returns
- M_TRUE if the registration was successful. Otherwise, M_FALSE. Currently, this returns M_FALSE only if any of the arguments are invalid.
◆ M_conf_register_int64()
M_bool M_conf_register_int64 |
( |
M_conf_t * |
conf, |
|
|
const char * |
key, |
|
|
M_int64 * |
mem, |
|
|
M_int64 |
default_val, |
|
|
M_int64 |
min_val, |
|
|
M_int64 |
max_val, |
|
|
M_conf_converter_int64_t |
converter |
|
) |
| |
Register a key that will have its value stored at the provided address as a signed 64-bit integer.
- Parameters
-
[in] | conf | M_conf_t object to use. |
[in] | key | Key to register. |
[out] | mem | Memory where the value will be stored. |
[in] | default_val | Default value to store, if a value is not set in the ini file. |
[in] | min_val | Minimum allowed value. A value in the ini file less than this will cause M_conf_parse() to fail and the default value to be stored. |
[in] | max_val | Maximum allowed value. A value in the ini file greater than this will cause M_conf_parse() to fail and the default value to be stored. |
[in] | converter | Callback for manual conversion. The value will be pulled out of the ini and passed directly to the callback, which must do all validation/conversion. The value passed to the callback can be NULL. Pass NULL if not needed. |
- Returns
- M_TRUE if the registration was successful. Otherwise, M_FALSE. Currently, this returns M_FALSE only if any of the arguments are invalid.
◆ M_conf_register_uint8()
M_bool M_conf_register_uint8 |
( |
M_conf_t * |
conf, |
|
|
const char * |
key, |
|
|
M_uint8 * |
mem, |
|
|
M_uint8 |
default_val, |
|
|
M_uint8 |
min_val, |
|
|
M_uint8 |
max_val, |
|
|
M_conf_converter_uint8_t |
converter |
|
) |
| |
Register a key that will have its value stored at the provided address as an unsigned 8-bit integer.
- Parameters
-
[in] | conf | M_conf_t object to use. |
[in] | key | Key to register. |
[out] | mem | Memory where the value will be stored. |
[in] | default_val | Default value to store, if a value is not set in the ini file. |
[in] | min_val | Minimum allowed value. A value in the ini file less than this will cause M_conf_parse() to fail and the default value to be stored. |
[in] | max_val | Maximum allowed value. A value in the ini file greater than this will cause M_conf_parse() to fail and the default value to be stored. |
[in] | converter | Callback for manual conversion. The value will be pulled out of the ini and passed directly to the callback, which must do all validation/conversion. The value passed to the callback can be NULL. Pass NULL if not needed. |
- Returns
- M_TRUE if the registration was successful. Otherwise, M_FALSE. Currently, this returns M_FALSE only if any of the arguments are invalid.
◆ M_conf_register_uint16()
M_bool M_conf_register_uint16 |
( |
M_conf_t * |
conf, |
|
|
const char * |
key, |
|
|
M_uint16 * |
mem, |
|
|
M_uint16 |
default_val, |
|
|
M_uint16 |
min_val, |
|
|
M_uint16 |
max_val, |
|
|
M_conf_converter_uint16_t |
converter |
|
) |
| |
Register a key that will have its value stored at the provided address as an unsigned 16-bit integer.
- Parameters
-
[in] | conf | M_conf_t object to use. |
[in] | key | Key to register. |
[out] | mem | Memory where the value will be stored. |
[in] | default_val | Default value to store, if a value is not set in the ini file. |
[in] | min_val | Minimum allowed value. A value in the ini file less than this will cause M_conf_parse() to fail and the default value to be stored. |
[in] | max_val | Maximum allowed value. A value in the ini file greater than this will cause M_conf_parse() to fail and the default value to be stored. |
[in] | converter | Callback for manual conversion. The value will be pulled out of the ini and passed directly to the callback, which must do all validation/conversion. The value passed to the callback can be NULL. Pass NULL if not needed. |
- Returns
- M_TRUE if the registration was successful. Otherwise, M_FALSE. Currently, this returns M_FALSE only if any of the arguments are invalid.
◆ M_conf_register_uint32()
M_bool M_conf_register_uint32 |
( |
M_conf_t * |
conf, |
|
|
const char * |
key, |
|
|
M_uint32 * |
mem, |
|
|
M_uint32 |
default_val, |
|
|
M_uint32 |
min_val, |
|
|
M_uint32 |
max_val, |
|
|
M_conf_converter_uint32_t |
converter |
|
) |
| |
Register a key that will have its value stored at the provided address as an unsigned 32-bit integer.
- Parameters
-
[in] | conf | M_conf_t object to use. |
[in] | key | Key to register. |
[out] | mem | Memory where the value will be stored. |
[in] | default_val | Default value to store, if a value is not set in the ini file. |
[in] | min_val | Minimum allowed value. A value in the ini file less than this will cause M_conf_parse() to fail and the default value to be stored. |
[in] | max_val | Maximum allowed value. A value in the ini file greater than this will cause M_conf_parse() to fail and the default value to be stored. |
[in] | converter | Callback for manual conversion. The value will be pulled out of the ini and passed directly to the callback, which must do all validation/conversion. The value passed to the callback can be NULL. Pass NULL if not needed. |
- Returns
- M_TRUE if the registration was successful. Otherwise, M_FALSE. Currently, this returns M_FALSE only if any of the arguments are invalid.
◆ M_conf_register_uint64()
M_bool M_conf_register_uint64 |
( |
M_conf_t * |
conf, |
|
|
const char * |
key, |
|
|
M_uint64 * |
mem, |
|
|
M_uint64 |
default_val, |
|
|
M_uint64 |
min_val, |
|
|
M_uint64 |
max_val, |
|
|
M_conf_converter_uint64_t |
converter |
|
) |
| |
Register a key that will have its value stored at the provided address as an unsigned 64-bit integer.
- Parameters
-
[in] | conf | M_conf_t object to use. |
[in] | key | Key to register. |
[out] | mem | Memory where the value will be stored. |
[in] | default_val | Default value to store, if a value is not set in the ini file. |
[in] | min_val | Minimum allowed value. A value in the ini file less than this will cause M_conf_parse() to fail and the default value to be stored. |
[in] | max_val | Maximum allowed value. A value in the ini file greater than this will cause M_conf_parse() to fail and the default value to be stored. |
[in] | converter | Callback for manual conversion. The value will be pulled out of the ini and passed directly to the callback, which must do all validation/conversion. The value passed to the callback can be NULL. Pass NULL if not needed. |
- Returns
- M_TRUE if the registration was successful. Otherwise, M_FALSE. Currently, this returns M_FALSE only if any of the arguments are invalid.
◆ M_conf_register_sizet()
M_bool M_conf_register_sizet |
( |
M_conf_t * |
conf, |
|
|
const char * |
key, |
|
|
size_t * |
mem, |
|
|
size_t |
default_val, |
|
|
size_t |
min_val, |
|
|
size_t |
max_val, |
|
|
M_conf_converter_sizet_t |
converter |
|
) |
| |
Register a key that will have its value stored at the provided address as a size_t integer.
- Parameters
-
[in] | conf | M_conf_t object to use. |
[in] | key | Key to register. |
[out] | mem | Memory where the value will be stored. |
[in] | default_val | Default value to store, if a value is not set in the ini file. |
[in] | min_val | Minimum allowed value. A value in the ini file less than this will cause M_conf_parse() to fail and the default value to be stored. |
[in] | max_val | Maximum allowed value. A value in the ini file greater than this will cause M_conf_parse() to fail and the default value to be stored. |
[in] | converter | Callback for manual conversion. The value will be pulled out of the ini and passed directly to the callback, which must do all validation/conversion. The value passed to the callback can be NULL. Pass NULL if not needed. |
- Returns
- M_TRUE if the registration was successful. Otherwise, M_FALSE. Currently, this returns M_FALSE only if any of the arguments are invalid.
◆ M_conf_register_bool()
Register a key that will have its value parsed for boolean truthfulness and stored at the provided address.
- Parameters
-
[in] | conf | M_conf_t object to use. |
[in] | key | Key to register. |
[out] | mem | Memory where the value will be stored. |
[in] | default_val | Default value to store, if a value is not set in the ini file. |
[in] | converter | Callback for manual conversion. The value will be pulled out of the ini and passed directly to the callback, which must do all validation/conversion. The value passed to the callback can be NULL. Pass NULL if not needed. |
- Returns
- M_TRUE if the registration was successful. Otherwise, M_FALSE. Currently, this returns M_FALSE only if any of the arguments are invalid.
◆ M_conf_register_custom()
Register a key that will have its value manually validated and converted. This passes the value straight to the converter callback and does not do any validation or conversion internally.
- Parameters
-
[in] | conf | M_conf_t object to use. |
[in] | key | Key to register. |
[out] | mem | Memory where the value will be stored. Pass NULL if not needed. |
[in] | converter | Callback for manual conversion. The value will be pulled out of the ini and passed directly to the callback, which must do all validation/conversion. The value passed to the callback can be NULL. This must be used. |
- Returns
- M_TRUE if the registration was successful. Otherwise, M_FALSE. Currently, this returns M_FALSE only if any of the arguments are invalid.
◆ M_conf_register_validator()
Register a validation callback. All registered validators are called after M_conf_parse() sets the registered keys. This can be used, for example, if you want to validate that one key's value is greater than another key's value, or if you want to print a debug statement for a certain key or keys. This can also be used to run a hook after the registrations are set.
- Parameters
-
[in] | conf | M_conf_t object to use. |
[in] | validator | Callback for validating stored values. |
[in] | data | Reference for passing in data in the callback. May be NULL if not needed. |
- Returns
- M_TRUE if the registration was successful. Otherwise, M_FALSE. Currently, this returns M_FALSE only if the callback is invalid.