OpenASIP  2.0
Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
CmdLineOptions Class Referenceabstract

#include <CmdLineOptions.hh>

Inheritance diagram for CmdLineOptions:
Inheritance graph
Collaboration diagram for CmdLineOptions:
Collaboration graph

Public Member Functions

 CmdLineOptions (std::string description, std::string version="")
 
virtual ~CmdLineOptions ()
 
void parse (char *argv[], int argc)
 
void parse (std::string argv[], int argc)
 
void parse (std::vector< std::string > argv)
 
virtual void printHelp () const
 
virtual void printVersion () const =0
 
virtual bool isVerboseSwitchDefined () const
 
virtual bool isVerboseSpamSwitchDefined () const
 
- Public Member Functions inherited from CmdLineParser
 CmdLineParser (std::string description)
 
virtual ~CmdLineParser ()
 
virtual void storeOptions (Options &options)
 
virtual int numberOfArguments () const
 
virtual std::string argument (int index) const
 

Protected Member Functions

bool optionGiven (std::string key) const
 
- Protected Member Functions inherited from CmdLineParser
void addOption (CmdLineOptionParser *opt)
 
CmdLineOptionParserfindOption (std::string name) const
 
bool parseOption (std::string option, std::string &name, std::string &arguments, std::string &prefix, bool &hasArgument) const
 
bool readPrefix (std::string &option, std::string &prefix, bool &longOption) const
 
bool isPrefix (std::string name) const
 

Private Types

typedef std::map< std::string, CmdLineOptionParser * >::value_type valType
 For adding new values to maps. More...
 
typedef std::map< std::string, CmdLineOptionParser * >::iterator mapIter
 For traversing non-const maps. More...
 
typedef std::map< std::string, CmdLineOptionParser * >::const_iterator constMapIter
 For traversing const maps. More...
 

Private Member Functions

 CmdLineOptions (const CmdLineOptions &)
 Copying not allowed. More...
 
CmdLineOptionsoperator= (const CmdLineOptions &)
 Assignment not allowed. More...
 
void parseAll ()
 

Private Attributes

std::string progName_
 The name of the program. More...
 
std::string description_
 The description of usage of program. More...
 
std::string version_
 The version of the program. More...
 

Static Private Attributes

static const int SHORT_FLAG = 2
 Number of characters reserved for printing short version of commandline flag. More...
 
static const int LONG_FLAG = 22
 Number of characters reserved for printing long version of commandline flag. More...
 
static const std::string VERBOSE_SWITCH = "verbose"
 Switch for verbose output listing scheduler modules. More...
 
static const std::string VERBOSE_SPAM_SWITCH = "verbose_spam"
 Switch for verbose output listing spam from scheduler internals. More...
 

Additional Inherited Members

- Protected Attributes inherited from CmdLineParser
std::map< std::string, CmdLineOptionParser * > optionLongNames_
 Database for holding options with their long names as a key. More...
 
std::map< std::string, CmdLineOptionParser * > optionShortNames_
 Database for holding options with their short names as a key. More...
 
std::vector< std::string > commandLine_
 Command line is stored here. More...
 
std::vector< std::string > arguments_
 Command line arguments are stored here. More...
 
std::vector< std::string > prefixes_
 Legal prefixes are stored here. More...
 

Detailed Description

Abstract base class for command line parsers.

Is capable of storing and parsing commmand line options.

Definition at line 54 of file CmdLineOptions.hh.

Member Typedef Documentation

◆ constMapIter

typedef std::map<std::string, CmdLineOptionParser*>::const_iterator CmdLineOptions::constMapIter
private

For traversing const maps.

Definition at line 77 of file CmdLineOptions.hh.

◆ mapIter

typedef std::map<std::string, CmdLineOptionParser*>::iterator CmdLineOptions::mapIter
private

For traversing non-const maps.

Definition at line 74 of file CmdLineOptions.hh.

◆ valType

typedef std::map<std::string, CmdLineOptionParser*>::value_type CmdLineOptions::valType
private

For adding new values to maps.

Definition at line 72 of file CmdLineOptions.hh.

Constructor & Destructor Documentation

◆ CmdLineOptions() [1/2]

CmdLineOptions::CmdLineOptions ( std::string  description,
std::string  version = "" 
)

Constructor.

Parameters
descriptionBrief description of the program and how to use it. Only prefix is currently "no-".

