- Rewrote Command::factory to construct all commands, indexed by
  primary command keyword.
This commit is contained in:
Paul Beckingham
2011-05-23 22:12:40 -04:00
parent f53d509930
commit 8e4a757200
3 changed files with 16 additions and 17 deletions

View File

@@ -37,20 +37,15 @@
extern Context context; extern Context context;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Command* Command::factory (const std::string& name) void Command::factory (std::map <std::string, Command*>& all)
{ {
Command* command; Command* c;
if (name == "execute") command = new CmdExec ();
else if (name == "help") command = new CmdHelp ();
else if (name == "install") command = new CmdInstall ();
else if (name == "tip") command = new CmdTip ();
else if (name == "_logo") command = new CmdLogo ();
else
throw std::string ("Unrecognized command object '") + name + "'";
// TODO Initialize command object. c = new CmdExec (); all[c->keyword ()] = c;
c = new CmdHelp (); all[c->keyword ()] = c;
return command; c = new CmdInstall (); all[c->keyword ()] = c;
c = new CmdLogo (); all[c->keyword ()] = c;
c = new CmdTip (); all[c->keyword ()] = c;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@@ -27,6 +27,7 @@
#ifndef INCLUDED_COMMAND #ifndef INCLUDED_COMMAND
#define INCLUDED_COMMAND #define INCLUDED_COMMAND
#include <map>
#include <string> #include <string>
class Command class Command
@@ -38,7 +39,7 @@ public:
bool operator== (const Command&) const; // TODO Is this necessary? bool operator== (const Command&) const; // TODO Is this necessary?
virtual ~Command (); virtual ~Command ();
static Command* factory (const std::string&); static void factory (std::map <std::string, Command*>&);
std::string keyword () const; std::string keyword () const;
std::string usage () const; std::string usage () const;

View File

@@ -250,10 +250,13 @@ int handleCustomReport (const std::string& report, std::string& outs)
view.colorOdd (alternate); view.colorOdd (alternate);
view.intraColorOdd (alternate); view.intraColorOdd (alternate);
// Add the columns. // Add the columns and labels.
std::vector <std::string>::iterator it; for (int i = 0; i < columns.size (); ++i)
for (it = columns.begin (); it != columns.end (); ++it) {
view.add (Column::factory (*it, report)); Column* c = Column::factory (columns[i], report);
c->setLabel (labels[i]);
view.add (c);
}
// How many lines taken up by table header? // How many lines taken up by table header?
int table_header; int table_header;