Boost logo

Boost Users :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2005-02-24 09:31:23


Austin Bingham wrote:

>> 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)
>
> Based on this, I've got a partially working solution. I treat
> --position as a vector<string> for parsing purposes; later, when I
> populate the runtime object with the parsed values, I make sure the
> count() of "position" is 2. While this is a bit problematic, it will
> work for the most part.
>
> Ideally, I would be able to specify that each "--position" token on
> the command line must be followed by exactly two other tokens. My
> validate function would then be able to determine if those strings are
> valid.

I think I'll be able to implement this. OTOH, this will become command-line
specific. What if you want to parse --position from config file:

  position=10:11:12:Nš13:14:15:W

in this case there are no separate token, the value is considered to be one
token. So probably, the best approach is to write your validator so that it
operates on a single string, and make program_options merge the tokens.
This way, the same validator will work both the command line and config
file.

- 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