C++ preprocessor type constuctor for processing structured (JSON) configuration files.
Describe the info about options you need:
CONSTRUCT_CONFIG(
myconfig, // the name of the generated type(struct)
(int, a) // the sequence of the variables
(double, b)
)
For read the options from file:
myconfig cfg = myconfig::read("myconfig.cfg");
For write the options to file:
myconfig cfg;
cfg.a = 33;
cfg.b = 44.55;
myconfig::write("myconfig.cfg", cfg);
As members now you can use nested config-ctor types:
CONSTRUCT_CONFIG(
option,
(int, i)
(std::string, s)
)
CONSTRUCT_CONFIG(
myconfig, // the name of the generated type(struct)
(int, a) // the sequence of the variables
(double, b)
(option, o) // <<<<<<<<<<<<<<<<<<<<<<
)
You can specify the default values for options. To do this, specify the third parameter for that variable:
CONSTRUCT_CONFIG(
myconfig, // the name of the generated type(struct)
(int, a, 33) // the sequence of the variables
(double, b, 44.55)
)
Also you can use placeholders in your config files.
For example, this(stat_log={HOME}/procs/{PID}/stat.log
) line in config file will be readed as stat_log=/home/nixman/procs/18151/stat.log
The following placeholders are supported:
{USER} // user name
{HOME} // user home path
{CWD} // current path
{TEMP} // user temp path
{PID} // process ID
{PATH} // PATH env
{PROC} // executable path
{GETENV(ENV_VAR)} // gets the system env var value. also you can use it with default value: {GETENV(ENV_VAR, defaul_value)}