|
Boost Users : |
Subject: Re: [Boost-users] [program options] count problem
From: Diederick C. Niehorster (dcnieho_at_[hidden])
Date: 2013-02-02 08:36:03
This call I use works for me:
po::command_line_parser(argc, ppargv).options(desc).run()
Don't know if there is an important difference here, or if what you
call is just a wrapper around it, but see if that works for you.
Best,
Dee
On Sat, Feb 2, 2013 at 9:14 PM, Olivier Tournaire <olitour_at_[hidden]> wrote:
> Oups. Made à mistake ... However the issue is still there:
>
> if (vm.count("hierarchy"))
> {
> path input_path(hierarchy);
> // DO STUFF
> }
> else if (vm.count("file"))
>
> {
> for(unsigned int i=0;i<files.size();++i)
> {
> path input_path(files[i]);
> // DO STUFF
> }
> }
> else if (vm.count("directory"))
>
> {
> for(unsigned int i=0;i<directories.size();++i)
> {
> path input_path(directories[i]);
> // DO STUFF
> }
> }
> else
> {
> cout << "You must choose an option between --hierarchy --file
> --directory!" << endl;
>
> cout << desc << endl;
> return 1;
> }
>
>
>
> Le samedi 2 février 2013, Olivier Tournaire a écrit :
>
>> Hi all,
>>
>> I am having troubles with program options. I try to test if at least some
>> of the available options are passed on the command line, but fail for some
>> reason using count("option_name"). Here is my code:
>>
>> int main(int argc, char** argv)
>> {
>> string hierarchy;
>> vector<string> files, directories;
>> double vertical_shift;
>> bool show_progress, single_file, single_dir;
>> int target_EPSG, nb_threads;
>>
>> po::options_description desc("Allowed options");
>> desc.add_options()
>> ("help ,h"
>> , "Produce help message")
>> ("hierarchy ", po::value<string>(&hierarchy)
>> , "process a hierarchy)
>> ("file ", po::value<vector<string> >(&files)
>> , "process the specified files")
>> ("directory ", po::value<vector<string> >(&directories)
>> , "process the specified directories");
>>
>> po::variables_map vm;
>> try
>> {
>> po::store(po::parse_command_line(argc, argv, desc), vm);
>>
>> if (vm.count("help"))
>> {
>> cout << desc << "\n";
>> return 1;
>> }
>>
>> po::notify(vm);
>> }
>> catch (const po::error &e)
>> {
>> cerr << "Exception caught ! --> " << e.what() << endl;
>> cout << desc << endl;
>> return 1;
>> }
>>
>> if (vm.count("hierarchy"))
>> {
>> path input_path(hierarchy);
>> // DO STUFF
>> }
>> else if (vm.count("files"))
>> {
>> for(unsigned int i=0;i<files.size();++i)
>> {
>> path input_path(files[i]);
>> // DO STUFF
>> }
>> }
>> else if (vm.count("directories"))
>> {
>> for(unsigned int i=0;i<directories.size();++i)
>> {
>> path input_path(directories[i]);
>> // DO STUFF
>> }
>> }
>> else
>> {
>> cout << "You must choose an option between --hierarchy --files
>> --directories!" << endl;
>> cout << desc << endl;
>> return 1;
>> }
>>
>>
>> I always fall in the "else". What am I doing wrong?
>>
>> For instance with this command line : ./acute_coordinates_transform
>> --hierarchy ~/work/data/
>>
>> à other question: is there à way to specify that 1 of the 3 options is
>> required (and only 1)?
>>
>> Hope you cloud help.
>>
>> Regards,
>>
>> Olivier
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
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