![]() |
Mixed Data Coincidence Analysis Software 1.0
A program to analyze files produced by the EventMixer software.
|
Interprets command line arguments according to a list of CommandLineArguments (acceptable flags), and throws an exception if unknown flags are encountered. More...
#include <CommandLineInterpreter.hh>
Public Member Functions | |||
CommandLineInterpreter (int argc, char *argv[], list< CommandLineArgument > myAcceptableFlags) | |||
Constructor.
| |||
vector< string > | readFlaggedCommand (string flag) | ||
Returns a vector<string> containing all arguments for a specific flag. Returns an empty vector if there are no arguments for this flag. | |||
vector< string > | readFlaglessCommands () | ||
Returns all arguments without flags. | |||
Private Attributes | |||
map< string, vector< string > > | myFlaggedCommands | ||
The current flagged commands. | |||
vector< string > | myFlaglessCommands | ||
The current flagless commands. |
Interprets command line arguments according to a list of CommandLineArguments (acceptable flags), and throws an exception if unknown flags are encountered.
Definition at line 42 of file CommandLineInterpreter.hh.
CommandLineInterpreter::CommandLineInterpreter | ( | int | argc, |
char * | argv[], | ||
list< CommandLineArgument > | myAcceptableFlags | ||
) |
Constructor.
CommandLineException | if the CommandLineArguments does not match argv and argc (if there are unknown flags). |
argc | The number of command line arguments. |
argv | The actual arguments. |
myAcceptableFlags | The flags which should be accepted by this interpreter. |
Definition at line 3 of file CommandLineInterpreter.cc.
References myFlaggedCommands, and myFlaglessCommands.
{ for(int i = 0; i<argc; i++) { string temp(argv[i]); if(temp[0]=='-') //we have a flag... { temp = temp.substr(1,temp.size()); bool found = false; for(list<CommandLineArgument>::iterator it = myAcceptableFlags.begin(); it!=myAcceptableFlags.end(); it++) { if(temp.compare(it->flag)==0) { if(i+it->numberOfArguments>argc) throw CommandLineException("Insufficient arguments for flag.\n"); vector<string> myList; for(int k = i+1; k<=i+it->numberOfArguments; k++) { string tmp(argv[k]); myList.push_back(tmp); } myFlaggedCommands[temp] = myList; i+=it->numberOfArguments; found=true; } } if(!found) throw CommandLineException("Command flag not recognized"); } else { myFlaglessCommands.push_back(argv[i]); } } }
vector< string > CommandLineInterpreter::readFlaggedCommand | ( | string | flag | ) |
Returns a vector<string> containing all arguments for a specific flag. Returns an empty vector if there are no arguments for this flag.
flag | The flag to read |
Definition at line 39 of file CommandLineInterpreter.cc.
References myFlaggedCommands.
Referenced by decodeInput(), and initSettings().
{ if(myFlaggedCommands.find(flag)!=myFlaggedCommands.end()) { if(myFlaggedCommands[flag].empty()) myFlaggedCommands[flag].push_back(""); return myFlaggedCommands[flag]; } else { return vector<string>(); } }