Boost logo

Boost :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2004-08-05 11:58:41


Jeff Garland <jeff <at> crystalclearsoftware.com> writes:

>
> I'm writing a program with program_options (very cool and useful library, BTW)
> and I found myself wanting to print out the variable_map values for debugging
> purposes. Is there an easy way to do this?

No, not at this moment. The first problem is that variables_map is
a wrapper over std::map<string, boost::any>, and you can't print boost::any,
unless you know for sure it's some specific type. So, we need some dynamic_any,
and I'm not sure if that library is being pushed into Boost.

Second problem is that not all option types are printable, for example
std::vector<string> is not. So, some method of detecting printability is
needed.

A similiar problem has arisen some time ago. The variable_value::as method used
to resort to lexical_cast, if the stored type was not equal to the requested
one. This, however, required that all types you put in variables_map could
be created from string -- which is a drastic requirement.

>
> Also couple of documentation nits:
> 1) From the first example....
>
> if (vm.count("help")) {
> std::cout << desc << "\n";
>
> I had to read the code to figure out that variable_map inherits from std::map,
> and this is why you can call this. Documentation only says:
>
> class variables_map
> : : public boost::program_options::abstract_variables_map

Noted.

> 2) In the 'Storage Component' section -- there's this:
>
> Let's consider an example:
>
> variables_map vm;
> store(parse_command_line(argc, argv, desc), vm);
> store(parse_config_file("example.cfg", desc), vm);
> finish(vm);
> ....
> Finally the call to notify function runs user-specified notify
> functions and stores values into regular variables, if needed.
>
> I assume 'finish' is supposed to be notify? I don't see any docs for finish.

Yes, the 'notify' is the new spelling. Hmm.. I think I've fixed that doc
typo before leaving on vacation.

- Volodya


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk