[cig-commits] r11516 - cs/benchmark/cigma/trunk/src

luis at geodynamics.org luis at geodynamics.org
Mon Mar 24 09:27:01 PDT 2008


Author: luis
Date: 2008-03-24 09:27:01 -0700 (Mon, 24 Mar 2008)
New Revision: 11516

Modified:
   cs/benchmark/cigma/trunk/src/CommandSet.cpp
   cs/benchmark/cigma/trunk/src/HelpCmd.cpp
   cs/benchmark/cigma/trunk/src/HelpCmd.h
Log:
Preserve the order in which help for each command is displayed


Modified: cs/benchmark/cigma/trunk/src/CommandSet.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/CommandSet.cpp	2008-03-24 16:26:59 UTC (rev 11515)
+++ cs/benchmark/cigma/trunk/src/CommandSet.cpp	2008-03-24 16:27:01 UTC (rev 11516)
@@ -39,12 +39,13 @@
     //addCommand(new SkelCmd());
 
     /* once assembled, pass set of commands to help command */
-    help->setCmdMap(&commands);
+    help->setCommandSet(this);
 }
 
 void cigma::CommandSet::addCommand(Command *cmd)
 {
     assert(cmd != 0);
+    names.push_back(cmd->name);
     commands[cmd->name] = cmd;
 }
 

Modified: cs/benchmark/cigma/trunk/src/HelpCmd.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/HelpCmd.cpp	2008-03-24 16:26:59 UTC (rev 11515)
+++ cs/benchmark/cigma/trunk/src/HelpCmd.cpp	2008-03-24 16:27:01 UTC (rev 11516)
@@ -3,6 +3,7 @@
 #include "HelpCmd.h"
 #include "CommandSet.h"
 
+using namespace std;
 using namespace cigma;
 
 // ---------------------------------------------------------------------------
@@ -10,7 +11,7 @@
 HelpCmd::HelpCmd()
 {
     name = "help";
-    commands = 0;
+    cmdset = 0;
 }
 
 
@@ -19,19 +20,18 @@
 }
 
 
-void HelpCmd::setCmdMap(CommandSet::CmdMap *cmds)
+void HelpCmd::setCommandSet(CommandSet *cmdset)
 {
-    /* pointer to set of commands */
-    this->commands = cmds;
+    this->cmdset = cmdset;
 
     /* prepare usage list from current set of commands */
     usageList.clear();
     std::string prefix = "   ";
-    CommandSet::CmdMap::iterator it;
-    for (it = commands->begin(); it != commands->end(); ++it)
+
+    CommandSet::CmdNames::iterator it;
+    for (it = cmdset->names.begin(); it != cmdset->names.end(); ++it)
     {
-        Command *cmd = it->second;
-        usageList.push_back(prefix + (cmd->name));
+        usageList.push_back(prefix + (*it));
     }
 }
 
@@ -94,9 +94,11 @@
 {
     //std::cout << "Calling cigma::HelpCmd::run()" << std::endl;
 
-    CommandSet::CmdMap::iterator it = commands->find(subcommand);
 
-    if (it != commands->end())
+    /* display help for appropriate subcommand */
+    CommandSet::CmdMap::iterator it = cmdset->commands.find(subcommand);
+
+    if (it != cmdset->commands.end())
     {
         AnyOption opt;
         Command *cmd = it->second;
@@ -106,9 +108,7 @@
     }
     else
     {
-        std::cerr << "Unknown command: '"
-                  << subcommand
-                  << "'" << std::endl;
+        cerr << "Unknown command: '" << subcommand << "'" << endl;
     }
 
     return 1;

Modified: cs/benchmark/cigma/trunk/src/HelpCmd.h
===================================================================
--- cs/benchmark/cigma/trunk/src/HelpCmd.h	2008-03-24 16:26:59 UTC (rev 11515)
+++ cs/benchmark/cigma/trunk/src/HelpCmd.h	2008-03-24 16:27:01 UTC (rev 11516)
@@ -29,10 +29,10 @@
     int run();
 
 public:
-    void setCmdMap(CommandSet::CmdMap *cmds);
+    void setCommandSet(CommandSet *cmdset);
 
 public:
-    CommandSet::CmdMap *commands;
+    CommandSet *cmdset;
     std::string subcommand;
     std::vector<std::string> usageList;
 };



More information about the cig-commits mailing list