Print

Print


Commit in slic on MAIN
include/CmdManager.hh+60-71.12 -> 1.13
src/CmdManager.cc+22-71.21 -> 1.22
   /G4Application.cc+14-201.73 -> 1.74
+96-34
3 modified files
JM: SLIC-160

slic/include
CmdManager.hh 1.12 -> 1.13
diff -u -r1.12 -r1.13
--- CmdManager.hh	5 Sep 2006 23:21:41 -0000	1.12
+++ CmdManager.hh	14 Nov 2006 10:27:03 -0000	1.13
@@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/slic/include/CmdManager.hh,v 1.12 2006/09/05 23:21:41 jeremy Exp $
+// $Header: /cvs/lcd/slic/include/CmdManager.hh,v 1.13 2006/11/14 10:27:03 jeremy Exp $
 
 #ifndef SLIC_CMDMANAGER_HH
 #define SLIC_CMDMANAGER_HH 1
@@ -23,39 +23,92 @@
   public:
     virtual ~CmdManager();
 
-    //static CmdManager* instance();
-
     CmdManager();
 
   public:
 
+    /**
+     * Adds the command line option and associates
+     * it with the given Geant4 command string.
+     */
     void addCmd(CmdLineOpt* cl, std::string s);
 
-    // make a queue of commands to exec from the input args
+    /** 
+     * Makes a queue of Geant4 macro commands to 
+     * execute from the input arguments.  If
+     * the command queue is empty, the usage
+     * command will be added automatically.
+     */
     void fillG4CmdQueue();
-
+    
+    /**
+     * Setup the CmdManager from the command line
+     * options.
+     */
     void fillCmdArgs(int argc, char** argv);
 
-    // does this str look like "-x"
+    /**
+     * Checks whether a string looks like
+     * a command line switch, like "-x".
+     */
     bool isCmdOpt(const std::string& token);
 
-    // does this str look like "--x*"
+    /**
+     * Checks whether a string looks like
+     * the full command line option, like "--cmd".
+     */
     bool isCmdName(const std::string& token);
 
+    /**
+     * Get the arguments that were passed from command line. 
+     */
     CmdArgs* getCmdArgs();
 
+    /**
+     * Get the registry of valid command line arguments     
+     */
     CmdRegistry* getCmdRegistry();
 
+    /**
+     * Get the queue of Geant4 commands generated from command line arguments.
+     */
     G4CmdQueue* getG4CmdQueue();
 
+    /**
+     * Execute and then clear the current Geant4
+     * command queue.
+     */
     void execCurrG4CmdQueue(bool clear_it = true);
 
+    /**
+     * Clear the current Geant4 command queue. 
+     */
     void clearG4CmdQueue();
 
+    /**
+     * Checks if usage should be printed.
+     */
     bool isPrintUsage() const;
 
+    /**
+     * Checks if the version should be printed.
+     */
     bool isPrintVersion() const;
 
+    /**
+     * Changes state to clear the current
+     * queue and add the command to print
+     * a version string.   
+     */
+    inline void setPrintVersion(bool b=true);
+    
+    /**
+     * Changes state to clear the current
+     * queue and add the command to print
+     * the usage menu.
+     */
+    inline void setPrintUsage(bool b=true);
+
   private:
 
     // valid command line options registry

slic/src
CmdManager.cc 1.21 -> 1.22
diff -u -r1.21 -r1.22
--- CmdManager.cc	5 Sep 2006 23:21:55 -0000	1.21
+++ CmdManager.cc	14 Nov 2006 10:27:04 -0000	1.22
@@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/slic/src/CmdManager.cc,v 1.21 2006/09/05 23:21:55 jeremy Exp $
+// $Header: /cvs/lcd/slic/src/CmdManager.cc,v 1.22 2006/11/14 10:27:04 jeremy Exp $
 #include "CmdManager.hh"
 
 #include "G4Application.hh"
