aboutsummaryrefslogtreecommitdiff
path: root/contrib/chained/README.md
blob: 9a7ebeab5e186a4bd7119335ec0337d0db186ff9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Method Chained libconfig #

**Exception free + header only + method chained + config files**

Provides reading the configuration and defining the configuration specification at once.

### Features ###

 * default values
 * limits (min/max)
 * mandatory/optional values
 * help text output for expected config format on specification violation
 * capturing and outputting expected configuration specification/defaults

While 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.

### Example ###

```C++
#include <libconfig_chained.h>

using namespace std;
using namespace libconfig;

int main(int argc, char **argv)
{
    Config cfg;
    cfg.readFile("example.cfg");
    ChainedSetting cs(cfg.getRoot());

    string name = cs["name"].defaultValue("<name>").isMandatory();
    string abstract = cs["abstract"].defaultValue("<unknown>");
    double longitude = cs["longitude"].min(-180.0).max(180.0).isMandatory();
    double latitude = cs["latitude"].min(-90.0).max(90.0).isMandatory();

    if (cs.isAnyMandatorySettingMissing())
    {
        cerr << "Cannot proceed until all mandatory settings are set." << endl;
    }
}
```

Console Output:
```sh
'longitude' setting is out of valid bounds (max: 180). Value was: 1200.35
Missing 'latitude' setting in configuration file.
Cannot proceed until all mandatory settings are set.
```

---

### How to integrate into your project ###

 1. Link the libconfig++.[lib/la/a] library as usual (see standard use of libconfig++).
 * Replace any includes of libconfig.h++ by libconfig_chained.h.
 * Use method chained candy as displayed above.

---

Create an issue for any questions or suggestions. Alternatively email me at github [at) hemofektik.de