CommandLineArg Class Reference

#include <SSAHAMain.h>

Inheritance diagram for CommandLineArg:

Inheritance graph
[legend]
List of all members.

Public Member Functions

 CommandLineArg (const string &nameLong, const string &nameShort)
virtual bool isThisMe (const string &argName)
virtual void addValue (const string &value)=0

Static Public Member Functions

static void parseCommandLine (int numArgs, char *args[], QueryParameterStruct &queryParams)

Protected Attributes

string nameLong_
string nameShort_

Detailed Description

Definition at line 161 of file SSAHAMain.h.


Constructor & Destructor Documentation

CommandLineArg::CommandLineArg ( const string &  nameLong,
const string &  nameShort 
) [inline]

Definition at line 175 of file SSAHAMain.h.

00175                                                                     :
00176     nameLong_( nameLong ), nameShort_( nameShort ) {}
  // Is the current argument equal to 'my' argument name?


Member Function Documentation

void CommandLineArg::parseCommandLine ( int  numArgs,
char *  args[],
QueryParameterStruct queryParams 
) [static]

Definition at line 158 of file SSAHAMain.cpp.

References QueryParameterStruct::bandExtension, QueryParameterStruct::doAlignment, QueryParameterStruct::logMode, QueryParameterStruct::maxGap, QueryParameterStruct::maxInsert, QueryParameterStruct::maxStore, QueryParameterStruct::minPrint, QueryParameterStruct::numRepeats, QueryParameterStruct::packHits, QueryParameterStruct::parserFriendly, QueryParameterStruct::printHashStats, QueryParameterStruct::queryEnd, QueryParameterStruct::queryFormat, QueryParameterStruct::queryName, QueryParameterStruct::queryReplace, QueryParameterStruct::queryStart, QueryParameterStruct::queryType, QueryParameterStruct::reverseQuery, QueryParameterStruct::runQuery, QueryParameterStruct::saveName, QueryParameterStruct::sortMatches, QueryParameterStruct::stepLength, QueryParameterStruct::subjectFormat, QueryParameterStruct::subjectName, QueryParameterStruct::subjectReplace, QueryParameterStruct::subjectType, QueryParameterStruct::substituteThreshold, and QueryParameterStruct::wordLength.

Referenced by main().

