Boost logo

Boost Users :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2005-02-24 07:14:20


Hi Austin,

> I'm wondering if program_options supports the notion of two
> command-line tokens forming a single value, and, if so, how. For
> example, one of the values I'd like to pass on via the command-line is
> `a position in lat-lon. For consistency with other programs my users
> know, I'd like to use something like this:
>
> --position 10:11:12:N 13:14:15:W
>
> During parsing, I'd like program_options to recognize that --position
> requires two associated tokens.
>
> I tried to use the multitoken() method, but this didn't seem to do
> what I wanted. The operator>> I wrote for parsing the tokens was still
> only being passed a single token. Either multitoken doesn't do what I
> expect, or I'm missing something. Any ideas? Thanks.

Something strange. What is the type of the 'position' option? Unless it's
std::vector of something, I'd expect an exception to be thrown.

The solution to your problem is the overload the 'validate' function for
your class. Like this:

  void validate(boost::any& v,
                const std::vector<std::string>& xs,
                your_type*, int)

You can look at boost/program_options/detail/value_semantic.hpp to learn how
to implement this.

I intend to document and probably improve the mechanisms really soon now.

- Volodya


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