Boost logo

Boost :

Subject: Re: [boost] Library for configuration file parsing
From: Denis Shevchenko (for.dshevchenko_at_[hidden])
Date: 2010-12-04 02:20:52

Hi all!

Those who are interested in my Confogurator, perhaps it will be interesting.

String-based interface that I used was a bad idea, because probably
errors will be detected only at runtime. Moreover, it was a my mistake
to use location of option in configuration file as identifier in user's
code. It was a very stupid design mistake.

Templates and preprocessor - and here is what I got:

Example config:
         Host =
         Port = 100

// in some .hpp file user definesoptions,
// in terms of their conceptual destination,
// but not their location in config:

// Work with options:
boost::cf::configurator conf;
conf.add< UdpHost >().location( "System::UdpServer::Host" );
conf.add< UdpPort >().location( "System::UdpServer::Port" );
// in other place...
std::string host = conf.get_value_of< UdpHost >();
unsigned int port = 0;
conf.get_value_of< UdpPort >( port );
// or like this: unsigned int port = conf.get_value_of< UdpPort,
unsigned int >();

So user does not use any string-identifier of option, but only its type.
Advantages of such solutions (imho):
- possible errors of option name will be detected at compile-time,
- if location of option in config file has changed, user must rewrite
only one string (in location() function),
- I can not imagine a more simple interface... :-)

What do you think about it?


Boost list run by bdawes at, gregod at, cpdaniel at, john at