boost::program_option #2
// testProgOpt.cpp
#include
#include
#include
using namespace boost;
using namespace boost::program_options;
using namespace std;
// A helper function to simplify the main part.
template
ostream& operator<<(ostream& os, const vector& v)
{
copy(v.begin(), v.end(), ostream_iterator(cout, " "));
return os;
}
int main(int ac, char* av[])
{
int light = 0;
options_description desc("Allowed options");
try {
desc.add_options()
("help", "Produce help message")
("compression", value(), "Set compression level")
("target-bpp", value(), "Set target bpp")
("lighting,L", value(&light)->default_value(10), "Set lighting")
("include-path,I", value<> >(), "input files")
("input-file", value<> >(), "input file")
;
/*
variables_map vm;
store(parse_command_line(ac, av, desc), vm);
notify(vm);
*/
positional_options_description p;
p.add("input-file", -1);
variables_map vm;
store(command_line_parser(ac, av).options(desc).positional(p).run(), vm);
notify(vm);
if (vm.count("help"))
{
cout << desc << "\n";
return 1;
}
if (vm.count("compression"))
{
cout << "Compression level was set to " <<>() << ".\n";
}
else
{
cout << "Compression level was not set.\n";
}
if (vm.count("include-path") )
{
cout << "Include paths are " <<> >() << endl;
}
if (vm.count("lighting") )
{
cout << "Lighting level is " << light << endl;
}
if (vm.count("input-file") )
{
cout << "Input files are " <<> >() << endl;
}
}
catch(exception& e)
{
cerr << e.what() << endl;
cout << desc << endl;
return 1;
}
return 0;
}
#include
#include
#include
using namespace boost;
using namespace boost::program_options;
using namespace std;
// A helper function to simplify the main part.
template
ostream& operator<<(ostream& os, const vector
{
copy(v.begin(), v.end(), ostream_iterator
return os;
}
int main(int ac, char* av[])
{
int light = 0;
options_description desc("Allowed options");
try {
desc.add_options()
("help", "Produce help message")
("compression", value
("target-bpp", value
("lighting,L", value
("include-path,I", value<> >(), "input files")
("input-file", value<> >(), "input file")
;
/*
variables_map vm;
store(parse_command_line(ac, av, desc), vm);
notify(vm);
*/
positional_options_description p;
p.add("input-file", -1);
variables_map vm;
store(command_line_parser(ac, av).options(desc).positional(p).run(), vm);
notify(vm);
if (vm.count("help"))
{
cout << desc << "\n";
return 1;
}
if (vm.count("compression"))
{
cout << "Compression level was set to " <<>() << ".\n";
}
else
{
cout << "Compression level was not set.\n";
}
if (vm.count("include-path") )
{
cout << "Include paths are " <<> >() << endl;
}
if (vm.count("lighting") )
{
cout << "Lighting level is " << light << endl;
}
if (vm.count("input-file") )
{
cout << "Input files are " <<> >() << endl;
}
}
catch(exception& e)
{
cerr << e.what() << endl;
cout << desc << endl;
return 1;
}
return 0;
}

0 Comments:
Post a Comment
<< Home