]> code.bitgloo.com Git - clyne/ini-config.git/summary
 
descriptionCompile-time INI config parser in modern C++
ownerClyne Sullivan
last changeWed, 10 Feb 2021 13:00:44 +0000 (08:00 -0500)

ini-config

A single-header library that converts INI-formatted string literals to a key-value pair list at compile-time.

Requires C++20; tested on gcc 10.1 and clang trunk. Passes -Wall -Wextra -pedantic.

Features

Try it on Godbolt.

INI format notes

How to use

```cpp

include "ini_config.hpp"

// Simply place the _ini suffix at the end of your config string: constexpr auto config = R"( someflag = true

[Cat] color = gray lives = 9 )"_ini;

// Or, go for a more functional look: //constexpr auto config = makeiniconfig;

auto KVPcount = config.size(); // = 3 for (auto kvp : config) {} // Iterate through all KVPs // (or use begin()/end()) for (auto kvp : config.section("Cat")) {} // Iterate through all KVPs under [Cat] section // (or use begin("Cat")/end("Cat")) config.get("someflag"); // Searches entire config for "someflag", picks first match // This call gets compile-time evaluated to "true" config.get("Cat", "lives"); // Searches "Cat" section, compile-time evaluated to "9" config.get("Cat", "lives"); // Compile-time evaluated to 9 config.get("Dog", "lives"); // Does not exist, compile-time evaluated to "" config.contains("Dog", "lives"); // Compile-time evaluated to false

config.tryget(argv[2]); // Same interface and behavior as get(), // use this when run-time evaluation is necessary config.trycontains("color"); // Run-time evaluated to true ``` See the header file for further documentation.

shortlog
2021-02-10 clyneUpdate README.md master
2021-02-10 Clyne Sullivandocumentation clean up; add make_ini_config
2021-02-09 clyneUpdate README.md
2021-02-08 clyneadd try...() calls for non-constant usage
2021-02-06 clyneFix <=> comparison
2021-02-06 clyneEnsure compile-time evaluation of accesses
2021-02-05 clyneAdd get<T>() for converting values to numbers
2021-01-10 clyneValidate section tags; add cbegin, cend, and contains
2021-01-06 clyneFixed end() for wide strings
2021-01-05 clyneTypo in godbolt example
2021-01-05 clyneImprove documentation, add godbolt example
2021-01-05 clyneAdd author comment
2021-01-05 clyneCreate ini_config.hpp
2021-01-05 clyneCreate README.md
2021-01-05 clyneInitial commit
heads
4 years ago master