Git Product home page Git Product logo

ini-config's Introduction

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

  • Direct accesses to values are compile-time evaluated, allowing an INI config to be used for project/program configuration.
  • Values can be accessed as strings, integers, or floating-point numbers.
  • Run-time support includes key lookup, iteration through the key-value list, and key existance checking; all of which can be filtered by section.

Try it on Godbolt.

INI format notes

  • Handles single-line key=value pairs (extra whitespace is okay)
  • Supports sections
  • Supports comments (start line with ';' or '#')
  • Supports wide strings
  • INI format is validated at compile-time, with future goal of clearly reporting syntax errors

How to use

#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 = make_ini_config<R"( ... )">;

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<int>("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.

ini-config's People

Contributors

tcsullivan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ini-config's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.