@@ -25,6 +25,11 @@
 
   void CmdManager::fillG4CmdQueue()
   {
+    if (m_args.getTokensBegin() == m_args.getTokensEnd()) {
+      setPrintUsage(true);
+      return;
+    }
+
     std::string curr_g4_cmd;
     std::string curr_tok;
     int n_args = 0;
@@ -80,17 +85,13 @@
 
 	  // Got a print usage.
 	  if (curr_g4_cmd == "/slic/usage") {
-	    m_printUsage = true;
-	    m_cmdQueue.clear();
-	    m_cmdQueue.addCmd(curr_g4_cmd);
+	    setPrintUsage(true);
 	    break;
 	  }
 
 	  // Got a print version.
 	  if (curr_g4_cmd == "/slic/version" ) {
-	    m_printVersion = true;
-	    m_cmdQueue.clear();
-	    m_cmdQueue.addCmd(curr_g4_cmd);
+	    setPrintVersion(true);
 	    break;
 	  }
 
@@ -257,4 +258,18 @@
   {
     return m_printVersion;
   }
+
+  void CmdManager::setPrintVersion(bool b)
+  {
+    m_printVersion=b;
+    clearG4CmdQueue();
+    m_cmdQueue.addCmd("/slic/version");
+  }
+  
+  void CmdManager::setPrintUsage(bool b)
+  {
+    m_printUsage=b;
+    clearG4CmdQueue();
+    m_cmdQueue.addCmd("/slic/usage");
+  }
 }

slic/src
G4Application.cc 1.73 -> 1.74
diff -u -r1.73 -r1.74
--- G4Application.cc	18 Oct 2006 22:32:13 -0000	1.73
+++ G4Application.cc	14 Nov 2006 10:27:04 -0000	1.74
@@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/slic/src/G4Application.cc,v 1.73 2006/10/18 22:32:13 jeremy Exp $
+// $Header: /cvs/lcd/slic/src/G4Application.cc,v 1.74 2006/11/14 10:27:04 jeremy Exp $
 #include "G4Application.hh"
 
 // slic
@@ -103,15 +103,11 @@
     CmdManager* mgr = CmdManager::instance();
 
     /* Tokenize the command line arguments. */
-    if ( argc > 1 ) {
-      mgr->fillCmdArgs( argc, argv );
-    }
-    /* Did not get any arguments, so print usage. */
-    else {
-      mgr->getG4CmdQueue()->addCmd("/slic/usage");
-    }
+    mgr->fillCmdArgs( argc, argv );
 
-    /* Create a queue of G4 commands from the command-line arguments. */
+    /* 
+     * Create a queue of G4 commands from the command-line arguments. 
+     */
     mgr->fillG4CmdQueue();
   }
 
@@ -309,20 +305,16 @@
   {
     // Get the command manager.
     CmdManager* cmgr = CmdManager::instance();
-
-    // Print usage was selected.
-    if (cmgr->isPrintUsage()) {
-      printUsage(std::cout);
-    }
-
+    
     // Print version was selected.
     if (cmgr->isPrintVersion()) {
       printVersion(std::cout);
     }
-
-    // Run the simulator if not print usage or version.
-    if ((!cmgr->isPrintUsage()) && (!cmgr->isPrintVersion())) {
-
+    // Print usage was selected.
+    else if (cmgr->isPrintUsage()) {
+      printUsage(std::cout);
+    }
+    else {
       // Initialize.
       if (!m_isInitialized) {
 	initialize();
@@ -346,6 +338,8 @@
 
   void G4Application::printUsage(std::ostream& os)
   {
+    printVersion(os);
+
     os << std::endl;
     os << "**************" << std::endl;
     os << "* SLIC Usage *" << std::endl;
@@ -373,7 +367,7 @@
 
   void G4Application::printVersion(std::ostream& os)
   {
-    os << std::endl << PackageInfo::getFullApplicationString() << std::endl << std::endl;
+    os << PackageInfo::getFullApplicationString() << std::endl;
   }
 
   void G4Application::printSplashScreen(std::ostream& os) const
CVSspam 0.2.8