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
make install
Conception
AnCH configuration library is a thread safe configuration files management library.
Every configurations will be store in application cache and will be available with static methods.
Configuration files has to be formatted with classic key=value syntax. It supports comments with # character.
Configuration files can also contains categories which will be declared between brackets.
Configuration file example:
# Some comment
key=value
key1=value1
[category]
key=value # Other comment
key2=value2
Library interface is done in a single class: anch::conf::Configuration.
Configuration files are retrieved through getConfiguration static method which returns a anch::conf::Configuration instance.
Configuration parameters are retrieved through getParameter method.
Example
Configuration file "test.ini":
# Comments
toto=tata
tata=tutu # test with comments
[TOTO]
toto=titi
C++ example:
#include <iostream>
#include "configuration/configuration.hpp"
using std::cout;
using std::endl;
using std::string;
using anch::configuration::Configuration;
int
main(void) {
cout << "Enter in test configuration" << endl;
cout << "Parse file" << endl;
const Configuration& res = Configuration::getConfiguration("test.ini");
cout << "File has been parsed" << endl;
string value;
bool found = res.getParameter(value,"toto");
if(found) {
cout << "toto=" << value << endl;
} else {
cout << "toto has not been found" << endl;
}
found = res.getParameter(value,"toto","TOTO");
if(found) {
cout << "TOTO/toto=" << value << endl;
} else {
cout << "TOTO/toto has not been found" << endl;
}
found = res.getParameter(value,"tata");
if(found) {
cout << "tata=" << value << endl;
} else {
cout << "tata has not been found" << endl;
}
cout << "Exit test configuration" << endl;
return 0;
}