Mathematics, philosophy, programming, in-line skating and everything in between. More about me…

My Blog

My Latest Tweets

Follow me on Twitter…
English | Czech
Choose your language. I write in English, but I translate most of my articles to Czech as well. Zvolte si jazyk. Píšu anglicky, ale většinu svých článků překládám i do češtiny.

Vita::config – reading config files

In a follow-up to my post about Vita::string, I release another part of my micro-library: class serving as a gateway to simple configuration files.

Vita::config is able to load a configuration file and put the key-value pairs into std::map<Vita::string, Vita::string>. All values are thus easily accessible and convertible, and one can use everything Vita::string offers. A sample usage:

Vita::config config1("test.conf");
double pi = config1.get("pi").convert<double>();
std::cout << config1.get("shell").ucfirst();

Configuration files are expected to be in the usual UNIX form; white space and comments are ignored, of course.

# Comment
key1 = value1
key2 = value2

Configuration can be easily written, too:

Vita::config config2;
config2.set("euler", "2.718281828");
config2.saveFile("new-config.conf");

See the demo/ directory in the archives for more examples. As usual, library documentation is contained in the downloadable archives and available for on-line browsing.

August 11, MMVIII — C++ and Programming.

Speak your mind

Allowed HTML tags are a, blockquote, em, code, li, ol, p, pre, strong, ul. Links to other comments in the form “[IV]” or “[4]” are detected automatically.