Skip to content

C++ preprocessor type constuctor for processing structured (JSON) configuration files

License

Notifications You must be signed in to change notification settings

niXman/config-ctor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

90 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

config-ctor

C++ preprocessor type constuctor for processing structured (JSON) configuration files.

Tutorial

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);

Nested config-ctor types

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) // <<<<<<<<<<<<<<<<<<<<<<
)

Default values

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)
)

Placeholders

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)}

About

C++ preprocessor type constuctor for processing structured (JSON) configuration files

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published