C++20 single-header library for embedding INI configs

Overview

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;

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.

You might also like...
Embedded Linux embedding for Flutter

Embedded Linux embedding for Flutter This project was created to develop non-official embedded Linux embeddings of Flutter. This embedder is focusing

An In-memory Embedding of CPython

An In-memory Embedding of CPython This repository contains all the build artifacts necessary to build an embedding of CPython 3.8.2 that can be run en

A Proof-of-concept of embedding Qt widgets into QML.
A Proof-of-concept of embedding Qt widgets into QML.

QQuickWidgetContainer It helps you embed Qt widgets into QML. Limitations and Disclaimer This is a proof-concept of bridging QWidget-based window syst

C++ front-end package manager for embedding and redistributing with native applications

Pacm Simple C++ package manager Homepage: https://sourcey.com/pacm Documentation: https://sourcey.com/libsourcey/api-pacm/ Dependencies: LibSourcey (b

Simple .INI file parser in C, good for embedded systems

inih (INI Not Invented Here) inih (INI Not Invented Here) is a simple .INI file parser written in C. It's only a couple of pages of code, and it was d

ini file parser

Iniparser 4 I - Overview This modules offers parsing of ini files from the C level. See a complete documentation in HTML format, from this directory o

Simple .INI file parser in C, good for embedded systems

inih (INI Not Invented Here) inih (INI Not Invented Here) is a simple .INI file parser written in C. It's only a couple of pages of code, and it was d

ini file parser

Iniparser 4 I - Overview This modules offers parsing of ini files from the C level. See a complete documentation in HTML format, from this directory o

Blog post on using a custom Bash builtin to parse INI config files

Writing a Bash Builtin in C to Parse INI Configs Why Not Just Parse INI Configs With Bash? Shell languages such as Bash excel at certain tasks, such a

A single file, single function, header to make notifications on the PS4 easier

Notifi Synopsis Adds a single function notifi(). It functions like printf however the first arg is the image to use (NULL and any invalid input should

Single-header single-function C/C++ immediate-mode camera for your graphics demos
Single-header single-function C/C++ immediate-mode camera for your graphics demos

Single-header single-function C/C++ immediate-mode camera for your graphics demos

Single-header header-only C++11 / C++14 / C++17 library for easily managing set of auto-generated type-safe flags.
Single-header header-only C++11 / C++14 / C++17 library for easily managing set of auto-generated type-safe flags.

Single-header header-only C++11 / C++14 / C++17 library for easily managing set of auto-generated type-safe flags. Quick start #include bitflags/bitf

A fast single-producer, single-consumer lock-free queue for C++

A single-producer, single-consumer lock-free queue for C++ This mini-repository has my very own implementation of a lock-free queue (that I designed f

A bounded single-producer single-consumer wait-free and lock-free queue written in C++11
A bounded single-producer single-consumer wait-free and lock-free queue written in C++11

SPSCQueue.h A single producer single consumer wait-free and lock-free fixed size queue written in C++11. Example SPSCQueueint q(2); auto t = std::th

Minimalistic MP3 decoder single header library

minimp3 Minimalistic, single-header library for decoding MP3. minimp3 is designed to be small, fast (with SSE and NEON support), and accurate (ISO con

ring-span lite - A C++yy-like ring_span type for C++98, C++11 and later in a single-file header-only library

ring-span lite: A circular buffer view for C++98 and later Contents Example usage In a nutshell Dependencies Installation Synopsis Reported to work wi

A single-header ANSI C immediate mode cross-platform GUI library
A single-header ANSI C immediate mode cross-platform GUI library

Nuklear This is a minimal-state, immediate-mode graphical user interface toolkit written in ANSI C and licensed under public domain. It was designed a

Single header C++ logging library. It is extremely powerful, extendable, light-weight, fast performing, thread and type safe and consists of many built-in features. It provides ability to write logs in your own customized format. It also provide support for logging your classes, third-party libraries, STL and third-party containers etc.
linalg.h is a single header, public domain, short vector math library for C++

linalg.h linalg.h is a single header, public domain, short vector math library for C++. It is inspired by the syntax of popular shading and compute la

Owner
clyne
clyne
Simple .INI file parser in C, good for embedded systems

inih (INI Not Invented Here) inih (INI Not Invented Here) is a simple .INI file parser written in C. It's only a couple of pages of code, and it was d

Ben Hoyt 1.9k Dec 28, 2022
ini file parser

Iniparser 4 I - Overview This modules offers parsing of ini files from the C level. See a complete documentation in HTML format, from this directory o

Nicolas D 845 Jan 1, 2023
This is a header only C++ version of inih.

inih This is a header only C++ version of inih. inih (INI Not Invented Here) is a simple .INI file parser written in C. It's only a couple of pages of

Jan Tilly 396 Dec 29, 2022
Header-only TOML config file parser and serializer for C++17 (and later!).

toml++ homepage ✨ This README is fine, but the toml++ homepage is better. ✨ Library features Header-only Supports the latest TOML release (v1.0.0), pl

Mark Gillard 965 Dec 29, 2022
Small configuration file parser library for C.

libConfuse Introduction Documentation Examples Build & Install Origin & References Introduction libConfuse is a configuration file parser library writ

null 419 Dec 14, 2022
Scripts and configs for Sea Dogs: To Each His Own

Sea Dogs: To Each His Own This repository contains game scripts and configuration files for the Sea Dogs: To Each His Own game. GitHub Discussions Dis

Storm Devs 23 Sep 8, 2022
Trilogy is a client library for MySQL-compatible database servers, designed for performance, flexibility, and ease of embedding.

Trilogy is a client library for MySQL-compatible database servers, designed for performance, flexibility, and ease of embedding.

GitHub 482 Dec 31, 2022
Simple library for embedding static resources into C++ binaries using CMake

libromfs libromfs is an easy way to bundle resources directly into any C++ application and access them through a simple interface. The main advantage

WerWolv 28 Nov 30, 2022
Cross-platform C++ library providing a simple API to read and write INI-style configuration files

simpleini A cross-platform library that provides a simple API to read and write INI-style configuration files. It supports data files in ASCII, MBCS a

Brodie Thiesfield 797 Dec 28, 2022
A small and portable INI file library with read/write support

minIni minIni is a portable and configurable library for reading and writing ".INI" files. At just below 900 lines of commented source code, minIni tr

Thiadmer Riemersma 293 Dec 29, 2022