|
Boost Users : |
Subject: [Boost-users] [program options] count problem
From: Olivier Tournaire (olitour_at_[hidden])
Date: 2013-02-02 08:08:06
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 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