Ajout de l'ensemble du workspace.
[GPU.git] / WCudaMSE / Tuto_Boost / src / cpp / core / options / useOptions.cpp
1 #include <iostream>
2 #include <boost/program_options.hpp>
3
4 /*----------------------------------------------------------------------*\
5 |* Declaration *|
6 \*---------------------------------------------------------------------*/
7
8 using std::cout;
9 using std::endl;
10
11 namespace po = boost::program_options;
12
13 using po::options_description;
14 using po::value;
15 using po::variables_map;
16 using po::store;
17 using po::parse_command_line;
18 using po::notify;
19
20 /*--------------------------------------*\
21 |* Public *|
22 \*-------------------------------------*/
23
24 bool useOption(int argc, char** argv);
25
26 /*--------------------------------------*\
27 |* Private *|
28 \*-------------------------------------*/
29
30 static bool use(double a, double b);
31 static bool help(const options_description& description);
32
33 /*----------------------------------------------------------------------*\
34 |* Implementation *|
35 \*---------------------------------------------------------------------*/
36
37 /*--------------------------------------*\
38 |* Public *|
39 \*-------------------------------------*/
40
41 /**
42 * http://www.boost.org/doc/libs/1_55_0/doc/html/program_options/tutorial.html#idp163291912
43 */
44 bool useOption(int argc, char** argv)
45 {
46 double a;
47 double b;
48
49 options_description description("Allowed options");
50 description.add_options()
51 ("help", "produce help message")
52 ("a", value<double>(&a)->default_value(3.14), "explain here what is a ... Example: --a=2.22")
53 ("b", value<double>(&b)->default_value(1.11), "explain here what is b ... Example: --a=3.33");
54
55 variables_map mapVariableValue;
56 store(parse_command_line(argc, argv, description), mapVariableValue);
57 notify(mapVariableValue);
58
59 if (mapVariableValue.count("help"))
60 {
61 return help(description);
62 }
63 else
64 {
65 return use(a, b);
66 }
67 }
68
69 /*--------------------------------------*\
70 |* Private *|
71 \*-------------------------------------*/
72
73 bool use(double a, double b)
74 {
75 cout << "[Use Option] : " << endl << endl;
76
77 cout << "a= " << a << endl;
78 cout << "b= " << b << endl;
79 cout << endl;
80
81 return true;
82 }
83
84 bool help(const options_description& description)
85 {
86 cout << "[Help] " << endl<<endl;
87
88 cout << description << endl<<endl;
89
90 cout<< "Write help here ..."<<endl<<endl;
91
92 return true;
93 }
94
95 /*----------------------------------------------------------------------*\
96 |* End *|
97 \*---------------------------------------------------------------------*/
98