Definition at line 73 of file CmdLineOptions.cc.

75  :
76  CmdLineParser(description),
77  progName_(""),
78  description_(description),
79  version_(version) {
80 
81  BoolCmdLineOptionParser* verboseSwitch =
83  VERBOSE_SWITCH, "The verbose switch", "v");
84  addOption(verboseSwitch);
85 
86  BoolCmdLineOptionParser* verboseSpamSwitch =
88  VERBOSE_SPAM_SWITCH, "The verbose spam - switch", "V");
89  addOption(verboseSpamSwitch);
90 }

References CmdLineParser::addOption(), VERBOSE_SPAM_SWITCH, and VERBOSE_SWITCH.

Here is the call graph for this function:

◆ ~CmdLineOptions()

CmdLineOptions::~CmdLineOptions ( )
virtual

Destructor.

Definition at line 95 of file CmdLineOptions.cc.

95  {
96 }

◆ CmdLineOptions() [2/2]

CmdLineOptions::CmdLineOptions ( const CmdLineOptions )
private

Copying not allowed.

Member Function Documentation

◆ isVerboseSpamSwitchDefined()

bool CmdLineOptions::isVerboseSpamSwitchDefined ( ) const
virtual

Return true if the verbose spam switch was defined in the command line.

Returns
True if the verbose spam switch was defined in the command line.

Definition at line 310 of file CmdLineOptions.cc.

310  {
312 }

References CmdLineParser::findOption(), CmdLineOptionParser::isDefined(), and VERBOSE_SPAM_SWITCH.

Referenced by GenerateProcessor::generateProcessor(), main(), and Application::setCmdLineOptions().

Here is the call graph for this function:

◆ isVerboseSwitchDefined()

bool CmdLineOptions::isVerboseSwitchDefined ( ) const
virtual

Return true if the verbose switch was defined in the command line.

Returns
True if the verbose switch was defined in the command line.

Reimplemented in LLVMTCECmdLineOptions.

Definition at line 300 of file CmdLineOptions.cc.

300  {
302 }

References CmdLineParser::findOption(), CmdLineOptionParser::isDefined(), and VERBOSE_SWITCH.

Referenced by GenerateProcessor::generateProcessor(), main(), Application::setCmdLineOptions(), and llvm::LLVMTCEIRBuilder::~LLVMTCEIRBuilder().

Here is the call graph for this function:

◆ operator=()

CmdLineOptions& CmdLineOptions::operator= ( const CmdLineOptions )
private

Assignment not allowed.

◆ optionGiven()

bool CmdLineOptions::optionGiven ( std::string  key) const
protected

Returns true if there is a value available for given option.

Returns
True if the option is defined.
Todo:
: This returns always true if trying to find added CmdLineOption...

Definition at line 320 of file CmdLineOptions.cc.

320  {
321  try {
322  /// @todo: This returns always true if trying to find added
323  /// CmdLineOption...
324  return findOption(key)->isDefined();
325  } catch (const IllegalCommandLine&) {
326  return false;
327  }
328  return true;
329 }

References CmdLineParser::findOption(), and CmdLineOptionParser::isDefined().

Referenced by SimulatorCmdLineOptions::backendType(), SimulatorCmdLineOptions::debugMode(), SchedulerCmdLineOptions::dumpIfConversionCFGs(), SchedulerCmdLineOptions::enableOffsetAA(), SchedulerCmdLineOptions::enableStackAA(), SchedulerCmdLineOptions::killDeadResults(), SchedulerCmdLineOptions::printResourceConstraints(), SchedulerCmdLineOptions::renameRegisters(), and SimulatorCmdLineOptions::scriptString().

Here is the call graph for this function:

◆ parse() [1/3]

void CmdLineOptions::parse ( char *  argv[],
int  argc 
)
virtual

Loads all command line arguments and parses them.

Parameters
optionsCommand line options pre-parsed in char* array.
argcThe number of command line options.
Exceptions
IllegalCommandLineIf parsing is not succesfull.
ParserStopRequestIf help or version option is found.

Reimplemented from CmdLineParser.

Definition at line 107 of file CmdLineOptions.cc.

107  {
108  // command line is emptied
109  commandLine_.clear();
110  progName_ = string(argv[0]);
111 
112  for (int i = 1; i < argc; i++) {
113  commandLine_.push_back(string(argv[i]));
114  }
115 
116  parseAll();
117 }

References CmdLineParser::commandLine_, parseAll(), and progName_.

Referenced by GenerateProcessor::generateProcessor(), llvm::LLVMTCEScheduler::LLVMTCEScheduler(), and main().

Here is the call graph for this function:

◆ parse() [2/3]

void CmdLineOptions::parse ( std::string  argv[],
int  argc 
)

Loads all command line arguments and parses them.

Parameters
optionsCommand line options pre-parsed in string array.
argcThe number of command line options.
Exceptions
IllegalCommandLineIf parsing is not succesfull.
ParserStopRequestIf help or version option is found.

Definition at line 128 of file CmdLineOptions.cc.

128  {
129  // command line is emptied
130  commandLine_.clear();
131  progName_ = argv[0];
132 
133  for (int i = 1; i < argc; i++) {
134  commandLine_.push_back(argv[i]);
135  }
136 
137  parseAll();
138 }

References CmdLineParser::commandLine_, parseAll(), and progName_.

Here is the call graph for this function:

◆ parse() [3/3]

void CmdLineOptions::parse ( std::vector< std::string >  argv)
virtual

Loads all command line arguments and parses them.

Parameters
optionsCommand line options pre-parsed in string vector.
Exceptions
IllegalCommandLineIf parsing is not succesfull.
ParserStopRequestIf help or version option is found.

Reimplemented from CmdLineParser.

Definition at line 147 of file CmdLineOptions.cc.

147  {
148  // command line is emptied
149  commandLine_.clear();
150  progName_ = argv.at(0);
151 
152  for (unsigned int i = 1; i < argv.size(); i++) {
153  commandLine_.push_back(argv[i]);
154  }
155 
156  parseAll();
157 }

References CmdLineParser::commandLine_, parseAll(), and progName_.

Here is the call graph for this function:

◆ parseAll()

void CmdLineOptions::parseAll ( )
private

Parses all command line options.

Exceptions
IllegalCommandLineIf parsing fails.
ParserStopRequestThe client should not proceed.

Definition at line 165 of file CmdLineOptions.cc.

165  {
166  // finished is set to true when options are parsed and the rest are
167  // command line arguments
168  bool finished = false;
169 
170  // checkArguments is set to false when command line arguments can start
171  // with "-" or "--"
172  bool checkArguments = true;
173  unsigned int i = 0;
174 
175  while (i < commandLine_.size()) {
176  string optString = commandLine_[i];
177 
178  if (!finished) {
179  string prefix = "";
180  string name = "";
181  string arguments = "";
182 
183  // hasArgument is true when option has argument
184  bool hasArgument = true;
185 
186  if (!parseOption(
187  optString, name, arguments, prefix, hasArgument)) {
188  finished = true;
189  if (optString == "--") {
190  checkArguments = false;
191  i++;
192  continue;
193  } else {
194  arguments_.push_back(optString);
195  i++;
196  continue;
197  }
198  }
199 
200  //
201  if (name == "help" || name == "h") {
202  printHelp();
203  string msg = "The client should not proceed";
204  string method = "CmdLineParser::parseAll()";
205  throw ParserStopRequest(__FILE__, __LINE__, method, msg);
206  } else if (name == "version") {
207  printVersion();
208  string msg = "The client should not proceed";
209  string method = "CmdLineParser::parseAll()";
210  throw ParserStopRequest(__FILE__, __LINE__, method, msg);
211  }
212 
213  CmdLineOptionParser* opt = findOption(name);
214 
215  if (arguments == "" &&
216  dynamic_cast<BoolCmdLineOptionParser*>(opt) == NULL) {
217 
218  // argument for an option may be separated with space
219  if (i < commandLine_.size() - 1 &&
220  commandLine_[i+1].substr(0, 1) != "-") {
221  hasArgument = true;
222  arguments = commandLine_[i+1];
223  i++;
224  }
225  }
226 
227  bool doneWithParsing = opt->parseValue(arguments, prefix);
228 
229  if (!doneWithParsing) {
230  if (hasArgument) {
231  // all the rest in command line are "extra" strings
232  arguments_.push_back(arguments);
233  finished = true;
234  i++;
235  } else {
236  // this is the situation when we have something like
237  // -abcd (multible flags put together)
238  for (unsigned int i = 0; i < arguments.length(); i++) {
239  opt = findOption(arguments.substr(i, 1));
240  opt->parseValue("", prefix);
241  }
242  }
243  }
244  } else {
245 
246  // finished reading options, all rest are command line arguments
247  if (checkArguments && optString[0] == '-') {
248  string msg = "Illegal command line argument: " + optString;
249  string method = "CmdLineOptions::parse()";
250  throw IllegalCommandLine(__FILE__, __LINE__, method, msg);
251  }
252  arguments_.push_back(optString);
253  }
254  i++;
255  }
256 }

