From: westcott Date: Mon, 15 Jun 2009 12:08:39 +0000 (+0000) Subject: removed validcommands and put its checking in commandfactory. X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=commitdiff_plain;h=de2dc9fb831f569b823031d0730f5a0d739e8290 removed validcommands and put its checking in commandfactory. --- diff --git a/Mothur.xcodeproj/project.pbxproj b/Mothur.xcodeproj/project.pbxproj index 6244917..8b890ae 100644 --- a/Mothur.xcodeproj/project.pbxproj +++ b/Mothur.xcodeproj/project.pbxproj @@ -140,7 +140,6 @@ 37D9289B0F21331F001D4494 /* summarysharedcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D9284A0F21331F001D4494 /* summarysharedcommand.cpp */; }; 37D9289C0F21331F001D4494 /* uvest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D9284D0F21331F001D4494 /* uvest.cpp */; }; 37D9289D0F21331F001D4494 /* validcalculator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D9284F0F21331F001D4494 /* validcalculator.cpp */; }; - 37D9289E0F21331F001D4494 /* validcommands.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D928510F21331F001D4494 /* validcommands.cpp */; }; 37D9289F0F21331F001D4494 /* validparameter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D928530F21331F001D4494 /* validparameter.cpp */; }; 37E5F3E30F29FD4200F8D827 /* treenode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37E5F3E20F29FD4200F8D827 /* treenode.cpp */; }; 37E5F4920F2A3DA800F8D827 /* readtreecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37E5F4910F2A3DA800F8D827 /* readtreecommand.cpp */; }; @@ -461,8 +460,6 @@ 37D9284E0F21331F001D4494 /* uvest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = uvest.h; sourceTree = SOURCE_ROOT; }; 37D9284F0F21331F001D4494 /* validcalculator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = validcalculator.cpp; sourceTree = SOURCE_ROOT; }; 37D928500F21331F001D4494 /* validcalculator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = validcalculator.h; sourceTree = SOURCE_ROOT; }; - 37D928510F21331F001D4494 /* validcommands.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = validcommands.cpp; sourceTree = SOURCE_ROOT; }; - 37D928520F21331F001D4494 /* validcommands.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = validcommands.h; sourceTree = SOURCE_ROOT; }; 37D928530F21331F001D4494 /* validparameter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = validparameter.cpp; sourceTree = SOURCE_ROOT; }; 37D928540F21331F001D4494 /* validparameter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = validparameter.h; sourceTree = SOURCE_ROOT; }; 37E3ED800F4D9D0D00B5DF02 /* mothur.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mothur.h; sourceTree = SOURCE_ROOT; }; @@ -907,8 +904,6 @@ children = ( 37D928500F21331F001D4494 /* validcalculator.h */, 37D9284F0F21331F001D4494 /* validcalculator.cpp */, - 37D928520F21331F001D4494 /* validcommands.h */, - 37D928510F21331F001D4494 /* validcommands.cpp */, 37D928540F21331F001D4494 /* validparameter.h */, 37D928530F21331F001D4494 /* validparameter.cpp */, ); @@ -1029,7 +1024,6 @@ 37D9289B0F21331F001D4494 /* summarysharedcommand.cpp in Sources */, 37D9289C0F21331F001D4494 /* uvest.cpp in Sources */, 37D9289D0F21331F001D4494 /* validcalculator.cpp in Sources */, - 37D9289E0F21331F001D4494 /* validcommands.cpp in Sources */, 37D9289F0F21331F001D4494 /* validparameter.cpp in Sources */, 372E12700F26365B0095CF7E /* readotucommand.cpp in Sources */, 372E12960F263D5A0095CF7E /* readdistcommand.cpp in Sources */, diff --git a/commandfactory.cpp b/commandfactory.cpp index eeaf8ee..7dd35fd 100644 --- a/commandfactory.cpp +++ b/commandfactory.cpp @@ -57,6 +57,48 @@ CommandFactory::CommandFactory(){ string s = ""; command = new NoCommand(s); + + + //initialize list of valid commands + commands["read.dist"] = "read.dist"; + commands["read.otu"] = "read.otu"; + commands["read.tree"] = "read.tree"; + commands["bin.seqs"] = "bin.seqs"; + commands["get.oturep"] = "get.oturep"; + commands["cluster"] = "cluster"; + commands["unique.seqs"] = "unique.seqs"; + commands["dist.seqs"] = "dist.seqs"; + commands["dist.shared"] = "dist.shared"; + commands["collect.single"] = "collect.single"; + commands["collect.shared"] = "collect.shared"; + commands["rarefaction.single"] = "rarefaction.single"; + commands["rarefaction.shared"] = "rarefaction.shared"; + commands["summary.single"] = "summary.single"; + commands["summary.shared"] = "summary.shared"; + commands["parsimony"] = "parsimony"; + commands["unifrac.weighted"] = "unifrac.weighted"; + commands["unifrac.unweighted"] = "unifrac.unweighted"; + commands["libshuff"] = "libshuff"; + commands["tree.shared"] = "tree.shared"; + commands["heatmap.bin"] = "heatmap.bin"; + commands["heatmap.sim"] = "heatmap.sim"; + commands["venn"] = "venn"; + commands["get.group"] = "get.group"; + commands["get.label"] = "get.label"; + commands["get.line"] = "get.line"; + commands["get.sabund"] = "get.sabund"; + commands["get.rabund"] = "get.rabund"; + commands["bootstrap.shared"] = "bootstrap.shared"; + commands["concensus"] = "concensus"; + commands["help"] = "help"; + commands["filter.seqs"] = "filter.seqs"; + commands["align.seqs"] = "align.seqs"; + commands["summary.seqs"] = "summary.seqs"; + commands["screen.seqs"] = "screen.seqs"; + commands["reverse.seqs"] = "reverse.seqs"; + commands["trim.seqs"] = "trim.seqs"; + commands["quit"] = "quit"; + } /***********************************************************/ @@ -126,5 +168,54 @@ Command* CommandFactory::getCommand(string commandName, string optionString){ } } -/***********************************************************/ + +/***********************************************************************/ +bool CommandFactory::isValidCommand(string command) { + try { + + //is the command in the map + if ((commands.find(command)) != (commands.end())) { + return true; + }else{ + cout << command << " is not a valid command in Mothur. Valid commands are "; + for (it = commands.begin(); it != commands.end(); it++) { + cout << it->first << ", "; + } + cout << endl; + return false; + } + + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the CommandFactory class Function isValidCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the CommandFactory class function isValidCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} + +/***********************************************************************/ +void CommandFactory::printCommands(ostream& out) { + try { + out << "Valid commands are "; + for (it = commands.begin(); it != commands.end(); it++) { + out << it->first << ", "; + } + out << endl; + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the CommandFactory class Function printCommands. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the CommandFactory class function printCommands. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} +/***********************************************************************/ + + + diff --git a/commandfactory.hpp b/commandfactory.hpp index e3eea41..0cede38 100644 --- a/commandfactory.hpp +++ b/commandfactory.hpp @@ -19,8 +19,15 @@ public: CommandFactory(); ~CommandFactory(); Command* getCommand(string, string); + bool isValidCommand(string); + void printCommands(ostream&); + private: Command* command; + map commands; + map::iterator it; + + }; diff --git a/helpcommand.cpp b/helpcommand.cpp index 4a97342..93def59 100644 --- a/helpcommand.cpp +++ b/helpcommand.cpp @@ -12,9 +12,11 @@ //********************************************************************************************************************** HelpCommand::HelpCommand(string option){ + + + if (option != "") { cout << "There are no valid parameters for the help() command." << endl; } - if (option != "") { cout << "There are no valid parameters for the help() command." << endl; } - validCommands = new ValidCommands(); + validCommands = new CommandFactory(); } //********************************************************************************************************************** diff --git a/helpcommand.h b/helpcommand.h index 4e68388..f6a4aa3 100644 --- a/helpcommand.h +++ b/helpcommand.h @@ -12,8 +12,7 @@ /* This class is designed to aid the user in running mothur. */ #include "command.hpp" -#include "validcommands.h" - +#include "commandfactory.hpp" class HelpCommand : public Command { @@ -24,7 +23,7 @@ public: void help() {}; private: - ValidCommands* validCommands; + CommandFactory* validCommands; private: diff --git a/nocommands.cpp b/nocommands.cpp index 9ac565b..18a2948 100644 --- a/nocommands.cpp +++ b/nocommands.cpp @@ -8,7 +8,6 @@ */ #include "nocommands.h" -#include "validcommands.h" //********************************************************************************************************************** @@ -24,7 +23,7 @@ int NoCommand::execute(){ //Could choose to give more help here?fdsah cout << "Invalid command." << "\n"; - ValidCommands* valid = new ValidCommands(); + CommandFactory* valid = new CommandFactory(); valid->printCommands(cout); delete valid; diff --git a/nocommands.h b/nocommands.h index 2da23d9..5b84b65 100644 --- a/nocommands.h +++ b/nocommands.h @@ -12,6 +12,7 @@ /* This command is run if the user enters an invalid command. */ #include "command.hpp" +#include "commandfactory.hpp" class NoCommand : public Command { diff --git a/validcommands.cpp b/validcommands.cpp deleted file mode 100644 index e5f93a9..0000000 --- a/validcommands.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* - * validcommands.cpp - * Dotur - * - * Created by Sarah Westcott on 1/5/09. - * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. - * - */ - -#include "validcommands.h" - -/***********************************************************************/ - -ValidCommands::ValidCommands() { - try { - - commands["read.dist"] = "read.dist"; - commands["read.otu"] = "read.otu"; - commands["read.tree"] = "read.tree"; - commands["bin.seqs"] = "bin.seqs"; - commands["get.oturep"] = "get.oturep"; - commands["cluster"] = "cluster"; - commands["unique.seqs"] = "unique.seqs"; - commands["dist.seqs"] = "dist.seqs"; - commands["dist.shared"] = "dist.shared"; - commands["collect.single"] = "collect.single"; - commands["collect.shared"] = "collect.shared"; - commands["rarefaction.single"] = "rarefaction.single"; - commands["rarefaction.shared"] = "rarefaction.shared"; - commands["summary.single"] = "summary.single"; - commands["summary.shared"] = "summary.shared"; - commands["parsimony"] = "parsimony"; - commands["unifrac.weighted"] = "unifrac.weighted"; - commands["unifrac.unweighted"] = "unifrac.unweighted"; - commands["libshuff"] = "libshuff"; - commands["tree.shared"] = "tree.shared"; - commands["heatmap.bin"] = "heatmap.bin"; - commands["heatmap.sim"] = "heatmap.sim"; - commands["venn"] = "venn"; - commands["get.group"] = "get.group"; - commands["get.label"] = "get.label"; - commands["get.line"] = "get.line"; - commands["get.sabund"] = "get.sabund"; - commands["get.rabund"] = "get.rabund"; - commands["bootstrap.shared"] = "bootstrap.shared"; - commands["concensus"] = "concensus"; - commands["help"] = "help"; - commands["filter.seqs"] = "filter.seqs"; - commands["align.seqs"] = "align.seqs"; - commands["summary.seqs"] = "summary.seqs"; - commands["screen.seqs"] = "screen.seqs"; - commands["reverse.seqs"] = "reverse.seqs"; - commands["trim.seqs"] = "trim.seqs"; - commands["quit"] = "quit"; - - - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the ValidCommands class Function ValidCommands. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the ValidCommands class function ValidCommands. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} - -/***********************************************************************/ - -ValidCommands::~ValidCommands() {} - -/***********************************************************************/ -bool ValidCommands::isValidCommand(string command) { - try { - - //is the command in the map - if ((commands.find(command)) != (commands.end())) { - return true; - }else{ - cout << command << " is not a valid command in Mothur. Valid commands are "; - for (it = commands.begin(); it != commands.end(); it++) { - cout << it->first << ", "; - } - cout << endl; - return false; - } - - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the ValidCommands class Function isValidCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the ValidCommands class function isValidCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} - -/***********************************************************************/ -void ValidCommands::printCommands(ostream& out) { - try { - out << "Valid commands are "; - for (it = commands.begin(); it != commands.end(); it++) { - out << it->first << ", "; - } - out << endl; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the ValidCommands class Function printCommands. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the ValidCommands class function printCommands. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} - - - - diff --git a/validcommands.h b/validcommands.h deleted file mode 100644 index 091281e..0000000 --- a/validcommands.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef VALIDCOMMANDS_H -#define VALIDCOMMANDS_H - -/* - * validcommands.h - * Dotur - * - * Created by Sarah Westcott on 1/5/09. - * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. - * - */ - -#include "mothur.h" - -//This class contains a list of all valid commands in Mothur. -//It has a function which will tell you if your command is valid. -//When adding a new command you must add it to the valid list in the class constructor. - -class ValidCommands { - - public: - ValidCommands(); - ~ValidCommands(); - bool isValidCommand(string); - void printCommands(ostream&); - private: - map commands; - map::iterator it; - -}; - -#endif