OpenASIP  2.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
IntegerCmdLineOptionParser Class Reference

#include <CmdLineOptionParser.hh>

Inheritance diagram for IntegerCmdLineOptionParser:
Inheritance graph
Collaboration diagram for IntegerCmdLineOptionParser:
Collaboration graph

Public Member Functions

 IntegerCmdLineOptionParser (std::string name, std::string desc, std::string alias="")
 
virtual ~IntegerCmdLineOptionParser ()
 
virtual OptionValuecopy () const
 
virtual bool parseValue (std::string arguments, std::string prefix)
 
virtual int integer (int index=0) const
 
- Public Member Functions inherited from CmdLineOptionParser
 CmdLineOptionParser (std::string name, std::string desc, std::string alias, bool hidden=false)
 
virtual ~CmdLineOptionParser ()
 
std::string longName () const
 
std::string shortName () const
 
std::string description () const
 
bool isHidden ()
 
bool isDefined ()
 
virtual unsigned unsignedInteger (int index=0) const
 
virtual std::string String (int index=0) const
 
virtual double real () const
 
virtual bool isFlagOn () const
 
virtual bool isFlagOff () const
 
virtual int listSize () const
 

Private Member Functions

 IntegerCmdLineOptionParser (const IntegerCmdLineOptionParser &)
 Copying not allowed. More...
 
IntegerCmdLineOptionParseroperator= (const IntegerCmdLineOptionParser &)
 Assignment not allowed. More...
 

Private Attributes

int value_
 The value of option. More...
 

Additional Inherited Members

- Protected Member Functions inherited from CmdLineOptionParser
void setDefined ()
 

Detailed Description

Models an option that has an integer value.

Definition at line 117 of file CmdLineOptionParser.hh.

Constructor & Destructor Documentation

◆ IntegerCmdLineOptionParser() [1/2]

IntegerCmdLineOptionParser::IntegerCmdLineOptionParser ( std::string  name,
std::string  desc,
std::string  alias = "" 
)

Constructor.

Parameters
nameThe name of the option.
descThe description of the option.
aliasThe short name of the option.

Definition at line 184 of file CmdLineOptionParser.cc.

187  : CmdLineOptionParser(name, desc, alias), value_(0) {
188 }

◆ ~IntegerCmdLineOptionParser()

IntegerCmdLineOptionParser::~IntegerCmdLineOptionParser ( )
virtual

Destructor.

Definition at line 193 of file CmdLineOptionParser.cc.

193  {
194 }

◆ IntegerCmdLineOptionParser() [2/2]

IntegerCmdLineOptionParser::IntegerCmdLineOptionParser ( const IntegerCmdLineOptionParser )
private

Copying not allowed.

Member Function Documentation

◆ copy()

OptionValue * IntegerCmdLineOptionParser::copy ( ) const
virtual

Copies the option value into a OptionValue object.

Client is responsible of deallocating the memeory reserved for the returned object.

Returns
A copy of the option value.

Implements CmdLineOptionParser.

Definition at line 205 of file CmdLineOptionParser.cc.

205  {
207  return copy;
208 }

References value_.

◆ integer()

int IntegerCmdLineOptionParser::integer ( int  index = 0) const
virtual

Returns the value of integer option.

Parameters
indexThis must be zero for integer option.
Returns
The value of integer option.
Exceptions
WrongSubclassIs never thrown by this function.

Reimplemented from CmdLineOptionParser.

Definition at line 253 of file CmdLineOptionParser.cc.

253  {
254  assert(index == 0);
255  return value_;
256 }

References assert, and value_.

◆ operator=()

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

Assignment not allowed.

◆ parseValue()

bool IntegerCmdLineOptionParser::parseValue ( std::string  arguments,
std::string  prefix 
)
virtual

Parses the integer option value.

Parameters
argumentsThe arguments of option.
prefixThe prefix of option.
Returns
True when parsing is ready.
Exceptions
IllegalCommandLineIf the arguments of option are erronous.

Implements CmdLineOptionParser.

Definition at line 219 of file CmdLineOptionParser.cc.

220  {
221  if (prefix != "") {
222  string msg = "Illegal prefix for integer option";
223  string method = "IntegerCmdLineOptionParser::parseValue()";
224  throw IllegalCommandLine(__FILE__, __LINE__, method, msg);
225  }
226 
227  if (arguments == "") {
228  string msg = "Missing value for integer option.";
229  string method = "IntegerCmdLineOptionParser::parseValue()";
230  throw IllegalCommandLine(__FILE__, __LINE__, method, msg);
231  }
232 
233  istringstream istream(arguments);
234  if((!(istream >> value_)) || istream.peek() != EOF) {
235  string msg = "Format of " + longName() + " option value was wrong: "
236  + arguments;
237  string method = "IntegerCmdLineOptionParser::parseValue()";
238  throw IllegalCommandLine(__FILE__, __LINE__, method, msg);
239  }
240 
241  setDefined();
242  return true;
243 }

References CmdLineOptionParser::longName(), CmdLineOptionParser::setDefined(), and value_.

Here is the call graph for this function:

Member Data Documentation

◆ value_

int IntegerCmdLineOptionParser::value_
private

The value of option.

Definition at line 137 of file CmdLineOptionParser.hh.

Referenced by copy(), integer(), and parseValue().


The documentation for this class was generated from the following files:
IntegerOptionValue
Definition: OptionValue.hh:85
CmdLineOptionParser::setDefined
void setDefined()
Definition: CmdLineOptionParser.cc:159
IllegalCommandLine
Definition: Exception.hh:438
assert
#define assert(condition)
Definition: Application.hh:86
CmdLineOptionParser::CmdLineOptionParser
CmdLineOptionParser(std::string name, std::string desc, std::string alias, bool hidden=false)
Definition: CmdLineOptionParser.cc:62
CmdLineOptionParser::longName
std::string longName() const
IntegerCmdLineOptionParser::value_
int value_
The value of option.
Definition: CmdLineOptionParser.hh:137
IntegerCmdLineOptionParser::copy
virtual OptionValue * copy() const
Definition: CmdLineOptionParser.cc:205