References CmdLineParser::arguments_, CmdLineParser::commandLine_, CmdLineParser::findOption(), CmdLineParser::parseOption(), CmdLineOptionParser::parseValue(), printHelp(), and printVersion().

Referenced by parse().

Here is the call graph for this function:

◆ printHelp()

void CmdLineOptions::printHelp ( ) const
virtual

Prints the help menu of the program.

Reimplemented in OsalCmdLineOptions, ProGeCmdLineOptions, PIGCmdLineOptions, TestHDBCmdLineOptions, TTAUnitTesterCmdLineOptions, ExplorerCmdLineOptions, SimulatorCmdLineOptions, BEMGeneratorCmdLineOptions, EstimatorCmdLineOptions, CreateHDBCmdLineOptions, BEMViewerCmdLineOptions, and MachInfoCmdLineOptions.

Definition at line 262 of file CmdLineOptions.cc.

262  {
263  cout << description_ << endl;
264  cout << "Options:" << endl;
265  constMapIter i;
266  for (i = optionLongNames_.begin(); i != optionLongNames_.end(); i++) {
267  CmdLineOptionParser* opt = findOption((*i).first);
268  if (opt->isHidden()) continue;
269  if (opt->shortName() != "") {
270  cout << left << setw(SHORT_FLAG) << "-" + opt->shortName() + ", "
271  << left << setw(LONG_FLAG) << "--" + opt->longName();
272  } else {
273  cout << " "
274  << left << setw(LONG_FLAG) << "--" + opt->longName();
275  }
276 
277  std::stringstream str(opt->description());
278  int charsPrintedInRow = 0;
279  while (!str.eof()) {
280  std::string nextToken = "";
281  str >> nextToken;
282  if (nextToken.size() + charsPrintedInRow > 60) {
283  cout << std::endl;
284  cout << std::left << setw(SHORT_FLAG + LONG_FLAG + 2) << " ";
285  charsPrintedInRow = 0;
286  }
287  cout << nextToken << " ";
288  charsPrintedInRow += nextToken.size();
289  }
290  cout << std::endl;
291  }
292 }

References CmdLineOptionParser::description(), description_, CmdLineParser::findOption(), CmdLineOptionParser::isHidden(), LONG_FLAG, CmdLineOptionParser::longName(), CmdLineParser::optionLongNames_, SHORT_FLAG, and CmdLineOptionParser::shortName().

Referenced by parseAll(), MachInfoCmdLineOptions::printHelp(), EstimatorCmdLineOptions::printHelp(), CreateHDBCmdLineOptions::printHelp(), BEMGeneratorCmdLineOptions::printHelp(), SimulatorCmdLineOptions::printHelp(), ExplorerCmdLineOptions::printHelp(), TTAUnitTesterCmdLineOptions::printHelp(), TestHDBCmdLineOptions::printHelp(), PIGCmdLineOptions::printHelp(), and ProGeCmdLineOptions::printHelp().

Here is the call graph for this function:

◆ printVersion()

virtual void CmdLineOptions::printVersion ( ) const
pure virtual

Member Data Documentation

◆ description_

std::string CmdLineOptions::description_
private

The description of usage of program.

Definition at line 89 of file CmdLineOptions.hh.

Referenced by printHelp().

◆ LONG_FLAG

const int CmdLineOptions::LONG_FLAG = 22
staticprivate

Number of characters reserved for printing long version of commandline flag.

Definition at line 99 of file CmdLineOptions.hh.

Referenced by printHelp().

◆ progName_

std::string CmdLineOptions::progName_
private

The name of the program.

Definition at line 87 of file CmdLineOptions.hh.

Referenced by parse().

◆ SHORT_FLAG

const int CmdLineOptions::SHORT_FLAG = 2
staticprivate

