X-Git-Url: http://git.euphorik.ch/index.cgi?a=blobdiff_plain;f=WCudaMSE%2FTuto_Boost%2Fsrc%2Fcpp%2Fcore%2Foptions%2FuseOptions.cpp;fp=WCudaMSE%2FTuto_Boost%2Fsrc%2Fcpp%2Fcore%2Foptions%2FuseOptions.cpp;h=cb56ee5aa72a41d0fa0b8f25bfa850b86834a470;hb=8d08c12b29c2a14684f35c023ee39e694bb80d25;hp=0000000000000000000000000000000000000000;hpb=226de81f7e1f1fbf4ac79d0d089e8a05ec7159a0;p=GPU.git diff --git a/WCudaMSE/Tuto_Boost/src/cpp/core/options/useOptions.cpp b/WCudaMSE/Tuto_Boost/src/cpp/core/options/useOptions.cpp new file mode 100755 index 0000000..cb56ee5 --- /dev/null +++ b/WCudaMSE/Tuto_Boost/src/cpp/core/options/useOptions.cpp @@ -0,0 +1,98 @@ +#include +#include + +/*----------------------------------------------------------------------*\ + |* Declaration *| + \*---------------------------------------------------------------------*/ + +using std::cout; +using std::endl; + +namespace po = boost::program_options; + +using po::options_description; +using po::value; +using po::variables_map; +using po::store; +using po::parse_command_line; +using po::notify; + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +bool useOption(int argc, char** argv); + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + +static bool use(double a, double b); +static bool help(const options_description& description); + +/*----------------------------------------------------------------------*\ + |* Implementation *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +/** + * http://www.boost.org/doc/libs/1_55_0/doc/html/program_options/tutorial.html#idp163291912 + */ +bool useOption(int argc, char** argv) + { + double a; + double b; + + options_description description("Allowed options"); + description.add_options() + ("help", "produce help message") + ("a", value(&a)->default_value(3.14), "explain here what is a ... Example: --a=2.22") + ("b", value(&b)->default_value(1.11), "explain here what is b ... Example: --a=3.33"); + + variables_map mapVariableValue; + store(parse_command_line(argc, argv, description), mapVariableValue); + notify(mapVariableValue); + + if (mapVariableValue.count("help")) + { + return help(description); + } + else + { + return use(a, b); + } + } + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + +bool use(double a, double b) + { + cout << "[Use Option] : " << endl << endl; + + cout << "a= " << a << endl; + cout << "b= " << b << endl; + cout << endl; + + return true; + } + +bool help(const options_description& description) + { + cout << "[Help] " << endl<