Boost logo

Boost Users :

Subject: [Boost-users] [Program Options] Streaming of actual option values.
From: Rodolfo Federico Gamarra (rgamarra_at_[hidden])
Date: 2009-01-21 21:28:53


Hi all!!

I'm using <boost/program_options.hpp> to allow options in my program
to be configured using 3 flavors:

- Command line values
- Config-file values ( parse_config_file).
- Default values ( value<double>(&myDouble)->default_value(3.3) )

prioritized in the given order and put all together in the same variables_map.

Upon finalization I'd like to generate a config-file (as required by
the 2nd flavor) with the actual values used in the run.

So far I've come with a solution that involves iterating over the map,
and performing the outstreaming by myself. Something in the line of

for(variables_map::const_iterator i = vm.begin(); i != vm.end();++i) {
    std::cout << i->first << " " << i->second.as<std::string>() << std::endl;
}

What is cumbersome of this approach is that, actually, not all my args
are "std::string", so in reality the call to as<>() ends with
bad_any_cast in some cases: it seems that there's no operator <<
defined for i->second or its underlying "boost::any". So I'd have to
switch-case over all the types I'm using for the values.

Second, I have to format the output in accordance to parse_config_file
by myself.

Is there any better solution to this?

Thanks a lot in advance.

--
Rodolfo Federico Gamarra

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net