Number of characters reserved for printing short version of commandline flag.

Definition at line 95 of file CmdLineOptions.hh.

Referenced by printHelp().

◆ VERBOSE_SPAM_SWITCH

const std::string CmdLineOptions::VERBOSE_SPAM_SWITCH = "verbose_spam"
staticprivate

Switch for verbose output listing spam from scheduler internals.

Definition at line 105 of file CmdLineOptions.hh.

Referenced by CmdLineOptions(), and isVerboseSpamSwitchDefined().

◆ VERBOSE_SWITCH

const std::string CmdLineOptions::VERBOSE_SWITCH = "verbose"
staticprivate

Switch for verbose output listing scheduler modules.

Definition at line 102 of file CmdLineOptions.hh.

Referenced by CmdLineOptions(), and isVerboseSwitchDefined().

◆ version_

std::string CmdLineOptions::version_
private

The version of the program.

Definition at line 91 of file CmdLineOptions.hh.


The documentation for this class was generated from the following files:
CmdLineOptions::description_
std::string description_
The description of usage of program.
Definition: CmdLineOptions.hh:89
ParserStopRequest
Definition: Exception.hh:491
CmdLineOptionParser::isDefined
bool isDefined()
Definition: CmdLineOptionParser.cc:169
CmdLineOptions::VERBOSE_SPAM_SWITCH
static const std::string VERBOSE_SPAM_SWITCH
Switch for verbose output listing spam from scheduler internals.
Definition: CmdLineOptions.hh:105
CmdLineOptions::LONG_FLAG
static const int LONG_FLAG
Number of characters reserved for printing long version of commandline flag.
Definition: CmdLineOptions.hh:99
CmdLineOptions::parseAll
void parseAll()
Definition: CmdLineOptions.cc:165
IllegalCommandLine
Definition: Exception.hh:438
CmdLineParser::commandLine_
std::vector< std::string > commandLine_
Command line is stored here.
Definition: CmdLineParser.hh:84
CmdLineParser::optionLongNames_
std::map< std::string, CmdLineOptionParser * > optionLongNames_
Database for holding options with their long names as a key.
Definition: CmdLineParser.hh:79
CmdLineOptionParser::isHidden
bool isHidden()
Definition: CmdLineOptionParser.hh:75
CmdLineOptions::progName_
std::string progName_
The name of the program.
Definition: CmdLineOptions.hh:87
CmdLineOptionParser::shortName
std::string shortName() const
CmdLineOptionParser::parseValue
virtual bool parseValue(std::string arguments, std::string prefix)=0
Pure virtual function that parses the value of option.
CmdLineParser::parseOption
bool parseOption(std::string option, std::string &name, std::string &arguments, std::string &prefix, bool &hasArgument) const
Definition: CmdLineParser.cc:277
CmdLineParser::addOption
void addOption(CmdLineOptionParser *opt)
CmdLineOptionParser
Definition: CmdLineOptionParser.hh:56
CmdLineParser::arguments_
std::vector< std::string > arguments_
Command line arguments are stored here.
Definition: CmdLineParser.hh:86
BoolCmdLineOptionParser
Definition: CmdLineOptionParser.hh:278
CmdLineParser::CmdLineParser
CmdLineParser(std::string description)
Definition: CmdLineParser.cc:59
CmdLineOptionParser::longName
std::string longName() const
CmdLineOptions::printHelp
virtual void printHelp() const
Definition: CmdLineOptions.cc:262
CmdLineOptions::version_
std::string version_
The version of the program.
Definition: CmdLineOptions.hh:91
CmdLineOptions::SHORT_FLAG
static const int SHORT_FLAG
Number of characters reserved for printing short version of commandline flag.
Definition: CmdLineOptions.hh:95
CmdLineOptionParser::description
std::string description() const
CmdLineOptions::printVersion
virtual void printVersion() const =0
CmdLineOptions::constMapIter
std::map< std::string, CmdLineOptionParser * >::const_iterator constMapIter
For traversing const maps.
Definition: CmdLineOptions.hh:77
CmdLineOptions::VERBOSE_SWITCH
static const std::string VERBOSE_SWITCH
Switch for verbose output listing scheduler modules.
Definition: CmdLineOptions.hh:102
CmdLineParser::findOption
CmdLineOptionParser * findOption(std::string name) const
Definition: CmdLineParser.cc:160