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

#include <CmdLineOptionParser.hh>

Inheritance diagram for StringListCmdLineOptionParser:
Inheritance graph
Collaboration diagram for StringListCmdLineOptionParser:
Collaboration graph

Public Member Functions

 StringListCmdLineOptionParser (std::string name, std::string desc, std::string alias="")
 
virtual ~StringListCmdLineOptionParser ()
 
virtual OptionValuecopy () const
 
virtual bool parseValue (std::string arguments, std::string prefix)
 
virtual std::string String (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 int integer (int index=0) const
 
virtual unsigned unsignedInteger (int index=0) const
 
virtual double real () const
 
virtual bool isFlagOn () const
 
virtual bool isFlagOff () const
 

Private Member Functions

 StringListCmdLineOptionParser (const StringListCmdLineOptionParser &)
 Copying not allowed. More...
 
StringListCmdLineOptionParseroperator= (const StringListCmdLineOptionParser &)
 Assignment not allowed. More...
 

Private Attributes

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

Additional Inherited Members

- Protected Member Functions inherited from CmdLineOptionParser
void setDefined ()
 

Detailed Description

CmdLineOptionParser that has a list of strings as value.

Definition at line 344 of file CmdLineOptionParser.hh.

Constructor & Destructor Documentation

◆ StringListCmdLineOptionParser() [1/2]

StringListCmdLineOptionParser::StringListCmdLineOptionParser ( 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 799 of file CmdLineOptionParser.cc.

802  : CmdLineOptionParser(name, desc, alias) {
803 }

◆ ~StringListCmdLineOptionParser()

StringListCmdLineOptionParser::~StringListCmdLineOptionParser ( )
virtual

Destructor.

Definition at line 808 of file CmdLineOptionParser.cc.

808  {
809  values_.clear();
810 }

References values_.

◆ StringListCmdLineOptionParser() [2/2]

StringListCmdLineOptionParser::StringListCmdLineOptionParser ( const StringListCmdLineOptionParser )
private

Copying not allowed.

Member Function Documentation

◆ copy()

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

821  {
823  return copy;
824 }

References values_.

◆ listSize()

int StringListCmdLineOptionParser::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 889 of file CmdLineOptionParser.cc.

889  {
890  return values_.size();
891 }

References values_.

◆ operator=()

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

Assignment not allowed.

◆ parseValue()

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

Parses the value of string set.

Value should be strings 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 837 of file CmdLineOptionParser.cc.

838  {
839  if (prefix != "") {
840  string msg = "Illegal prefix for string list option";
841  throw IllegalCommandLine(__FILE__, __LINE__, __func__, msg);
842  }
843 
844  if (arguments == "") {
845  string msg = "Missing value for option " + longName();
846  throw IllegalCommandLine(__FILE__, __LINE__, __func__, msg);
847  }
848 
849  string comma = ",";
850  string::size_type commaPosition = 0;
851  string::size_type lastPosition = 0;
852  while (commaPosition < arguments.size()) {
853  commaPosition = arguments.find(comma, lastPosition);
854  if (commaPosition == string::npos) {
855  values_.push_back(
856  arguments.substr(lastPosition, arguments.size()));
857  break;
858  } else {
859  values_.push_back(
860  arguments.substr(lastPosition, commaPosition-lastPosition));
861  lastPosition = commaPosition + 1;
862  }
863  }
864 
865  setDefined();
866  return true;
867 }

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

Here is the call graph for this function:

◆ String()

std::string StringListCmdLineOptionParser::String ( int  index = 0) const
virtual

Returns a particular value of string 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 877 of file CmdLineOptionParser.cc.

877  {
878  assert(index > 0 && static_cast<unsigned>(index) <= values_.size());
879  return values_[index - 1];
880 }

References assert, and values_.

Member Data Documentation

◆ values_

std::vector<std::string> StringListCmdLineOptionParser::values_
private

The values in string list.

Definition at line 367 of file CmdLineOptionParser.hh.

Referenced by copy(), listSize(), parseValue(), String(), and ~StringListCmdLineOptionParser().


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
__func__
#define __func__
Definition: Application.hh:67
CmdLineOptionParser::longName
std::string longName() const
StringListOptionValue
Definition: OptionValue.hh:237
StringListCmdLineOptionParser::values_
std::vector< std::string > values_
The values in string list.
Definition: CmdLineOptionParser.hh:367
StringListCmdLineOptionParser::copy
virtual OptionValue * copy() const
Definition: CmdLineOptionParser.cc:821