Initial filenames can be passed as command-line arguments
authorDmitriy Morozov <morozov@cs.duke.edu>
Tue, 22 Jul 2008 10:01:49 -0400
changeset 14 172c2683c714
parent 13 554df9494fd2
child 15 846354ed6853
Initial filenames can be passed as command-line arguments
CMakeLists.txt
main.cpp
--- a/CMakeLists.txt	Mon Jul 21 17:33:20 2008 -0400
+++ b/CMakeLists.txt	Tue Jul 22 10:01:49 2008 -0400
@@ -1,4 +1,5 @@
 project						(VEFViewer)
+cmake_minimum_required      (VERSION 2.4)
 
 # Set Qt4 and QGLViewer configuration
 find_package				(Qt4 REQUIRED)
@@ -17,8 +18,11 @@
 qt4_wrap_ui					(uis_h ${uis})
 include_directories			(${CMAKE_CURRENT_BINARY_DIR} ${QGLViewer_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
 
+find_library                (boost_program_options_LIBRARY      NAME boost_program_options
+                                                                PATHS ${Boost_LIBRARY_DIR})
+
 add_executable				(VEFViewer ${sources} ${moc_srcs} ${uis_h})
-target_link_libraries		(VEFViewer ${QT_LIBRARIES} ${QGLViewer_LIBRARY})
+target_link_libraries		(VEFViewer ${QT_LIBRARIES} ${QGLViewer_LIBRARY} ${boost_program_options_LIBRARY})
 
 install						(TARGETS VEFViewer
 							 RUNTIME DESTINATION bin)
--- a/main.cpp	Mon Jul 21 17:33:20 2008 -0400
+++ b/main.cpp	Tue Jul 22 10:01:49 2008 -0400
@@ -1,6 +1,9 @@
 #include <qapplication.h>
 #include "ui_viewerInterface.h"
 #include "VEFViewer.h"
+#include <boost/program_options.hpp>
+#include <vector>
+#include <string>
 
 class ViewerInterface: public QDialog, public Ui::Dialog
 {
@@ -8,11 +11,44 @@
 		ViewerInterface() { setupUi(this); viewer->setModelList(listWidget); }
 };
 
+namespace po = boost::program_options;
+
 int main(int argc, char** argv)
 {
-  QApplication application(argc,argv);
-  ViewerInterface vi;
-  vi.show();
+    QApplication application(argc,argv);
+    ViewerInterface vi;
+    vi.show();
+
+    // Parse program options
+    std::vector<std::string> input_filenames;
+    po::options_description hidden("Hidden options");
+    hidden.add_options()
+        ("input-file",  po::value<std::vector<std::string> >(&input_filenames),
+                        "Input filenames (extensions: vrt, edg, stl)");
+
+    po::options_description visible("Allowed options");
+    visible.add_options()
+        ("help,h",      "produce help message");
+    po::positional_options_description p;
+    p.add("input-file", -1);
+    
+    po::options_description all; all.add(visible).add(hidden);
 
-  return application.exec();
+    po::variables_map vm;
+    po::store(po::command_line_parser(argc, argv).
+                  options(all).positional(p).run(), vm);
+    po::notify(vm);
+
+    if (vm.count("help"))
+    { 
+        std::cout << "Usage: " << argv[0] << " [options] [INPUTFILE1] [INPUTFILE2] ..." << std::endl;
+        std::cout << visible << std::endl; 
+        return 1; 
+    }
+    
+    for (std::vector<std::string>::const_iterator cur = input_filenames.begin();
+                                                  cur != input_filenames.end(); ++cur)
+        vi.viewer->addFile(cur->c_str());
+
+    return application.exec();
 }