I looked into the source to see if I could find what the count() function
was supposed to be doing, but I actually didn't find a count() function at
all?? The usage seems to be "was this parameter set"? But what I'm looking
for is "how many times was this parameter set - ie. how many times did I see
--list?)
Vladimir, you made it sound like po::parse_command_line does not collapse
the multiple parameters, but when you call po::store do they get collapsed?
Thanks,
David
On Wed, Apr 15, 2009 at 7:45 AM, David Doria
Volodya, thanks for the help thus far, I think I am close to getting it to work. According to the post you referred me to, multiple of the same parameter are not collapsed, ie --list a.txt b.txt --list c.txt d.txt Should give me access to the two separate lists.
I tried declaring the parameter as usual: ("list", po::value
()->multitoken(), "Lists.") And then I thought it may be the .count property?
cout << "There are " << vm.count("list") << " lists." << endl;
But there is only 1 list.
The idea was to do this:
vector
lists; for(unsigned int list = 0; list < vm.count("list"); list++) { vector<string> l = vm["list"].as (); lists.push_back(l); for(unsigned int item = 0; item < lists[list].size(); item++) cout << "List: " << list << " Item: " << item << " " << lists[list][item] << endl; }
Clearly I am still missing the part about accessing the separated "list" params. Can you see the problem here?
Thanks,
David
David Doria wrote:
I want to do something like this: --NumLists 2 --List0 a.txt b.txt --List1 c.txt d.txt
vector
Lists(2); po::options_description desc("Allowed options"); desc.add_options() ("help", "produce help message") ("List0", po::value
multitoken(), "List0.") ("List1", po::value multitoken(), "List1.") ; But if I wanted to handle --NumLists 10, I would have to manually add List0, List1, ... List10 as parameters. That seems a bit silly, but maybe this is a very odd usage?
Well, it's somewhat odd :-)
Please let me know if you can think of a better way to handle this.
Well, as a remark, your command line interface will make users cry:
- Do you really want users to type uppercase letters? (Use can use case-insensitive mode, of course, and allow any spelling, but upper case in your example seems strange. - Do you really want users to count lists and pass 0, 1, 2, etc explicitly? - Why do you need explicit specification of the number of lists?
I'd use:
--list a.txt b.txt --list c.txt d.txt
You might find the recent thread useful for handling such command lines:
http://permalink.gmane.org/gmane.comp.lib.boost.user/46405
- Volodya