OpenASIP 2.2
Loading...
Searching...
No Matches
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.
 
typedef std::map< std::string, CmdLineOptionParser * >::iterator mapIter
 For traversing non-const maps.
 
typedef std::map< std::string, CmdLineOptionParser * >::const_iterator constMapIter
 For traversing const maps.
 

Private Member Functions

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

Private Attributes

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

Static Private Attributes

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

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.
 
std::map< std::string, CmdLineOptionParser * > optionShortNames_
 Database for holding options with their short names as a key.
 
std::vector< std::string > commandLine_
 Command line is stored here.
 
std::vector< std::string > arguments_
 Command line arguments are stored here.
 
std::vector< std::string > prefixes_
 Legal prefixes are stored here.
 

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}
std::string progName_
The name of the program.
static const std::string VERBOSE_SWITCH
Switch for verbose output listing scheduler modules.
std::string version_
The version of the program.
static const std::string VERBOSE_SPAM_SWITCH
Switch for verbose output listing spam from scheduler internals.
std::string description_
The description of usage of program.
void addOption(CmdLineOptionParser *opt)

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}
CmdLineOptionParser * findOption(std::string name) const

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}
std::vector< std::string > commandLine_
Command line is stored here.

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}
virtual bool parseValue(std::string arguments, std::string prefix)=0
Pure virtual function that parses the value of option.
virtual void printHelp() const
virtual void printVersion() const =0
std::vector< std::string > arguments_
Command line arguments are stored here.
bool parseOption(std::string option, std::string &name, std::string &arguments, std::string &prefix, bool &hasArgument) const

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

Referenced by parse(), parse(), and parse().

Here is the call graph for this function:

◆ printHelp()

void CmdLineOptions::printHelp ( ) const
virtual

Prints the help menu of the program.

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

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}
std::string longName() const
std::string shortName() const
std::string description() const
static const int LONG_FLAG
Number of characters reserved for printing long version of commandline flag.
std::map< std::string, CmdLineOptionParser * >::const_iterator constMapIter
For traversing const maps.
static const int SHORT_FLAG
Number of characters reserved for printing short version of commandline flag.
std::map< std::string, CmdLineOptionParser * > optionLongNames_
Database for holding options with their long names as a key.

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

Referenced by parseAll(), ExplorerCmdLineOptions::printHelp(), SimulatorCmdLineOptions::printHelp(), BEMGeneratorCmdLineOptions::printHelp(), PIGCmdLineOptions::printHelp(), EstimatorCmdLineOptions::printHelp(), CreateHDBCmdLineOptions::printHelp(), TestHDBCmdLineOptions::printHelp(), MachInfoCmdLineOptions::printHelp(), ProGeCmdLineOptions::printHelp(), and TTAUnitTesterCmdLineOptions::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(), parse(), and 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: