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

#include <CmdLineOptionParser.hh>

Inheritance diagram for IntegerListCmdLineOptionParser:
Inheritance graph
Collaboration diagram for IntegerListCmdLineOptionParser:
Collaboration graph

Public Member Functions

 IntegerListCmdLineOptionParser (std::string name, std::string desc, std::string alias="")
 
virtual ~IntegerListCmdLineOptionParser ()
 
virtual OptionValuecopy () const
 
virtual bool parseValue (std::string arguments, std::string prefix)
 
virtual int integer (int index=0) const
 
virtual int listSize () 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
 

Private Member Functions

 IntegerListCmdLineOptionParser (const IntegerListCmdLineOptionParser &)
 Copying not allowed. More...
 
IntegerListCmdLineOptionParseroperator= (const IntegerListCmdLineOptionParser &)
 Assignment not allowed. More...
 

Private Attributes

std::vector< int > values_
 The values in integer list. More...
 

Additional Inherited Members

- Protected Member Functions inherited from CmdLineOptionParser
void setDefined ()
 

Detailed Description

CmdLineOptionParser that has a list of integers as value.

Definition at line 310 of file CmdLineOptionParser.hh.

Constructor & Destructor Documentation

◆ IntegerListCmdLineOptionParser() [1/2]

IntegerListCmdLineOptionParser::IntegerListCmdLineOptionParser ( 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 681 of file CmdLineOptionParser.cc.

684  : CmdLineOptionParser(name, desc, alias) {
685 }

◆ ~IntegerListCmdLineOptionParser()

IntegerListCmdLineOptionParser::~IntegerListCmdLineOptionParser ( )
virtual

Destructor.

Definition at line 690 of file CmdLineOptionParser.cc.

690  {
691  values_.clear();
692 }

References values_.

◆ IntegerListCmdLineOptionParser() [2/2]

IntegerListCmdLineOptionParser::IntegerListCmdLineOptionParser ( const IntegerListCmdLineOptionParser )
private

Copying not allowed.

Member Function Documentation

◆ copy()

OptionValue * IntegerListCmdLineOptionParser::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 703 of file CmdLineOptionParser.cc.

703  {
705  return copy;
706 }

References values_.

◆ integer()

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

Returns a particular value of integer list option.

Parameters
indexThe index of list element that is wanted.
Returns
The value of a particular element in list.
Exceptions
WrongSubclassIs never thrown by this function.

Reimplemented from CmdLineOptionParser.

Definition at line 772 of file CmdLineOptionParser.cc.

772  {
773  assert(index > 0 && static_cast<unsigned>(index) <= values_.size());
774  return values_[index - 1];
775 }

References assert, and values_.

◆ listSize()

int IntegerListCmdLineOptionParser::listSize ( ) const
virtual

Returns the number of list elements.

Returns
The number of list elements.
Exceptions
WrongSubclassIs never thrown by this function.

Reimplemented from CmdLineOptionParser.

Definition at line 784 of file CmdLineOptionParser.cc.

784  {
785  return values_.size();
786 }

References values_.

◆ operator=()

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

Assignment not allowed.

◆ parseValue()

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

Parses the value of integer set.

Value should be integers separated by commas.

Parameters
argumentsThe arguments of option.
prefixThe prefix of option.
Returns
True when parsing is ready.
Exceptions
IllegalCommandLineIf argument is invalid.

Implements CmdLineOptionParser.

Definition at line 719 of file CmdLineOptionParser.cc.

720  {
721  if (prefix != "") {
722  string msg = "Illegal prefix for integer list option";
723  string method = "IntegerListCmdLineOptionParser::parseValue()";
724  throw IllegalCommandLine(__FILE__, __LINE__, method, msg);
725  }
726 
727  if (arguments == "") {
728  string msg = "Missing value for option " + longName();
729  string method = "IntegerSetCmdLineOptionParser::parseValue()";
730  throw IllegalCommandLine(__FILE__, __LINE__, method, msg);
731  }
732 
733  int number;
734  char comma;
735  istringstream istream(arguments);
736  // there must be at least one number
737  if (!(istream >> number)) {
738  string msg = "Format of " + longName() + "option value was wrong";
739  string method = "IntegerSetCmdLineOptionParser::parseValue()";
740  throw IllegalCommandLine(__FILE__, __LINE__, method, msg);
741  }
742  values_.push_back(number);
743 
744  while (istream.peek() != EOF) {
745 
746  // now there must be comma
747  if (!(istream >> comma) || comma != ',') {
748  string msg = "Format of " + longName() + "option value was wrong";
749  string method = "IntegerSetCmdLineOptionParser::parseValue()";
750  throw IllegalCommandLine(__FILE__, __LINE__, method, msg);
751  }
752 
753  if (!(istream >> number)) {
754  string msg = "Format of " + longName() + "option value was wrong";
755  string method = "IntegerSetCmdLineOptionParser::parseValue()";
756  throw IllegalCommandLine(__FILE__, __LINE__, method, msg);
757  }
758  values_.push_back(number);
759  }
760  setDefined();
761  return true;
762 }

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

Here is the call graph for this function:

Member Data Documentation

◆ values_

std::vector<int> IntegerListCmdLineOptionParser::values_
private

The values in integer list.

Definition at line 333 of file CmdLineOptionParser.hh.

Referenced by copy(), integer(), listSize(), parseValue(), and ~IntegerListCmdLineOptionParser().


The documentation for this class was generated from the following files:
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
IntegerListOptionValue
Definition: OptionValue.hh:210
IntegerListCmdLineOptionParser::values_
std::vector< int > values_
The values in integer list.
Definition: CmdLineOptionParser.hh:333
IntegerListCmdLineOptionParser::copy
virtual OptionValue * copy() const
Definition: CmdLineOptionParser.cc:703