]> git.donarmstrong.com Git - mothur.git/blob - commandfactory.cpp
49d197c40b9fe215f8067fa8d8a8f6ddb262f45c
[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 "readdistcommand.h"
12 #include "readotucommand.h"
13 #include "readlistcommand.h"
14 #include "clustercommand.h"
15 #include "parselistcommand.h"
16 #include "collectcommand.h"
17 #include "collectsharedcommand.h"
18 #include "rarefactcommand.h"
19 #include "summarycommand.h"
20 #include "summarysharedcommand.h"
21 #include "rarefactsharedcommand.h"
22 #include "nocommand.h"
23 #include "quitcommand.h"
24 #include "helpcommand.h"
25 #include "commandfactory.hpp"
26 #include "deconvolutecommand.h"
27 #include <exception>
28
29
30 /***********************************************************/
31
32 /***********************************************************/
33 CommandFactory::CommandFactory(){
34         command = new NoCommand();
35 }
36
37 /***********************************************************/
38
39 /***********************************************************/
40 CommandFactory::~CommandFactory(){
41         delete command;
42 }
43
44 /***********************************************************/
45
46 /***********************************************************/
47 //This function calls the appropriate command fucntions based on user input.
48 Command* CommandFactory::getCommand(string commandName){
49         try {
50                 delete command;   //delete the old command
51
52                          if(commandName == "read.dist")                         {       command = new ReadDistCommand();                }
53                 else if(commandName == "read.otu")                              {       command = new ReadOtuCommand();                 }
54                 else if(commandName == "read.list")                             {       command = new ReadListFileCommand();    }
55                 else if(commandName == "cluster")                               {       command = new ClusterCommand();                 }
56                 else if(commandName == "deconvolute")                   {       command = new DeconvoluteCommand();             }
57                 else if(commandName == "help")                                  {       command = new HelpCommand();                    }
58                 else if(commandName == "quit")                                  {       command = new QuitCommand();                    }
59                 else if(commandName == "collect.single")                {       command = new CollectCommand();                 }
60                 else if(commandName == "collect.shared")                {       command = new CollectSharedCommand();   }
61                 else if(commandName == "rarefaction.single")    {       command = new RareFactCommand();                }
62                 else if(commandName == "rarefaction.shared")    {       command = new RareFactSharedCommand();  }
63                 else if(commandName == "summary.single")                {       command = new SummaryCommand();                 }
64                 else if(commandName == "summary.shared")                {       command = new SummarySharedCommand();   }
65                 else                                                                                    {       command = new NoCommand();                              }
66
67                 return command;
68         }
69         catch(exception& e) {
70                 cout << "Standard Error: " << e.what() << " has occurred in the CommandFactory class Function getCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
71                 exit(1);
72         }
73         catch(...) {
74                 cout << "An unknown error has occurred in the CommandFactory class function getCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
75                 exit(1);
76         }
77
78 }
79 /***********************************************************/
80
81 /***********************************************************/