AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
AnCH configuration library documentation

Introduction

AnCh configuration library aims to provide facilities to handle configuration files.

Prerequisites

  • anch-ini: this is the default configuration file parser (it will be register with extensions ini , conf , cnf and properties files)

Installation

CMake target anch::conf:

find_package(Anch REQUIRED)
target_link_libraries(my-app PRIVATE anch::conf)

See installation.

Conception

Configuration is loaded once with Configuration::loader() and read with Configuration::inst(). Values are read with dotted paths (section.subsection.key ).

Cascade

# application.ini
anch::conf.includes=database,security
anch::conf.default-profiles=dev
[server]
host=${env=HOST|localhost}
port=8080
url=http://${conf=server.host}:${conf=server.port}/

Loading order (later files override previous values): application , included files (database , security ), then for each active profile application-<profile> and <include>-<profile> when they exist. Active profiles are given to profiles() , or set in ANCH_PROFILES environment variable, or anch::conf.default-profiles .

Placeholders

${alternative|alternative|...}: an alternative is resolver=argument (env , conf or registered resolvers) or a default value; the first alternative which resolves is used. Resolution is event driven (a resolved value completes the values which reference it) and has a watchdog: cycles and too long resolution chains are errors (CYCLE ). Resolved values are literal.

Example

#include "conf/configuration.hpp"
int
main() {
.name("application")
.folders({"/etc/myapp", "."})
.load();
std::optional<std::string> url = conf.value("server.url");
std::cout << "server.url=" << url.value_or("<none>") << std::endl;
return 0;
}