[MOAB-dev] r5185 - in MOAB/trunk: src src/moab tools/dagmc

sjackson at cae.wisc.edu sjackson at cae.wisc.edu
Thu Oct 6 12:20:29 CDT 2011


Author: sjackson
Date: 2011-10-06 12:20:29 -0500 (Thu, 06 Oct 2011)
New Revision: 5185

Modified:
   MOAB/trunk/src/ProgOptions.cpp
   MOAB/trunk/src/moab/ProgOptions.hpp
   MOAB/trunk/tools/dagmc/dagmc_preproc.cpp
Log:
Add a version feature to ProgOptions.

* Program can specify a version string, which can be printed with
  the printVersion() method
* A command-line version flag is optionally created when the version
  string is set.  Such a flag prints the program version without
  doing any further option parsing; this allows a '--version' option
  to operate in the absense of required arguments.
* Test this feature with dagmc_preproc.

Modified: MOAB/trunk/src/ProgOptions.cpp
===================================================================
--- MOAB/trunk/src/ProgOptions.cpp	2011-10-04 19:09:47 UTC (rev 5184)
+++ MOAB/trunk/src/ProgOptions.cpp	2011-10-06 17:20:29 UTC (rev 5185)
@@ -106,8 +106,15 @@
   
 }
 
+void ProgOptions::setVersion( const std::string& version_string, bool addFlag ){
+  progversion = version_string;
+  if( addFlag ){
+    addOpt<void>( "version", "Print version number and exit", version_flag );
+  }
+}
 
 
+
 template < typename T >
 void ProgOptions::addOpt( const std::string& namestring, const std::string& helpstring, 
 			  T* value, int flags ){
@@ -193,6 +200,10 @@
   option_help_strings.push_back( std::make_pair( (ProgOpt*)NULL, s) );
 }
 
+void ProgOptions::printVersion( std::ostream& out ){
+  out << progversion << std::endl;
+}
+
 void ProgOptions::printHelp( std::ostream& out ){
   
   /* Print introductory help text */
@@ -639,6 +650,11 @@
     printHelp( std::cout );
     exit( EXIT_SUCCESS );
   }
+
+  if( opt->flags & version_flag ){
+    printVersion( std::cout );
+    exit( EXIT_SUCCESS );
+  }
   
   if (opt->type != FLAG) {
     if (!value)

Modified: MOAB/trunk/src/moab/ProgOptions.hpp
===================================================================
--- MOAB/trunk/src/moab/ProgOptions.hpp	2011-10-04 19:09:47 UTC (rev 5184)
+++ MOAB/trunk/src/moab/ProgOptions.hpp	2011-10-06 17:20:29 UTC (rev 5185)
@@ -72,6 +72,9 @@
    *  has no effect for non-string options.
    */


More information about the moab-dev mailing list