1# Method Chained libconfig # 2 3**Exception free + header only + method chained + config files** 4 5Provides reading the configuration and defining the configuration specification at once. 6 7### Features ### 8 9 * default values 10 * limits (min/max) 11 * mandatory/optional values 12 * help text output for expected config format on specification violation 13 * capturing and outputting expected configuration specification/defaults 14 15While it is possible to write a config file with this extension using the configuration specification capturing feature, it is not intended to be used as a full fledged config writer. 16 17### Example ### 18 19```C++ 20#include <libconfig_chained.h> 21 22using namespace std; 23using namespace libconfig; 24 25int main(int argc, char **argv) 26{ 27 Config cfg; 28 cfg.readFile("example.cfg"); 29 ChainedSetting cs(cfg.getRoot()); 30 31 string name = cs["name"].defaultValue("<name>").isMandatory(); 32 string abstract = cs["abstract"].defaultValue("<unknown>"); 33 double longitude = cs["longitude"].min(-180.0).max(180.0).isMandatory(); 34 double latitude = cs["latitude"].min(-90.0).max(90.0).isMandatory(); 35 36 if (cs.isAnyMandatorySettingMissing()) 37 { 38 cerr << "Cannot proceed until all mandatory settings are set." << endl; 39 } 40} 41``` 42 43Console Output: 44```sh 45'longitude' setting is out of valid bounds (max: 180). Value was: 1200.35 46Missing 'latitude' setting in configuration file. 47Cannot proceed until all mandatory settings are set. 48``` 49 50--- 51 52### How to integrate into your project ### 53 54 1. Link the libconfig++.[lib/la/a] library as usual (see standard use of libconfig++). 55 * Replace any includes of libconfig.h++ by libconfig_chained.h. 56 * Use method chained candy as displayed above. 57 58--- 59 60Create an issue for any questions or suggestions. Alternatively email me at github [at) hemofektik.de