]> git.donarmstrong.com Git - mothur.git/blob - commandfactory.cpp
Initial revision
[mothur.git] / commandfactory.cpp
1 /*
2  *  commandfactory.cpp
3  *  
4  *
5  *  Created by Pat Schloss on 10/25/08.
6  *  Copyright 2008 Patrick D. Schloss. All rights reserved.
7  *
8  */
9
10 #include "command.hpp"
11 #include "readdistphylipfilecommand.h"
12 #include "readdistcolumnfilecommand.h"
13 #include "readlistfilecommand.h"
14 #include "readrabundfilecommand.h"
15 #include "readsabundfilecommand.h"
16 #include "readsharedfilecommand.h"
17 #include "clustercommand.h"
18 #include "parselistcommand.h"
19 #include "sharedcommand.h"
20 #include "collectcommand.h"
21 #include "collectsharedcommand.h"
22 #include "rarefactcommand.h"
23 #include "summarycommand.h"
24 #include "summarysharedcommand.h"
25 #include "rarefactsharedcommand.h"
26 #include "nocommand.h"
27 #include "quitcommand.h"
28 #include "helpcommand.h"
29 #include "commandfactory.hpp"
30 #include <exception>
31
32
33 /***********************************************************/
34
35 /***********************************************************/
36 CommandFactory::CommandFactory(){
37         command = new NoCommand();
38 }
39
40 /***********************************************************/
41
42 /***********************************************************/
43 CommandFactory::~CommandFactory(){
44         delete command;
45 }
46
47 /***********************************************************/
48
49 /***********************************************************/
50 //This function calls the appropriate command fucntions based on user input.
51 Command* CommandFactory::getCommand(string commandName){
52         try {
53                 delete command;   //delete the old command
54
55                          if(commandName == "read.phylip")                       {       command = new ReadDistPhylipFileCommand();      }
56                 else if(commandName == "read.column")                   {       command = new ReadDistColumnFileCommand();      }
57                 else if(commandName == "read.list")                             {       command = new ReadListFileCommand();    }
58                 else if(commandName == "read.rabund")                   {       command = new ReadRAbundFileCommand();  }
59                 else if(commandName == "read.sabund")                   {       command = new ReadSAbundFileCommand();  }
60                 else if(commandName == "read.shared")                   {       command = new ReadSharedFileCommand();  }
61                 else if(commandName == "cluster")                               {       command = new ClusterCommand();                 }
62                 else if(commandName == "help")                                  {       command = new HelpCommand();                    }
63                 else if(commandName == "quit")                                  {       command = new QuitCommand();                    }
64                 else if(commandName == "collect.single")                {       command = new CollectCommand();                 }
65                 else if(commandName == "shared")                                {       command = new SharedCommand();                  }
66                 else if(commandName == "collect.shared")                {       command = new CollectSharedCommand();   }
67                 else if(commandName == "rarefaction.single")    {       command = new RareFactCommand();                }
68                 else if(commandName == "rarefaction.shared")    {       command = new RareFactSharedCommand();  }
69                 else if(commandName == "summary.single")                {       command = new SummaryCommand();                 }
70                 else if(commandName == "summary.shared")                {       command = new SummarySharedCommand();   }
71                 else if(commandName == "parselist")                             {       command = new ParseListCommand();               }
72                 else                                                                                    {       command = new NoCommand();                              }
73
74                 return command;
75         }
76         catch(exception& e) {
77                 cout << "Standard Error: " << e.what() << " has occurred in the CommandFactory class Function getCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
78                 exit(1);
79         }
80         catch(...) {
81                 cout << "An unknown error has occurred in the CommandFactory class function getCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
82                 exit(1);
83         }
84
85 }
86 /***********************************************************/
87
88 /***********************************************************/