]> git.donarmstrong.com Git - mothur.git/blob - commandoptionparser.cpp
Initial revision
[mothur.git] / commandoptionparser.cpp
1 /*
2  *  commandoptionparser.cpp
3  *  
4  *
5  *  Created by Pat Schloss on 10/23/08.
6  *  Copyright 2008 Patrick D. Schloss. All rights reserved.
7  *
8  */
9
10 #include <string>
11
12 using namespace std;
13
14 #include "globaldata.hpp"
15 #include "commandoptionparser.hpp"
16 #include <exception>
17 #include <iostream>
18
19 //**********************************************************************************************************************
20 //This Function parses through the command line and pulls out the command then sends the options to  the parseGlobalData
21 CommandOptionParser::CommandOptionParser(string input){
22         try {
23                 int openParen = input.find_first_of('(');
24                 int closeParen = input.find_last_of(')');
25                 string optionString = "";
26                 commandString = "";
27         
28                 if(openParen != -1 && closeParen != -1){                        
29                         commandString = input.substr(0, openParen);   //commandString contains everything before "("
30                         optionString = input.substr(openParen+1, closeParen-openParen-1); //optionString contains everything between "(" and ")".
31                 }
32                                         
33                 GlobalData* globaldata = GlobalData::getInstance();
34                 globaldata->parseGlobalData(commandString, optionString);                       //parser to separate and check options
35         }
36         catch(exception& e) {
37                 cout << "Standard Error: " << e.what() << " has occurred in the CommandOptionParser class Function CommandOptionParser. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
38                 exit(1);
39         }
40         catch(...) {
41                 cout << "An unknown error has occurred in the CommandOptionParser class function CommandOptionParser. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
42                 exit(1);
43         }
44
45 }
46
47 //**********************************************************************************************************************
48
49 string CommandOptionParser::getCommandString()  {       return commandString;   }
50
51 //**********************************************************************************************************************