00159 {
00160 
00161   int firstArg;
00162 
00163   // Add mandatory parameters
00164   if ( (args[2])[0] == '-' )
00165   {
00166     // then only one file name given: assume this is a subject file
00167     // to be hashed
00168     firstArg = 2;
00169     queryParams.subjectName = (string) args[1];
00170     queryParams.runQuery = false; 
00171   }
00172   else
00173   {
00174     // two file names given: assume first is query, second is subject
00175     firstArg = 3;
00176     queryParams.queryName   = (string) args[1];
00177     queryParams.subjectName = (string) args[2];
00178   }
00179 
00180   // Parse options
00181   vector<CommandLineArg*> validArgs;
00182   validArgs.push_back
00183   ( new CommandLineArgInt( "-wordLength", "-wl", queryParams.wordLength ) );
00184   validArgs.push_back
00185   ( new CommandLineArgInt( "-stepLength", "-sl", queryParams.stepLength ) );
00186   validArgs.push_back
00187   ( new CommandLineArgInt( "-maxStore", "-ms", queryParams.maxStore ) );
00188   validArgs.push_back
00189   ( new CommandLineArgInt( "-minPrint", "-mp", queryParams.minPrint ) );
00190   validArgs.push_back
00191   ( new CommandLineArgInt( "-maxGap", "-mg", queryParams.maxGap ) );
00192   validArgs.push_back
00193   ( new CommandLineArgInt( "-maxInsert", "-mi", queryParams.maxInsert ) );
00194   validArgs.push_back
00195   ( new CommandLineArgInt( "-numRepeats", "-nr", queryParams.numRepeats ) );
00196   validArgs.push_back
00197   ( new CommandLineArgInt( "-substituteWords", "-sw", 
00198                            queryParams.substituteThreshold ) );
00199   validArgs.push_back
00200   ( new CommandLineArgInt( "-bandExtension", "-be", 
00201                            queryParams.bandExtension ) );
00202   validArgs.push_back
00203   ( new CommandLineArgInt( "-sortMatches", "-sm", queryParams.sortMatches ) );
00204   validArgs.push_back
00205   ( new CommandLineArgInt
00206     ( "-doAlignment", "-da", queryParams.doAlignment ));
00207   validArgs.push_back
00208   ( new CommandLineArgInt( "-queryStart", "-qs", queryParams.queryStart ) );
00209   validArgs.push_back
00210   ( new CommandLineArgInt( "-queryEnd", "-qe", queryParams.queryEnd ) );
00211   validArgs.push_back
00212   ( new CommandLineArgBool( "-hashStats", "-hs", queryParams.printHashStats ));
00213   validArgs.push_back
00214   ( new CommandLineArgBool( "-packHits", "-ph", queryParams.packHits ));
00215   validArgs.push_back
00216   ( new CommandLineArgBool
00217     ( "-reverseQuery", "-rq", queryParams.reverseQuery ));  
00218   validArgs.push_back
00219   ( new CommandLineArgBool
00220     ( "-parserFriendly", "-pf", queryParams.parserFriendly ) );
00221   validArgs.push_back
00222   ( new CommandLineArgString( "-queryType", "-qt", queryParams.queryType ) );
00223   validArgs.push_back
00224   ( new CommandLineArgString( "-subjectType", "-st", queryParams.subjectType));
00225   validArgs.push_back
00226   ( new CommandLineArgString( "-queryFormat", "-qf", queryParams.queryFormat));
00227   validArgs.push_back
00228   ( new CommandLineArgString
00229     ( "-subjectFormat", "-sf", queryParams.subjectFormat) );
00230   //  validArgs.push_back
00231   //  ( new CommandLineArgString( "-reportMode", "-rm", queryParams.reportMode ) );
00232   validArgs.push_back
00233   ( new CommandLineArgString( "-queryReplace", "-qr", queryParams.queryReplace ) );
00234   validArgs.push_back
00235   ( new CommandLineArgString( "-subjectReplace", "-sr", queryParams.subjectReplace ) );
00236   validArgs.push_back
00237   ( new CommandLineArgString( "-logMode", "-lm", queryParams.logMode ) );
00238   validArgs.push_back
00239   ( new CommandLineArgString( "-saveName", "-sn", queryParams.saveName ) );
00240 
00241   string thisArg;
00242   vector<CommandLineArg*>::iterator pArg = validArgs.end();
00243   for ( int i(firstArg); i < numArgs ; i++ )
00244   {
00245     thisArg = (string) args[i];
00246     if (pArg != validArgs.end()) 
00247     // ... then an instance of CommandLineArg is waiting to parse the current
00248     // command line arg
00249     { 
00250       (*pArg)->addValue( thisArg ); 
00251       pArg = validArgs.end(); 
00252     } // ~if
00253     else
00254     // ... trawl through the list of command line args and see if any of 'em
00255     // recognize the current command line arg
00256     { 
00257       for (pArg = validArgs.begin() ; pArg != validArgs.end(); ++pArg )
00258       {
00259         if ( (*pArg)->isThisMe(thisArg) ) break; // *pArg recognizes the arg
00260       } // ~for      
00261       if ( pArg == validArgs.end() )
00262       // ... then the argument has not been recognized - complain!
00263       {
00264         cerr << "Error: command line argument " << thisArg << " not found.\n";
00265         exit(1);
00266       } // ~if
00267 
00268       // if pArg is an instance of type CommandLineArgBool, then there is
00269       // no associated value, so don't try to read one
00270       if ( dynamic_cast<CommandLineArgBool*>(*pArg)) pArg=validArgs.end();
00271     } // ~else    
00272   } // ~for
00273 
00274   // Deallocate memory
00275   for ( vector<CommandLineArg*>::iterator i = validArgs.begin(); 
00276         i != validArgs.end(); ++i ) delete *i;
00277 
00278 
00279 } // ~parseCommandLine

Here is the caller graph for this function:

virtual bool CommandLineArg::isThisMe ( const string &  argName  )  [inline, virtual]

Reimplemented in CommandLineArgBool.

Definition at line 178 of file SSAHAMain.h.

References nameLong_, and nameShort_.

00179   { 
00180     return ( ( argName == nameLong_ ) || ( argName == nameShort_ ) );
00181   }

virtual void CommandLineArg::addValue ( const string &  value  )  [pure virtual]

Implemented in CommandLineArgString, CommandLineArgInt, and CommandLineArgBool.


Member Data Documentation

string CommandLineArg::nameLong_ [protected]

Definition at line 184 of file SSAHAMain.h.

Referenced by CommandLineArgBool::isThisMe(), and isThisMe().

string CommandLineArg::nameShort_ [protected]

Definition at line 185 of file SSAHAMain.h.

Referenced by CommandLineArgBool::isThisMe(), and isThisMe().


The documentation for this class was generated from the following files:
Generated on Fri Dec 21 13:15:48 2007 for ssaha by  doxygen 1.5.2