]> git.donarmstrong.com Git - mothur.git/blob - commandfactory.cpp
dbcfb54be8c09fbf6177ad2d4ed10be8773d0358
[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 "readtreecommand.h"
13 #include "readotucommand.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 "parsimonycommand.h"
28 #include "unifracunweightedcommand.h"
29 #include "unifracweightedcommand.h"
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.dist")                         {       command = new ReadDistCommand();                        }
56                 else if(commandName == "read.otu")                              {       command = new ReadOtuCommand();                         }
57                 else if(commandName == "read.tree")                             {       command = new ReadTreeCommand();                        }
58                 else if(commandName == "cluster")                               {       command = new ClusterCommand();                         }
59                 else if(commandName == "deconvolute")                   {       command = new DeconvoluteCommand();                     }
60                 else if(commandName == "parsimony")                             {       command = new ParsimonyCommand();                       }
61                 else if(commandName == "help")                                  {       command = new HelpCommand();                            }
62                 else if(commandName == "quit")                                  {       command = new QuitCommand();                            }
63                 else if(commandName == "collect.single")                {       command = new CollectCommand();                         }
64                 else if(commandName == "collect.shared")                {       command = new CollectSharedCommand();           }
65                 else if(commandName == "rarefaction.single")    {       command = new RareFactCommand();                        }
66                 else if(commandName == "rarefaction.shared")    {       command = new RareFactSharedCommand();          }
67                 else if(commandName == "summary.single")                {       command = new SummaryCommand();                         }
68                 else if(commandName == "summary.shared")                {       command = new SummarySharedCommand();           }
69                 else if(commandName == "unifrac.weighted")              {       command = new UnifracWeightedCommand();         }
70                 else if(commandName == "unifrac.unweighted")    {       command = new UnifracUnweightedCommand();       }
71                 else                                                                                    {       command = new NoCommand();                                      }
72                         
73                 return command;
74         }
75         catch(exception& e) {
76                 cout << "Standard Error: " << e.what() << " has occurred in the CommandFactory class Function getCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
77                 exit(1);
78         }
79         catch(...) {
80                 cout << "An unknown error has occurred in the CommandFactory class function getCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
81                 exit(1);
82         }
83
84 }
85 /***********************************************************/
86