#include <conf.h>
Data Fields | |
char * | var |
int | type |
char * | defval |
conf_t
represents an element of a configuration description table that is used for a user program to specify a set of sections and variable including their types and default values; a configuration table is the only way to specify types of variables as having other than CONF_TYPE_STR
(string type).
The var
member specifies a section/variable name. The string has one of the following two forms:
variable section . variable
where whitespaces are allowed before and/or after a section and variable name. The first form refers to a variable in the global section; there is no concept of the "current" section yet because conf_section() cannot be invoked before conf_preset() or conf_init(). To mark the end of a table, set the var
member to a null pointer.
The type
member specifies the type of a variable and should be one of CONF_TYPE_BOOL
(boolean value, int), CONF_TYPE_INT
(signed integer, long), CONF_TYPE_UINT
(unsigned integer, unsigned long), CONF_TYPE_REAL
(floating-point number, double), and CONF_TYPE_STR
(string, char *). Once a variable is set to have a type, there is no way to change its type; thus, if a variable is supposed to have various types depending on the context, set to CONF_TYPE_STR
and use conf_conv(). For OPT_TYPE_INT
and OPT_TYPE_UINT
, the conversion of a given value recognizes the C-style prefixes; numbers starting with 0 are treated as octal, and those with 0x or 0X are treated as hexadecimal.
The defval
member specifies a default value for a variable that is used when a configuration file dose not set that variable to a value. It cannot be a null pointer but an empty string. Note that conf_preset() that accepts a configuration description table does not check if a default value has a proper form for the type of a variable.
See the commented-out example code given in the source file for more about a configuration description table.
char* conf_t::defval |
default value
int conf_t::type |
type of variable
char* conf_t::var |
section name and variable name