Ajout de l'ensemble du workspace.
[GPU.git] / WCudaMSE / Tuto_Boost / src / cpp / core / options / useOptions.cpp
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 (executable)
index 0000000..cb56ee5
--- /dev/null
@@ -0,0 +1,98 @@
+#include <iostream>\r
+#include <boost/program_options.hpp>\r
+\r
+/*----------------------------------------------------------------------*\\r
+ |*                    Declaration                                     *|\r
+ \*---------------------------------------------------------------------*/\r
+\r
+using std::cout;\r
+using std::endl;\r
+\r
+namespace po = boost::program_options;\r
+\r
+using po::options_description;\r
+using po::value;\r
+using po::variables_map;\r
+using po::store;\r
+using po::parse_command_line;\r
+using po::notify;\r
+\r
+/*--------------------------------------*\\r
+ |*            Public                  *|\r
+ \*-------------------------------------*/\r
+\r
+bool useOption(int argc, char** argv);\r
+\r
+/*--------------------------------------*\\r
+ |*            Private                 *|\r
+ \*-------------------------------------*/\r
+\r
+static bool use(double a, double b);\r
+static bool help(const options_description& description);\r
+\r
+/*----------------------------------------------------------------------*\\r
+ |*                    Implementation                                  *|\r
+ \*---------------------------------------------------------------------*/\r
+\r
+/*--------------------------------------*\\r
+ |*            Public                  *|\r
+ \*-------------------------------------*/\r
+\r
+/**\r
+ * http://www.boost.org/doc/libs/1_55_0/doc/html/program_options/tutorial.html#idp163291912\r
+ */\r
+bool useOption(int argc, char** argv)\r
+    {\r
+    double a;\r
+    double b;\r
+\r
+    options_description description("Allowed options");\r
+    description.add_options()\r
+           ("help", "produce help message")\r
+           ("a", value<double>(&a)->default_value(3.14), "explain here what is a ... Example: --a=2.22")\r
+           ("b", value<double>(&b)->default_value(1.11), "explain here what is b ... Example: --a=3.33");\r
+\r
+    variables_map mapVariableValue;\r
+    store(parse_command_line(argc, argv, description), mapVariableValue);\r
+    notify(mapVariableValue);\r
+\r
+    if (mapVariableValue.count("help"))\r
+       {\r
+       return help(description);\r
+       }\r
+    else\r
+       {\r
+       return use(a, b);\r
+       }\r
+    }\r
+\r
+/*--------------------------------------*\\r
+ |*            Private                 *|\r
+ \*-------------------------------------*/\r
+\r
+bool use(double a, double b)\r
+    {\r
+    cout << "[Use Option] : " << endl << endl;\r
+\r
+    cout << "a= " << a << endl;\r
+    cout << "b= " << b << endl;\r
+    cout << endl;\r
+\r
+    return true;\r
+    }\r
+\r
+bool help(const options_description& description)\r
+    {\r
+    cout << "[Help] " << endl<<endl;\r
+\r
+    cout << description << endl<<endl;\r
+\r
+    cout<< "Write help here ..."<<endl<<endl;\r
+\r
+    return true;\r
+    }\r
+\r
+/*----------------------------------------------------------------------*\\r
+ |*                    End                                             *|\r
+ \*---------------------------------------------------------------------*/\r
+\r