added command line args parsing into gpu performance sample
authorAlexey Spizhevoy <no@email>
Thu, 3 Mar 2011 13:46:44 +0000 (13:46 +0000)
committerAlexey Spizhevoy <no@email>
Thu, 3 Mar 2011 13:46:44 +0000 (13:46 +0000)
samples/gpu/performance/performance.cpp

index c265b36..01623ff 100644 (file)
@@ -1,5 +1,6 @@
 #include <iomanip>\r
 #include <stdexcept>\r
+#include <string>\r
 #include "performance.h"\r
 \r
 using namespace std;\r
@@ -151,12 +152,25 @@ int CV_CDECL cvErrorCallback(int /*status*/, const char* /*func_name*/,
 \r
 int main(int argc, char** argv)\r
 {\r
-    if (argc < 3)\r
-        cout << "Usage: performance_gpu <test_filter> <working_dir_with_slash>\n\n";\r
-    if (argc >= 2)\r
-        TestSystem::instance().setTestFilter(argv[1]);\r
-    if (argc >= 3)\r
-        TestSystem::instance().setWorkingDir(argv[2]);\r
+    // Parse command line arguments\r
+    for (int i = 1; i < argc; ++i)\r
+    {\r
+        string key = argv[i];\r
+        if (key == "--help")\r
+        {\r
+            cout << "Usage: performance_gpu [--filter <test_filter>] [--working-dir <working_dir_with_slash>]\n";\r
+            return 0;\r
+        }\r
+        if (key == "--filter" && i + 1 < argc)\r
+            TestSystem::instance().setTestFilter(argv[++i]);\r
+        else if (key == "--working-dir" && i + 1 < argc)\r
+            TestSystem::instance().setWorkingDir(argv[++i]);\r
+        else \r
+        {\r
+            cout << "Unknown parameter: '" << key << "'" << endl;\r
+            return -1;\r
+        }\r
+    }\r
 \r
     redirectError(cvErrorCallback);\r
     TestSystem::instance().run();\r